Claude Code Model Selection: Sonnet vs Opus vs Haiku — When to Use Each
Use Claude Sonnet for 90% of tasks — it is the best balance of quality and cost. Use Claude Opus for complex architecture decisions, hard debugging sessions, or when Sonnet gives unsatisfying results. Use Claude Haiku for high-volume automated tasks where speed and cost matter more than depth.
Claude Code defaults to Claude Sonnet, and for most developers that is the right choice. Sonnet offers state-of-the-art coding performance at a cost that makes interactive sessions affordable. For a typical day of coding work — writing features, fixing bugs, refactoring — Sonnet will give you excellent results.
Claude Opus is the most capable model but costs roughly 5x more per token than Sonnet. Reserve it for tasks where capability genuinely matters: designing the architecture of a new system, debugging a subtle race condition that Sonnet keeps missing, writing a complex algorithm from scratch, or reviewing security-critical code. The extra capability justifies the cost when the alternative is hours of manual work.
Claude Haiku is the smallest and fastest model — it processes tokens about 3x faster than Sonnet at a fraction of the cost. It is not ideal for complex reasoning but works well for high-volume automated tasks: generating documentation comments for hundreds of functions, classifying code snippets, extracting structured data from files, or any task where you run Claude hundreds of times in a loop.
You can set the default model in settings.json and override it per-session with '--model'. For automated workflows that run many times, explicitly setting Haiku or Sonnet in the script prevents accidental Opus runs that could spike your API bill.
Examples
{
"model": "claude-sonnet-4-5",
"largeContextModel": "claude-sonnet-4-5"
}# Use Opus for a complex architectural task
claude --model claude-opus-4-5 \
"Design the authentication system architecture for a multi-tenant SaaS app. \
Consider JWT vs session tokens, refresh token rotation, and rate limiting."
# Use Haiku for batch documentation generation
for FILE in src/lib/*.ts; do
claude --model claude-haiku-4-5 --headless --print \
"Add JSDoc comments to all exported functions in $(cat $FILE). Output only the updated file content." \
> "$FILE.documented" &
done
wait
# Default Sonnet for everyday work
claude "Fix the failing auth tests"| Model | Input cost | Output cost | Speed | Best for |
|----------------|---------------|---------------|----------|-----------------------------------|
| claude-haiku-4-5 | $0.80/MTok | $4.00/MTok | Fastest | Batch automation, classification |
| claude-sonnet-4-5 | $3.00/MTok | $15.00/MTok | Fast | Everyday coding, 90% of tasks |
| claude-opus-4-5 | $15.00/MTok | $75.00/MTok | Moderate | Complex architecture, hard bugs |
(Prices approximate as of April 2026 — check llmversus.com/llm/pricing for current rates)Tips
- →If Claude gives a mediocre answer on a complex task, try again with Opus before spending more time iterating — it often solves in one shot what Sonnet needs 3-4 tries for.
- →Set Haiku as the default in CI workflows to minimize costs — reserve Sonnet/Opus flags for the steps that need quality.
- →Opus is especially good at finding subtle bugs in concurrent code, pointer arithmetic, and complex state machines where lesser models miss edge cases.
- →The cost difference between Sonnet and Haiku is ~20x — for a batch job that runs 1,000 times, Haiku can save hundreds of dollars.
- →Check llmversus.com/llm/pricing for up-to-date model pricing before committing to a model for a high-volume pipeline.
FAQ
Does Claude Code automatically pick the best model for each task?+
No. Claude Code uses whatever model you configure in settings.json or pass via --model. It does not auto-select based on task complexity. You need to consciously choose when to escalate to Opus.
Can I use third-party models with Claude Code?+
Claude Code is designed for Claude models via the Anthropic API. It does not natively support OpenAI, Mistral, or other providers. If you need model flexibility, consider Aider which supports any OpenAI-compatible API endpoint.
What is the difference between claude-sonnet-4-5 and claude-sonnet-4-6?+
Claude models use a major.minor versioning scheme where the first number is the generation (Sonnet 4) and the second is the iteration. Newer iterations generally have improved capabilities and sometimes updated pricing. Always use the latest stable version unless you have specific reproducibility requirements.
Is there a way to estimate the cost of a task before running it?+
Not precisely within Claude Code. You can estimate by counting the tokens in files Claude will read (roughly 1 token per 4 characters) plus the expected output. For production pipelines, run a small sample first and extrapolate.