ByteCosts
coding-agent-effort-router.mdx

AI Coding Agents

Build an effort router for coding agents without switching the main model

Coding agent effort routing keeps a single model on the main conversation, adjusts its reasoning effort when the client and model preserve the prompt cache, and delegates isolated work to a cheaper subagent. Price each route by counting the main conversation’s input and output, the worker’s cold cache write, and any follow-up needed to get an accepted result.

Keep the model that owns the conversation

Pick the main model when you start a coding session. Keep it responsible for the plan, disputed assumptions, patches, and final verification. In Claude Code, each model has its own prompt cache. When you switch models with /model, the next request to the new model processes the conversation history without a cache hit even if you kept the messages identical. By contrast, the call to a separate subagent and its result append to the parent conversation. The parent can reuse its existing prefix, while the worker starts with its own prompt and tool set. Claude Code prompt caching

Choose the route based on what the next step needs from the conversation. A request to locate references to a known symbol can carry its own search scope and return paths. A request to decide whether a failing test violates a contract may need the earlier implementation choices, the patch under review, and the reason a seemingly simpler patch was rejected. Keep that decision on the main route. If it takes several paragraphs to brief the worker and the parent still has to inspect the same evidence to accept the answer, price that review as part of delegation.

The subagent should receive a deliverable the parent can check without repeating the work. For a read-only search, ask for file paths and the references that support the finding. For log triage, ask for the failing test name, a small output excerpt, and a path to the full output. For summarization, name the source material and the details that must survive. That keeps the handoff short and gives the main model evidence it can use when it decides what to do next. An exact fork of the conversation follows a different cache pattern. Cache-safe subagent forking

Change effort where the client preserves the prefix

As of November 30, 2026, there are separate rules for the Claude Code client and the Messages API. Select the rule based on the request that will actually be sent. Record the connection type and the chosen model with the policy so an environment change doesn’t silently turn every escalation into a cache rewrite.

EnvironmentDocumented behaviorRouting decision
Claude Code with a direct API key or Claude subscriptionEffort changes preserve the cache on Fable 5.1 and later, Opus 5.5, Sonnet 5.5, and Haiku 5.5 under the documented defaults (Fable 5.1 requires Claude Code v2.1.260 or later)Allow the main route to change effort
Claude Code on Amazon Bedrock, Google Cloud’s Agent Platform, or a Claude apps gatewayThe effort change follows the usual cache-miss ruleHold main effort steady
Claude Code with CLAUDE_CODE_DISABLE_EXPERIMENTAL_BETAS set or an organization with a HIPAA configurationThe same exception to cache preservation appliesHold main effort steady
Messages API on a supported model and configurationAppend per-message effort in a role: "system" message within messages to preserve the cached prefixKeep top-level effort steady and use the per-message mechanism
Messages API with a top-level effort changeMessage-level breakpoints can miss on any model. Tool and system breakpoints can also miss on Opus 5, Sonnet 5, Fable 5, Mythos 5, and earlier models that support effortTreat the whole cache as invalidated when pricing a rewrite, or hold effort steady

For a custom LLM gateway, verify the actual request path before enabling the effort rule. The Claude Code docs scope caching through that connection to what the gateway forwards. For the API, check the per-message effort beta’s model and platform availability table and send mid-conversation-output-config-2026-07-01 on the first-party Claude API. The reference describes an empty content array and the new output_config.effort value in the appended system message. Capability depends on the thinking configuration too. For example, Sonnet 5.5 with thinking: {"type": "between_tools"} rejects a per-message change to a new effort level. In the API, a message containing only tool results doesn’t start a new user turn for this feature. Schedule the effort change where there’s new user input and keep the appended system message in place on later requests. Claude Code prompt caching, Per-message effort, Thinking

Effort is a behavioral signal. A higher setting can change what the model generates, including thinking and tool calls. It gives you a way to spend more on hard steps while retaining the main model, but it doesn’t buy a fixed number of reasoning tokens. Start with a deliberate session default and look at the outcome of escalations before making them routine. A turn that reports one failed test might merit a closer look. An identical failure caused by a recognized setup problem may be better handled by a deterministic check before you even call the router. Effort

