For coding workloads — generation, refactoring, code review, agentic tool use — the Opus-vs-Sonnet choice is the most consequential model decision a developer team makes with the Claude API. Here is the practical guide.
The 5× cost wedge
Model
Input
Output
Typical PR-review cost
Opus 4.7
$15/M
$75/M
$0.18–$0.45
Sonnet 4.6
$3/M
$15/M
$0.04–$0.09
Numbers assume a typical 8–15k token PR diff plus a 1–2k token review.
Where Sonnet 4.6 holds up
Single-file edits. Adding a function, fixing a small bug, applying a refactor pattern.
Greenfield generation. "Write a Python script that does X" — Sonnet's training is strong here.
Code review at scale. Linting-style reviews on hundreds of PRs daily, where you'd never pay Opus prices anyway.
Where Opus 4.7 wins
Cross-file refactors. Renaming a symbol across 30 files while preserving call-site semantics.
Unfamiliar codebases. Opus is meaningfully better at inferring conventions from existing code before generating new code.
Agentic flows with many tool calls. Each tool-call decision compounds; a single bad call early can derail a 20-step plan. Opus has a higher per-decision success rate.
Security-sensitive code. Cryptography, auth flows, SQL involving user input — areas where being "almost right" is dangerous.
The hybrid pattern that actually ships
Most production-grade coding assistants do Sonnet by default, Opus on escalation: Sonnet writes the first draft; if a test fails or the diff is rejected, retry with Opus. This captures Opus quality on the hard 10–15% while paying Sonnet prices on the easy 85%.
Diff-related workloads are well-served by the Diff Summarizer — it turns a git diff into a plain-English PR description in seconds.
Frequently asked questions
Is Opus 4.7 worth 5× the price for everyday coding?
Usually no. For single-file edits and greenfield generation, Sonnet 4.6 produces near-identical output at one-fifth the cost. Save Opus for cross-file refactors, agentic flows with many tool calls, and security-sensitive code.
Can I use Sonnet 4.6 for Claude Code or other agent CLIs?
Yes. Most agent CLIs let you pin a model. Sonnet 4.6 handles the majority of coding tasks well; switch to Opus 4.7 only when a task fails repeatedly on Sonnet or involves complex multi-step planning.
How much does code review cost on the Claude API?
For a typical 10k-token PR diff plus a 2k-token review response: about $0.04–$0.09 on Sonnet 4.6, and $0.18–$0.45 on Opus 4.7 — before prompt caching. With cached repo context, both drop ~40%.