Claude Code Cost by Sub-Agent: Where a $0.17 Run Went
One Claude Code run through a gateway, split by agent: the first call of each of three agents was 72% of a $0.17 bill. Setup is two environment variables.
Our picks
live pricing| Model | Verdict | Price |
|---|---|---|
| Claude Sonnet 5.5 An 11-call Claude Code run with two sub-agents cost $0.1728 from a cold cache and $0.0812 half a minute later. Cache writes were 77% of the cold run. | Model in the demo | from $2/M |
Contents
- How do you send Claude Code through a gateway?
- What does the gateway see without any other setup?
- Where did the $0.17 go?
- What does a second run cost?
- Does Claude Code’s own cost figure match the bill?
- How do you split spend by developer or by repository?
- How do you see agent cost across sessions?
- What does this setup not give you?
- FAQ
- How much does a Claude Code session cost?
- How do I track Claude Code costs for a team?
- Do Claude Code sub-agents cost more?
- Is the cost Claude Code prints accurate?
- What does CLAUDE_CODE_GATEWAY_HINT_HEADERS do?
- Related reading
Claude Code tells you what a session cost. It does not tell you which part of the session the money went to, and once a team runs it, nobody can say which repository or which developer a bill belongs to. Sending Claude Code through a gateway (a proxy between Claude Code and the model provider) answers both without a plugin or a wrapper: the gateway already sees every request, and Claude Code already labels its requests with a session id and an agent id. This guide runs one small task through the Synthorai gateway and reads the result: $0.1728 for 11 requests, and the first call of each of the three agents made up 72% of that cost.
TL;DR
- One Claude Code run on Claude Sonnet 5.5 with two sub-agents cost $0.1728 through a gateway, and $0.0812 when repeated half a minute later.
- Cache writes were 77% of the first run, and the first call of each of the three agents was 72%.
- The two sub-agents were 39% of the session’s cost.
- Two environment variables send Claude Code through a gateway, and a third names each sub-agent’s type.
The code is at github.com/synthorai-io/use-cases under coding-agent-spend/. You need Python 3.10 or later and the claude command, version 2.1.280 or later, which this model requires.
git clone https://github.com/synthorai-io/use-cases
cd use-cases
cp .env.example .env # put your API key in it
cd coding-agent-spend
python3 -m venv .venv && source .venv/bin/activate
pip install -r requirements.txt
python run.py --hints --label repo=shipping --label _user=dev_1
The script starts Claude Code on a copy of a small sample repository with one failing test. It sets the gateway address and the key only in the environment of that process, with an empty configuration directory, so it does not read or change your own Claude Code setup. One run takes about half a minute. The script caps a run at $0.60 with --max-budget-usd, and it will not start a run that could take its total past $2.