Choose where to put the second model

Claude Code’s opusplan uses Opus in plan mode and Sonnet in execution mode. That’s a model split within one workflow, and entering or leaving plan mode with that setting is a model switch that starts a fresh cache. It can make sense when the distinction between planning and executing dominates your session. If you alternate frequently and depend on the parent’s warm history, consider a fixed main model and ask a worker for specific evidence instead. Claude Code model configuration, Claude Code prompt caching

For a dedicated Claude Code subagent, set its model field to haiku or a full model ID. Set its effort in the subagent definition if you want its effort independent of the parent’s. In Codex, agents.default_subagent_model and agents.default_subagent_reasoning_effort apply to spawned agents, with explicit spawn values taking precedence. Use the settings for the client you’re running. The Python policy below uses Claude model IDs as application data. Claude Code subagents, Codex subagents

Anthropic’s advisor tool uses the opposite division of work. A lower-cost executor drives the task and consults a stronger model for guidance before continuing. The advisor’s calls are billed separately at the advisor model’s rates, and the top-level usage totals cover the executor. The tool docs put typical advisor output at 400 to 700 text tokens or 1,400 to 1,800 tokens including thinking, and give roughly three advisor calls as their break-even point for enabling advisor caching. In its April 9, 2026 evaluation, Anthropic reported a 2.7 percentage point gain on SWE-bench Multilingual and 11.9% lower cost per agentic task for Sonnet 4.6 with an Opus 4.6 advisor compared with Sonnet 4.6 alone. On BrowseComp, Haiku 4.5 with an Opus 4.6 advisor scored 41.2%, compared with 19.7% for Haiku 4.5 alone. These are Anthropic’s results for those setups. Use the advisor pattern when the expensive operation is a decision inside an otherwise routine loop. Advisor tool, Anthropic’s advisor evaluation

Aider’s September 2024 architect/editor results offer historical evidence for splitting planning from file edits. Its code editing benchmark reported an 85.0% pass rate with o1-preview as architect and o1-mini as editor using the whole-file format. The solo o1-preview baseline was 79.7% using the diff format. The model pairing and edit format both changed, so those figures can’t isolate the effect of delegation. Use them to motivate testing the split on your own tasks. Aider architect and editor results

Implement a small rule-based router

Pass the tool type, files touched, proposed diff size in lines, and count of failures already observed on the task. These are application inputs. If the step searches a bounded scope, triages a log, or summarizes known material, the policy sends it to the worker only when the proposed diff is empty and the other limits pass. Keep the task on the main route when the caller can’t classify the tool or bound the read scope. Make that decision before invoking this function.

The cutoffs are example policy choices. A task becomes hard in this policy when it touches more than three files, expects more than 100 changed lines, or has already failed. The failure check keeps a retry in the conversation that can judge whether to revise the plan. Turn on cache_safe only after confirming the documented mechanism for your client. The main policy stays at medium by default, including in environments where a mid-session increase would rebuild the cache.

Save this reference as router.py. Its policy and estimate run locally, with no model calls. Adapt the requested model and effort to your client at the point where your application dispatches work. The dictionary is the router’s decision, with fields defined by this example.

from decimal import Decimal as D

MAIN = "claude-sonnet-5-5"
WORKER = "claude-haiku-5-5"
ISOLATED = {"search", "log_triage", "summarize"}


def route_turn(tool_type, files_touched, diff_lines, failures, *, cache_safe=False):
    if min(files_touched, diff_lines, failures) < 0:
        raise ValueError("counts must be nonnegative")
    hard = files_touched > 3 or diff_lines > 100 or failures > 0
    if tool_type in ISOLATED and not hard and diff_lines == 0:
        return {"route": "subagent", "model": WORKER, "effort": "low"}
    return {
        "route": "main",
        "model": MAIN,
        "effort": "high" if cache_safe and hard else "medium",
    }


