Claude Code Cost: Where the Tokens Go and the Five Ways to Cut Them
Claude Code bills like a chat API, and a coding session is the worst possible chat. Every turn re-sends the system prompt, the tool definitions, the file tree, every file it read, every diff it wrote, and every tool result so far. The input for turn 40 contains the input for turns 1 to 39. Cost grows roughly with the square of the session length even though the work grows linearly.
This page shows where the tokens actually go in a real session shape, what a session really costs at list rates, and the five levers that cut it — ordered by how much they save, with the arithmetic shown so you can check it against your own usage.
Written by the SentioGate team. We sell a BYOK router that Claude Code can point at, and we say so where relevant; the levers below apply on any endpoint.
Where the tokens go
A typical mid-sized refactor task on a mature repo, measured as the shape of the request stream:
| Component | Share of a session's input tokens | Notes |
|---|---|---|
| System prompt + tool definitions | 5–10% | Stable, cacheable |
| Repo context (file contents, tree, grep results) | 50–70% | Grows with exploration; partly cacheable |
| Conversation history (plan, reasoning, prior turns) | 20–40% | Grows every turn; the quadratic term |
| Output (diffs, messages, tool calls) | small but pricey | Billed at the output rate |
Two things follow. First, input dominates the token count but output punches above its weight: at Claude Sonnet 5.5 list rates ($2/M input, $10/M output), output is 5× the price per token, so 75k output tokens cost as much as 375k input tokens. Second, the history term is the one you can attack — repo context is load-bearing, but half the conversation is the agent re-reading itself.
What a session actually costs
Take a two-hour session on Claude Sonnet 5.5 with a realistic cumulative profile: 600,000 input tokens (with a 2,000-token stable prefix) and 7,500 output tokens.
Without prompt caching:
- Input: 600,000 / 1e6 × $2 = $1.20
- Output: 7,500 / 1e6 × $10 = $0.075
- Total: ~$1.28 per session
With prompt caching at the documented ~10% of input price for the stable prefix and Anthropic's cache-write pricing on the rest, real sessions on the Pro plan's metering commonly land between $0.75 and $1.50; heavy repo-exploration sessions can exceed $3. A developer doing focused agent work all day on the API can easily burn $15–30.
That is the whole reason the subscription plans exist: Claude Pro at $17/month (annual) or $20/month and Max from $100/month cap your downside. If your sessions are short or bursty, the API price list is fine; if you run multi-hour sessions daily, a plan is almost always cheaper — and the Claude Code pricing page works the India-specific rupee numbers.
The five levers
1. Compact instead of letting history grow
/compact (automatic in recent versions) summarizes the conversation and drops the transcript. On a long session this is the single largest saving, often 30–50% of input tokens, because it attacks the quadratic term directly. Manual compaction at natural checkpoints — after a green test run, after a review pass — beats automatic compaction at a token threshold, because you choose what the summary must keep.
2. Narrow the context window the agent can see
CLAUDE.md is not the lever; the directory is. Launch Claude Code in the subdirectory you are changing, use /add on specific files rather than letting it explore, and keep grep-driven discovery instead of whole-file reads when possible. A session started at the repo root of a monorepo reads a file tree and diff surface an order of magnitude larger than one started at services/auth.
3. Route the cheap turns somewhere cheaper
Most turns in a coding session are not hard turns: listing files, running a test, reading a 40-line file, restating a plan. A router that sends simple turns to a cheaper model and the genuinely hard turns to the frontier model cuts cost dramatically — this is the case where a BYOK gateway earns its keep, because Claude Code speaks an Anthropic-compatible endpoint (ANTHROPIC_BASE_URL) that a router can serve. SentioGate does exactly this, which is our stake in this guide; LiteLLM and Portkey can do the pattern too, with different trade-offs in the gateway comparison.
4. Failover beats re-prompting
A 429 or 529 mid-session does not just cost time; the retry re-sends the full conversation. Two defences: configure a fallback endpoint so the retry goes to a different provider, and never hand-retry a failed long turn — compact first, then re-ask, or the retry re-pays the whole history. See OpenAI-to-Claude failover for the same pattern from the other direction.
5. Measure at the key level, not the app level
Claude Code's own /cost shows a session total; it does not show which repo, which task type, or which developer profile drives spend. Per-key budgets and per-task attribution — the reason teams put a gateway in front at all — turn "the API bill is big" into "agentic exploration on the payments module is 40% of it".
Plan vs API: the actual breakeven
At $1.28 per uncached session, the $20/month Pro plan pays for itself at ~16 long sessions a month — about one working day of focused agent work. But plans meter by 5-hour windows and can throttle; the API never throttles but never caps. The honest rule:
- Bursty or exploratory work → a plan, accept the window limits
- Automation, CI agents, or many parallel sessions → API with a budget
- Both → the pattern most teams land on: a plan for the developer, API keys for the robots, and a router that keeps them from being the same failure domain
FAQ
Is Claude Code more expensive than Codex?
Per token, no: the underlying model rates are comparable. Per session, Claude Code's repo-exploration style can read more context than a tightly-scoped agent, which is a workflow difference, not a price difference. The Codex vs Claude Code comparison covers it with benchmark data.
Does prompt caching work in Claude Code?
Yes, and it matters: the system prompt and tool definitions are stable, so the cacheable prefix is large. Cache savings show up automatically in the API billing; they do not apply to subscription-plan metering.
What is the biggest single waste in a typical session?
Re-reading the same files. Watch a session log and count how many times the same path appears in tool results; it is often the majority of repo-context tokens.
Can I cap what Claude Code spends?
On the API, yes: per-key spend caps at a gateway level, plus workspace-level limits. On a subscription plan, the cap is the plan itself.
Sources
Accessed 25 Nov – 1 Dec 2026. Rates are list prices and change often; check before you plan against them.
- Anthropic pricing — Sonnet 5.5 at $2/M input, $10/M output; Pro $17–20/month, Max from $100/month
- Claude Code docs — compaction, CLAUDE.md, /cost
- Related: Codex vs Claude Code, Reduce LLM costs, Claude Code pricing in India