The numbers on this page are from runs on October 10, 2026, with Claude Code 2.1.296 on Claude Sonnet 5.5.
How do you send Claude Code through a gateway?
You set two environment variables. Claude Code speaks Anthropic’s Messages API, and the gateway serves the same API at its own address:
export ANTHROPIC_BASE_URL="https://synthorai.io" # no /v1: Claude Code adds /v1/messages itself
export ANTHROPIC_API_KEY="<your gateway key>"
Nothing else changes. The Claude Code integration page covers the details. From that point every model call of every session is in the gateway’s request log, and the console groups them.
What does the gateway see without any other setup?
It sees the session, its traces, the client and each sub-agent. Claude Code sends its own session id with every request, so one claude run is one session in the console, and the session page names the client as “Claude Code 2.1.296”. Its requests also show a trace id in the console, so the session lists its traces: two for this run, of 6 and 5 calls. Its calls are already split in the “Agents in this session” table into the main conversation and one row per sub-agent.
A sub-agent is a second agent that Claude Code starts for part of a task, with its own instructions and its own context. The task in the demo asks for two: the built-in Explore sub-agent to find where a rule lives, and a custom test-runner sub-agent to run the tests.
By default a sub-agent appears under an id such as a05e467acd14b25e6, which tells you there were two of them but not which was which. One more variable fixes that:
export CLAUDE_CODE_GATEWAY_HINT_HEADERS=1
| default | with the hint variable | |
|---|---|---|
| session, traces, client and cost | yes | yes |
| sub-agents split out, by id | yes | yes |
sub-agent type (Explore, custom) | no | yes |
| kind of each call, and the tools that ran before it | no | yes |
With it, the table names each sub-agent by type, and opening a call in Logs shows its kind (subagent:Explore) and a “Tools before this call” list with each tool’s name and run time, such as Read 7 ms. The gateway keeps the type of an agent and not the name you gave it, so test-runner appears as custom. Tool names and run times are kept. What a tool read or wrote is not.
Where did the $0.17 go?
It went to three agents, and mostly to the first call of each.
| Agent | Calls | Input tokens | Cache hit | Cost |
|---|---|---|---|---|
| Main conversation | 6 | 159k | 78.9% | $0.1053 |
| Explore sub-agent | 3 | 47.5k | 64.7% | $0.0575 |
custom sub-agent (test-runner) | 2 | 5,323 | 48.1% | $0.0101 |
| Session | 11 | 212k | 74.9% | $0.1728 |
The two sub-agents cost $0.0676, which is 39% of the session, for the two smallest jobs in the task: finding one rule in a library of three source files and running five tests. The fix itself was one character, > to >=.
The reason is in the token counts Claude Code prints at the end of the run:
claude-sonnet-5-5 20 in 158612 cache read 53058 cache write 2425 out $0.1728
At the model’s prices ($2 per million input tokens, $10 output, $0.10 for a cache read, $2.50 for a cache write) those four numbers come to:
| Token type | Tokens | Cost | Share |
|---|---|---|---|
| Cache write | 53,058 | $0.1326 | 77% |
| Output | 2,425 | $0.0243 | 14% |
| Cache read | 158,612 | $0.0159 | 9% |
| Input, not cached | 20 | $0.0000 | 0% |
Cache writes are 77% of the bill. A cache write is the first time a prompt prefix is sent: it costs 1.25 times the input price, and later requests read it at a twentieth of the input price on this model. A coding agent’s prompt is long before you type anything, since it carries the system prompt and the definition of every tool, so the first call of an agent is its most expensive one.
Each agent starts with a prompt of its own, so each one pays that first call:
| First call of | Input tokens | Cache hit | Cost |
|---|---|---|---|
| Main conversation | 30.0k | 0% | $0.0772 |
| Explore sub-agent | 14.9k | 0% | $0.0391 |
| custom sub-agent | 2,562 | 0% | $0.0077 |
Those three calls are $0.1240, 72% of the run. Everything after them is cheap: the Explore sub-agent’s second and third calls read 94% of their input from cache and cost $0.0052 and $0.0132.
A sub-agent is worth its cold start when it keeps a large amount of reading out of the main conversation’s context, which is what Explore is for in a real codebase. For a job that takes one or two calls, doing it in the main conversation avoids another cache write. This is one small repository, so check the split on your own sessions before changing how you work.
What does a second run cost?
It costs about half if it starts while the cache is still warm. We started the same run again half a minute later. It made the same 11 calls, read 93.1% of its input from cache where the first run read 74.9%, and cost $0.0812 against $0.1728. Its three first calls read 82%, 81% and 71% from cache, because the prompts they start with were already there from the run before.
Anthropic’s cache keeps an entry for five minutes by default and renews it on every read. A developer working steadily in one repository mostly pays the warm price. A scheduled job that runs once an hour pays the cold one every time.
Does Claude Code’s own cost figure match the bill?
On 2.1.296 it did, to the fourth decimal: $0.1728 cold and $0.0812 warm on both sides. It depends on the version. Claude Code calculates a cost from a price table of its own, and on 2.1.278, which still ran this model on October 8, it priced it at $5 and $25 per million input and output tokens where the bill was $2 and $10, so it printed about 2.7 times what was charged. The token counts were identical on both sides every time.
This matters for one setting. --max-budget-usd stops a run when Claude Code’s own figure reaches the limit. On the older version a run was stopped at $0.60 on Claude Code’s count with about a third of that billed. Check the figure against the session page once after an upgrade, and put the limit you depend on where the bill is counted: a spending limit on the API key.
How do you split spend by developer or by repository?
You put a label on every request, which Claude Code can send through a variable it already supports for custom headers:
export ANTHROPIC_CUSTOM_HEADERS='X-Synthorai-Metadata: {"repo":"shipping","_user":"dev_1"}'
X-Synthorai-Metadata is the gateway’s header for labels: a flat JSON object of up to 10 short strings, where _user is the key for the person a request was made for. The demo’s --label flags set exactly this, and the session page above shows both labels as tags.
Set the variable per developer in their shell profile and per repository in whatever loads environment variables for a project, and two views open up:
- In Traces, the search box takes
metadata.repo = shippingand lists the sessions of that repository. - On the Breakdown tab of Analytics, the Cost by metadata card totals requests and cost for each value of a key, so
repogives the bill per repository and_userthe bill per developer.
This works with one shared key. Separate keys per developer do the same job for billing and add separate spend limits, at the cost of managing more keys.
How do you see agent cost across sessions?
Use the Cost by agent card on the Breakdown tab of Analytics. The session page splits one session. This card totals every session in the time range by agent type:

