How-To/How to Use Claude for Coding: A Practical Guide

How to Use Claude for Coding: A Practical Guide

Claude is the strongest agentic coding model available, and it can plan, edit, and run long autonomous tasks across a real codebase. This guide walks you through picking a model, setting up Claude Code, writing prompts that produce working diffs, and using the 1M-token context window to reason over big projects. By the end you will have a repeatable workflow for shipping code with Claude.

Last updated: Jun 20, 2026

Step 1: Pick the right Claude model for the job

Model choice drives both your results and your bill. Start coding work on Sonnet 5, which is available in Claude Code and the API and is Anthropic's default on Claude Free and Pro. Compare another model only when repository-level evaluations show a material benefit.

  • Sonnet 5: the current default on Claude Free and Pro and available in Claude Code and the API. Introductory API pricing is $2 in / $10 out per million tokens through August 31, 2026, then $3/$15.
  • Opus 4.8 (May 28 2026): the flagship and best agentic coding model. It plans before it edits and sustains long autonomous runs. Costs $5 in / $25 out per million tokens ($10/$50 in Fast Mode), also with 1M-token context.
  • Haiku 4.5: the fastest and cheapest at $1 in / $5 out per million tokens, with a 200K context window. Good for quick edits, linting passes, and high-volume calls.

Pro tip

Fable 5 was restored globally on July 1, 2026 and can be used where your Claude plan exposes it. Mythos 5 is limited to approved Project Glasswing organizations, so do not build a coding workflow around it without confirmed access. Use Sonnet 5 as the generally available Claude Code and API starting point.

Step 2: Set up Claude Code, the dedicated CLI

Claude Code is Anthropic's command-line tool built for agentic coding. It runs in your terminal, reads and edits files directly, runs commands, and works through multi-step tasks without you copy-pasting between a chat window and your editor.

  • Install Claude Code and authenticate with your Anthropic account (Free, Pro, or Max for consumer use, or an API key for metered usage).
  • Run it from the root of your project so it has the full repo in scope.
  • Set your model: use Sonnet 4.6 for day-to-day work and switch to Opus 4.8 for large refactors or long autonomous runs.
  • Let it read before it writes. Ask it to investigate the relevant files first, then propose a plan, then make the change.

Step 3: Write prompts that produce working code

Vague prompts produce vague diffs. Give Claude the goal, the constraints, and the definition of done. Claude responds well to explicit structure and verifiable success criteria.

A strong prompt template

  • Context: "This is a Next.js app. Auth lives in /lib/auth.ts and uses JWT."
  • Task: "Add rate limiting to the /api/login route, max 5 attempts per IP per minute."
  • Constraints: "Use the existing Redis client in /lib/redis.ts. Do not add new dependencies."
  • Done means: "Return a 429 with a JSON error body when the limit is hit, and add a test that proves the limit triggers."

Common mistake

Asking for the whole feature in one shot and accepting the first diff without running it. Have Claude plan first, then implement in steps, then run the tests. With Opus 4.8 you can hand off a larger plan and let it work autonomously, but you still verify the output.

Step 4: Use the 1M-token context for whole-codebase work

Both Opus 4.8 and Sonnet 4.6 carry a 1M-token context window at a flat rate, with no surcharge for using it. That changes what is possible: you can load large chunks of a codebase, multiple related files, and long documents into a single session and reason across all of it.

  • Drop in the files involved in a bug so Claude sees the call chain, not just one function.
  • Paste error logs, stack traces, and a screenshot of the failing UI. Claude accepts image input, so you can show it the broken screen.
  • Ask it to trace a feature end to end across services before it suggests a change.

Step 5: Connect tools with MCP

Anthropic created the Model Context Protocol (MCP) and gives it first-class support. MCP lets Claude talk to external tools and data sources in a standard way: your database, your issue tracker, your docs, internal APIs. For agentic coding, this means Claude can pull real context and take real actions instead of guessing.

  • Add an MCP server for the systems Claude needs to reach, such as your database or a ticketing tool.
  • Use web search when the task needs current information beyond your repo.
  • Keep tool definitions tight and specific so Claude calls the right one without ambiguity.

Step 6: Control cost on real workloads

Coding agents read and write a lot of tokens. Two built-in levers cut the bill substantially without changing your workflow.

  • Prompt caching: up to 90% off cached input tokens. Cache the stable parts of your context, like a large file or a system prompt, so repeated calls do not re-pay for them.
  • Batch processing: 50% cheaper for work that does not need an instant response, like bulk refactors or generating tests across many files.
  • Right-size the model: start on Sonnet 5, then route simple edits, high-volume calls, and hard problems separately only after each candidate passes your coding evaluations.

Workflow checklist

Before you ship: 1) Claude read the relevant files. 2) It proposed a plan you approved. 3) It made the change in reviewable steps. 4) Tests ran and passed. 5) You read the diff yourself. Skipping step 5 is how bad code reaches main.

THE CLAUDE INSIDER

Get the Claude playbook in your inbox.

One weekly email for Claude and Claude Code users. Real workflows, no hype. Subscribe and we send you The Claude Power-User Cheatsheet.

Frequently Asked Questions

RELATED