Choosing the Right Model
Opus, Sonnet, Haiku — different models for different tasks. When to switch, what each excels at, and the cost-quality tradeoff.
Claude Code gives you access to multiple models, each tuned for different kinds of work. Most developers just use whatever the default is and never think about it. That's leaving performance and money on the table. Picking the right model for the task saves money, gets faster responses, and often produces better results than always running the biggest option.
The Model Lineup
Claude Code uses model aliases so you don't have to memorize version numbers:
- default — depends on your plan tier. Max and Team Premium accounts get Opus 4.6. Pro and Team Standard accounts get Sonnet 4.6.
- sonnet — latest Sonnet (currently Sonnet 4.6). Your daily driver.
- opus — latest Opus (currently Opus 4.6). The heavyweight for complex reasoning.
- haiku — fast, cheap, efficient. Great for simple tasks.
- sonnet[1m] — Sonnet with a 1M token context window. For sessions where you need a massive amount of code in memory.
- opusplan — a hybrid. Uses Opus for planning and reasoning, then switches to Sonnet for code generation.
These aliases always point to the latest version. When Anthropic releases Sonnet 5, the sonnet alias updates automatically. You never have to change your workflow.
The extended context window (1M tokens) is available for both Opus 4.6 and Sonnet 4.6, but it's currently in beta. You'll need extra usage enabled on your subscription to access it.
How to Switch Models
Four ways, with a clear priority order. Most specific wins.
1. During a session — type /model and pick an alias or full model name. Takes effect immediately.
# Inside Claude Code, just type:
/model opus2. At startup — use the --model flag.
claude --model opus3. Environment variable — set ANTHROPIC_MODEL in your shell profile.
export ANTHROPIC_MODEL=sonnet4. Settings file — add a model field to your settings.json.
{
"model": "sonnet"
}Priority: session /model beats startup --model, which beats ANTHROPIC_MODEL env var, which beats settings.json.
Try it: Start Claude Code with claude --model haiku, ask it a simple question, then type /model opus and ask something architecturally complex. The difference in response depth and speed is immediately obvious.
Switching Mid-Session
This is criminally underrated. You can swap models without losing your conversation context. Cranking through a bunch of small file edits? Stay on Sonnet. Hit a gnarly architectural decision? Switch to Opus for that one question, then switch back.
/model opus
# Ask your complex question
/model sonnet
# Back to fast iterationThe context window carries over. You don't lose anything.
When to Use Each Model
Sonnet: Your Default
Sonnet handles 80-90% of coding tasks perfectly well. Writing functions, fixing bugs, adding features, refactoring, writing tests. It's fast and costs significantly less than Opus. If you're not sure which model to use, the answer is Sonnet. Always.
Opus: The Big Decisions
Save Opus for moments that genuinely need it:
- Complex architectural decisions across multiple systems
- Multi-step reasoning with many constraints to hold simultaneously
- Debugging subtle, hard-to-reproduce issues
- Planning large refactors that touch dozens of files
- When Sonnet gives you an answer that feels shallow or misses nuance
Opus is noticeably smarter on these tasks. But for straightforward coding? The difference is marginal and you're paying a premium for nothing.
Haiku: Fast and Cheap
Haiku shines when you don't need depth:
- Generating boilerplate from clear specs
- Simple text transformations
- Quick lookups or explanations
- Subagent tasks where latency matters more than nuance
opusplan: Split the Difference
opusplan uses Opus to think through the plan, then hands off to Sonnet for code generation. Opus-level reasoning for the hard part (figuring out what to do), Sonnet-level speed for the easy part (writing the code).
I reach for this on complex-but-code-heavy tasks. You get the smart planning without paying Opus prices for every generated line of boilerplate.
Practical Habits
Start with Sonnet, escalate when needed. Don't default to Opus because it feels safer. You'll burn through usage limits faster and sessions will be slower. Sonnet is genuinely good at coding.
Use /model liberally. Switching is free and instant. No penalty for changing models mid-conversation. Get comfortable bouncing between them based on what you're doing right now.
Set your environment variable for the baseline. Put ANTHROPIC_MODEL=sonnet in your shell profile. Override at startup when you know you need something different.
Match the model to the task, not the project. A complex system doesn't make every task complex. You don't need Opus to write a utility function.
Watch your context window. If you're in a long session approaching context limits, consider sonnet[1m] to avoid losing important context. Restarting and re-explaining everything wastes more time than the extended window costs.
Recap
Sonnet handles 80-90% of work. Use Opus when Sonnet gives you a shallow answer, not as a safety blanket. Model aliases track latest versions automatically. /model switching is free mid-session, context stays intact, use it freely. opusplan splits the cost smartly: Opus plans, Sonnet writes. Priority order: session command > startup flag > env var > settings file.
Mastering Claude Code
Lesson 23 of 70