Explore × 2 and custom × 2 are the cold and the warm run above, one total per agent type across both sessions. The Share column is each row’s part of all spend in the time range, which held other sessions too. Without the hint variable a run’s sub-agents report no type and are counted together in a row named “Sub-agent”. An agent in your own program that sets X-Agent-Id itself, like the one in Trace an LLM agent, gets a row under the name it sent.
Over a week of a team’s sessions this is the view that answers whether sub-agents are a small or a large part of the bill, and which type.
What does this setup not give you?
It does not give you span ids, names for custom agents, an isolation shortcut or a view of the work itself.
- No span ids. Requests from Claude Code 2.1.296 show a session id and a trace id but no span id, so a call’s span field reads “not sent”. The units to work with are the session, its traces and its agents.
- No names for custom agents. Every custom sub-agent is
custom. If you run several kinds and need to tell them apart, the agent id on the session page is the only handle. - No isolation shortcut.
--barelooks like the way to run Claude Code without your own plugins and settings. It also turns sub-agents off, so the session has one agent and nothing to split. The demo isolates the run with an emptyCLAUDE_CONFIG_DIRinstead. - No view of the work itself. The gateway records model calls, tool names and run times. It does not record file contents, diffs or command output.
FAQ
How much does a Claude Code session cost?
It depends on the model, the size of the repository, how many agents take part and whether the cache is warm. The run on this page, 11 requests on Claude Sonnet 5.5 to fix a one-character bug with two sub-agents, cost $0.1728 from a cold cache and $0.0812 when repeated half a minute later.
How do I track Claude Code costs for a team?
Point every developer’s Claude Code at a gateway with ANTHROPIC_BASE_URL, and add a label for the developer and the repository through ANTHROPIC_CUSTOM_HEADERS. The gateway then totals cost per session, per label value and per agent type without anything installed in Claude Code.
Do Claude Code sub-agents cost more?
Each sub-agent starts with its own prompt and pays its own cache write. In the demo on Claude Sonnet 5.5 the Explore sub-agent’s first call cost $0.0391 and its next two $0.0052 and $0.0132, and the two sub-agents together were 39% of the session. That cost buys a separate context, which pays off on large explorations and not on one-call jobs.
Is the cost Claude Code prints accurate?
Check it once per version. Claude Code 2.1.296 printed the same $0.1728 that was billed. Claude Code 2.1.278 priced Claude Sonnet 5.5 at $5 and $25 per million tokens where the bill was $2 and $10, and printed about 2.7 times the bill. The token counts matched in both versions.
What does CLAUDE_CODE_GATEWAY_HINT_HEADERS do?
It makes Claude Code send three more things with each request: the type of the agent, the kind of call, and the names and run times of the tools that ran before it. Without it a gateway still sees the session and each sub-agent, but only by id.
Related reading
- Trace an LLM agent: the same console views for an agent you write yourself.
- Why is my LLM agent expensive?: cache misses, growing context and retry loops, reproduced and fixed.
- Why is my LLM agent slow? and Debug an LLM agent: the same views read for latency and for failures.
- Ask Claude about your LLM logs: questions about sessions like these, answered through the gateway’s MCP server.
- Give your agent log tools: the same log read by a program of your own, and what the model tokens cost.
- Claude Code integration: the two variables and the model names.
- Request headers reference: which headers of Claude Code and other agents the gateway reads.