def estimate_session():
    # Columns are uncached input, cache reads, 5-minute writes, and output.
    def price(counts, rates):
        return sum(count * D(rate) for count, rate in zip(counts, rates)) / 1_000_000

    sonnet = ("2", "0.10", "2.50", "10")
    haiku = ("0.10", "0.01", "0.125", "0.50")
    baseline = price((10 * 600, 9 * 12_000, 12_000, 10 * 400), sonnet)
    main = price((6 * 600 + 4 * 250, 9 * 12_000, 12_000, 6 * 400 + 4 * 100), sonnet)
    workers = price((4 * 600, 0, 4 * 2_000, 4 * 250), haiku)
    return {"baseline": baseline, "main": main, "workers": workers, "delegated": main + workers}


if __name__ == "__main__":
    print(route_turn("log_triage", 2, 0, 0))
    for name, usd in estimate_session().items():
        print(f"{name}: ${usd:.5f}")

Run python3 -B router.py to print the cost estimates. Write a test that routes a read-only search at the file-count limit to the worker and keeps a search one file over the limit on the main model. Then check that a failure keeps the task on the main route and raises effort only when the caller has enabled cache_safe. Before connecting the router to a client, record decisions on completed tasks and inspect cases where a worker would have needed more of the parent’s history than the task brief supplied.

Estimate a session with four delegated turns

Assume ten main requests. In the baseline, Sonnet 5.5 handles all ten. In the routed estimate, four of the ten logical turns, or 40%, send the substantive work to Haiku 5.5. The parent still gets ten requests for the session, with cheaper assumed token counts on four handoff turns. Both variants write a 12,000-token parent prefix on the first request and read it nine times. This example holds prefix size flat to isolate the route decision.

A full Sonnet request adds 600 uncached input tokens and generates 400 output tokens. A handoff on the parent adds 250 uncached input tokens, including the abbreviated result, and generates 100 output tokens. Each of the four fresh Haiku requests writes a 2,000-token prefix, takes 600 uncached input tokens, and produces 250 output tokens. The worker gets zero cache reads in this scenario. These are assumed billable token counts for the fixture, including any reasoning in the assumed output, rather than observations about which model uses fewer tokens.

For each model, multiply uncached input, cache reads, five-minute cache writes, and output by their respective prices per million and divide the sum by one million. For Sonnet 5.5 those prices are $2, $0.10, $2.50, and $10. For Haiku 5.5 at the prompt lengths used here they are $0.10, $0.01, $0.125, and $0.50. The local Python run gave the following estimates for the assumed ten-turn fixture. ByteCosts pricing index

Estimated billUSD
All Sonnet$0.09280
Sonnet with four handoff turns$0.07800
Four Haiku requests, including cold writes$0.00174
Routed session total$0.07974

The difference is $0.01306 for this fixture. Compare worker cost plus extra parent review with the cost of the Sonnet work you displaced. If the worker’s answer triggers another investigation or grows the parent’s history significantly, add that spend before counting savings. In production, include each API request a handoff takes and split usage by model. Include cache writes and replays of the handoff on later requests when you measure a growing history.

Roll out the policy on one read-only task

Start with a search or test log whose result the parent can verify against a stable source. Run equivalent tasks with the original policy and with delegation, then review diffs and tests against the same acceptance criteria. Keep the cost of every attempt, including the request that asks the main model to redo an inadequate worker result. Expand the rule when the cost per accepted task falls and the parent still sees enough evidence to make the correct decision. Cost per accepted task

Once the first route works, shrink the material the worker needs using a test output triage filter. If escalating effort raises input spend even when the main model stays fixed, inspect thinking blocks and prompt caching before widening the effort policy.

Sources

How this note was produced

Drafted with AI assistance from committed ByteCosts pricing snapshots and deterministic cost formulas. Figures are grounded in the linked sources (last updated 2026-11-30). Read our editorial & automation policy, inspect the methodology, or report a discrepancy.

Build an effort router for coding agents without switching the main model. ByteCosts. Updated 2026-11-30. https://bytecosts.com/blog/coding-agent-effort-router/

Sources