Which Claude model to use for agents and coding

The model to pick depends on who's making the decision, not how smart you need it to be
Anthropic ships four Claude models right now and the mistake most people make is picking one and running everything through it. Haiku 4.5 costs $1 per million input tokens, Sonnet 5 costs $2 through August 31, 2026, Opus 4.8 costs $5, and Fable 5 costs $10, all per million input tokens, with output priced at 5x the input rate on every one of them. That's a 10x spread between the cheapest and most expensive model for the exact same API call shape. The right move is routing each step of your agent loop to the cheapest model that can actually do it, not picking one model for the whole run. You can see what builders are actually shipping around this exact routing problem on Clawsmith's live demand signals, where cost-optimization and agent-routing ideas show up constantly.
Here's the full lineup as of writing:
| Model | Input $/Mtok | Output $/Mtok | Context window | Speed tier | Best for |
|---|---|---|---|---|---|
| Haiku 4.5 | $1 | $5 | 200K tokens | Fastest, 4-5x Sonnet 4.5 | Sub-agents, classification, formatting, high-volume steps |
| Sonnet 5 | $2 (intro, through Aug 31 2026) / $3 after | $10 / $15 after | 1M tokens | Standard | Default executor for coding agents, most production work |
| Opus 4.8 | $5 | $25 | 1M tokens | Standard, Fast mode at $10/$50 | Advisor for a stuck executor, hard multi-step reasoning |
| Fable 5 | $10 | $50 | 1M tokens | Standard | Multi-hour autonomous runs, large migrations, days-long agentic work |
What you're actually paying for at each price point
The tokenizer matters as much as the sticker price. Opus 4.7 and later, Sonnet 5, and Fable 5 all switched to a newer tokenizer that produces roughly 30% more tokens for the same text than the older Sonnet 4.6 tokenizer. So a raw per-Mtok comparison against an older model understates the real cost gap by about a third once you convert to "cost per task" instead of "cost per token."
Context window is not a tiebreaker anymore. Haiku 4.5 caps at 200,000 tokens with a 64,000 token output limit. Sonnet 5, Opus 4.8, and Fable 5 all carry the full 1 million token window at standard per-token pricing, meaning a 900,000-token request bills at the same rate as a 9,000-token one. If your agent needs to hold an entire repo or a long tool-call history in context, that rules Haiku out regardless of price.
Coding benchmark scores by model, on SWE-bench Verified: Haiku 4.5 sits at 73.3%, Sonnet 5 is reported in the 82-85% range depending on how the run was scored, Opus 4.8 lands at 88.6%, and Fable 5 tops the current lineup at 95%. None of these numbers alone tell you which model to use for a given call. They tell you the ceiling. The floor is set by price and by how much of that ceiling your specific task actually needs.
Route to Haiku 4.5 when the step is narrow, repeatable, and you're running dozens of them
Haiku 4.5 is the model to reach for whenever a single step in your agent loop is a closed, well-defined action: run a test suite and report pass/fail, classify a ticket, format a diff, extract fields from a document, or act as one of many parallel sub-agents fanning out over a large task. It runs 4-5x faster than Sonnet 4.5 and still clears 73.3% on SWE-bench Verified, plenty strong for real coding sub-tasks, just tuned toward volume over depth.
The threshold: route to Haiku when a single call costs you a few cents and you're running it 10+ times in a row, or when the task has one obvious right answer and no ambiguity to reason through. Set it as your model per call, not per session:
# Claude Code: run a single narrow step on Haiku 4.5
claude --model claude-haiku-4-5 -p "Run the test suite and report only failing test names"
# Anthropic SDK: same call, same rule (small, closed, repeated)
response = client.messages.create(
model="claude-haiku-4-5",
max_tokens=1024,
messages=[{"role": "user", "content": "Classify this support ticket: billing, bug, or feature request."}],
)
If you're running this same call 50 times across a batch, the Batch API drops it further to $0.50/$2.50 per Mtok, half of standard Haiku pricing.
Sonnet 5 is the default executor for real coding work
Sonnet 5 is explicitly built to be "the most agentic Sonnet model yet" per Anthropic's own launch post, and it's priced to be the one you leave running by default: $2 per million input tokens and $10 per million output through August 31, 2026, moving to $3/$15 after that date. It carries the full 1M token context window and the newer tokenizer, and it's reported to be the first Claude model to clear 80% on SWE-bench Verified.
Use Sonnet 5 as your baseline for anything that looks like a real PR: multi-file changes, debugging a failing test with an unclear cause, writing a feature end to end, or any agentic tool-use loop where the model needs to plan more than one step ahead. The threshold for staying on Sonnet 5 rather than escalating: the task has a clear goal and the executor is still making forward progress, even if slowly.
# Set the executor per call, swap per task type
def pick_executor(task_kind: str) -> str:
if task_kind in ("format", "classify", "extract", "test-run"):
return "claude-haiku-4-5"
return "claude-sonnet-5" # default for real coding work
response = client.messages.create(
model=pick_executor("multi-file-refactor"),
max_tokens=8192,
messages=[{"role": "user", "content": prompt}],
)
Escalate to Opus 4.8 with the advisor tool, not a full model swap
The cleanest way to use Opus 4.8 isn't "switch the whole session to Opus." Anthropic's own advisor strategy, launched on the Claude Platform, pairs a cheaper executor with Opus as an on-demand advisor: the executor runs the task end to end, and only when it hits a decision it can't resolve does it consult Opus for a plan, a correction, or a stop signal, then resumes on its own. Advisor tokens bill at Opus rates, executor tokens bill at the executor's rate, so you only pay Opus prices for the moments that actually needed Opus.
The real numbers from Anthropic's own benchmarks: Sonnet with an Opus advisor beat Sonnet running solo by 2.7 percentage points on SWE-bench Multilingual while costing 11.9% less per agentic task overall. Haiku with an Opus advisor scored 41.2% on BrowseComp versus 19.7% running solo, more than doubling its score while still costing 85% less per task than running Sonnet alone.
# Sonnet 5 executor, Opus 4.8 as advisor, one line added
response = client.messages.create(
model="claude-sonnet-5",
tools=[
{
"type": "advisor_20260301",
"name": "advisor",
"model": "claude-opus-4-8",
"max_uses": 3,
},
],
extra_headers={"anthropic-beta": "advisor-tool-2026-03-01"},
messages=[{"role": "user", "content": prompt}],
)
Threshold: escalate to Opus (advisor or full swap) when the executor has failed the same subtask twice, or when the task involves reasoning across a genuinely large or ambiguous decision space that a narrow model keeps getting wrong in the same way. If you're paying for a full Opus session and the executor never actually needed a second opinion, you overpaid, that's what the advisor pattern is for.
Fable 5 is for runs that can't stop and ask you a question
Fable 5 costs exactly double Opus 4.8 on both input and output, $10/$50 per million tokens against Opus's $5/$25, which makes it the most expensive model on the current price list. Anthropic positions it for "ambitious, long-running, asynchronous tasks previous models couldn't sustain," and cites Stripe completing a 50-million-line Ruby migration in a single day using it. It's rated for sustained autonomy up to roughly 12 hours and scores 95% on SWE-bench Verified, the highest of the four.
If you're running Fable 5 (or any model) inside Claude's Managed Agents runtime rather than raw API calls, there's a second cost dimension: session runtime bills separately at $0.08 per session-hour, on top of token costs, metered only while the session status is "running." A one-hour session at moderate token volume adds well under ten cents in runtime cost on top of the token bill, so it rarely changes the model decision, but it's a real line item to know about before you leave a Fable 5 session running unattended overnight.
The threshold: reach for Fable 5 only when the task genuinely needs to run for hours without a human checking in, not because it's the "smartest" model. If your task finishes in under an hour of agent wall-clock time, Opus 4.8 (or Sonnet 5 with an Opus advisor) is almost always the better cost-per-outcome choice, since Fable 5's premium buys sustained autonomy, not per-call intelligence you can't get cheaper elsewhere.
What a 10-step agent loop actually costs on each model
Take Anthropic's own worked example unit, a single agent step that consumes 50,000 input tokens and produces 15,000 output tokens, and run it 10 times in a row with no caching:
STEPS = 10
INPUT_TOKENS_PER_STEP = 50_000
OUTPUT_TOKENS_PER_STEP = 15_000
PRICING = {
"haiku-4.5": (1, 5),
"sonnet-5": (2, 10), # intro pricing through Aug 31, 2026
"opus-4.8": (5, 25),
"fable-5": (10, 50),
}
for model, (in_rate, out_rate) in PRICING.items():
cost_per_step = (INPUT_TOKENS_PER_STEP / 1_000_000 * in_rate) + \
(OUTPUT_TOKENS_PER_STEP / 1_000_000 * out_rate)
print(f"{model}: ${cost_per_step * STEPS:.2f} for {STEPS} steps")
That prints: Haiku 4.5 at $1.25, Sonnet 5 at $2.50, Opus 4.8 at $6.25, Fable 5 at $12.50, for the identical 10-step loop. Turn on prompt caching for the parts of context that repeat across steps (system prompt, tool definitions, earlier turns), and a cache hit costs 10% of the base input rate on every one of these models, so a loop where 40,000 of the 50,000 input tokens per step are cache reads drops the Opus 4.8 total from $6.25 to roughly $2.75, and the Fable 5 total from $12.50 to about $5.50. Caching matters most on the two most expensive models, since the dollar savings scale with the base rate.
Build a per-call router instead of picking one model for everything
The pattern that actually saves money is a router that decides per call, not a global model setting. A simple version costs nothing to build:
def route(task: dict) -> str:
if task["tokens_est"] < 5_000 and task["type"] in ("classify", "format", "extract"):
return "claude-haiku-4-5"
if task["retries"] >= 2:
return "claude-opus-4-8" # escalate, executor is stuck
if task["duration_est_hours"] > 2:
return "claude-fable-5" # needs to run unattended
return "claude-sonnet-5" # default executor
Testing a router like this needs a real, large, structured payload to size against, not a toy prompt. Pulling a full engineering-ready spec off Clawsmith's MCP server is a decent stress test: calling get_product_brief on a single idea returned a 65KB response, well over 10,000 tokens of feature specs, tech stack choices, and source citations in one call.
result = mcp_client.call_tool(
"get_product_brief",
{"idea_id": "a3b888ee-a74a-4a88-902f-d960342bc3e0"},
)
That's a real answer to "does my router's context budget hold up against an actual large payload," not a guess. Clawsmith's MCP access sits on the Builder tier, the same tier that unlocks the lead lists and agent-ready briefs the router would be reading from. For more of these model-by-model breakdowns as new releases land, the model comparisons category tracks them as they ship.
FAQ
Is Claude Sonnet 5 good enough for coding agents, or do you need Opus 4.8?
Sonnet 5 scores in the low-to-mid 80s on SWE-bench Verified and runs at $2 per million input tokens / $10 per million output through August 31, 2026 ($3/$15 after). Opus 4.8 scores 88.6% but costs 2.5x more per token. For most PR-sized coding tasks, Sonnet 5 finishes the job at a quarter of Opus's output cost, and you can still call Opus mid-task as an advisor for the hard 10% instead of running the whole session on it.
What's the cheapest Claude model for a coding sub-agent that just runs tests or formats output?
Haiku 4.5 at $1 per million input tokens and $5 per million output, with a 200,000 token context window and speeds 4-5x faster than Sonnet 4.5. It still scores 73.3% on SWE-bench Verified, a real number for a model tuned toward narrow, repeatable steps rather than open-ended reasoning. Run 50 Haiku sub-agent calls for close to what one Opus 4.8 call costs.
How much does a 10-step Claude agent loop actually cost on each model?
Using a 50,000 input token / 15,000 output token step size (Anthropic's own worked example), 10 steps costs about $1.25 on Haiku 4.5, $2.50 on Sonnet 5 at intro pricing, $6.25 on Opus 4.8, and $12.50 on Fable 5. Prompt caching cuts the input-token portion of that by up to 90% on repeated context, which matters most on Opus and Fable where the base input rate is $5-$10 per million.
When does Fable 5's price actually pay for itself over Opus 4.8?
Fable 5 costs exactly double Opus 4.8 per token ($10/$50 vs $5/$25), so it only pays off when a task needs autonomy Opus can't sustain, not just more intelligence per call. Anthropic cites Stripe using Fable 5 for a 50-million-line Ruby migration completed in a single day, and Fable 5 scores 95% on SWE-bench Verified against Opus's 88.6%. If your task finishes in under an hour of wall-clock agent time, Opus 4.8 is almost always the better dollar-per-outcome bet.
Can Claude Code or the API switch models automatically mid-task?
Yes, two ways. The advisor tool (`advisor_20260301`, beta header `advisor-tool-2026-03-01`) lets a cheaper executor model call a more expensive model as an advisor only when it gets stuck, billed separately per model. Separately, you can just set the `model` field per API call or pass `--model` per Claude Code session, so a router you write yourself can pick the model before the call ever fires.
Sources
Keep reading
Find what to build next
Clawsmith reads real posts across the web, finds the demand, and hands your coding agent a full build brief. Free to start.
Try Clawsmith






