A Claude Code session is typically 90 to 97 percent input tokens, because the agent reads far more than it writes and re-sends the accumulated context on every request, including one request per batch of tool results. Cost therefore grows closer to the square of turn count than linearly. Prompt caching cuts the repeated portion to 0.1x base input, which is what makes long sessions affordable, and a cache miss after a break undoes that for one request.
- A coding session is overwhelmingly input tokens, usually 90 to 97 percent.
- Every request re-sends the accumulated conversation, so cost scales with turns squared.
- Cache reads cost 0.1x base input. A 5-minute write is 1.25x, a 1-hour write is 2x.
- The cache lifetime is an hour on a subscription, five minutes on an API key.
- Tool output is input. A command that prints 4,000 lines has bought 4,000 lines of context.
- Claude 4.7-generation models use a newer tokenizer producing about 30 percent more tokens for the same text.
The four kinds of token you pay for
Token categories and their relative price, using Sonnet 5 standard rates as the reference.
| Kind | What it is | Multiplier | Rate / M | Share of a session |
|---|---|---|---|---|
| Input (uncached) | New content sent this request | 1x | $3.00 | 5 to 20% |
| Cache write (5 min) | Content stored for reuse | 1.25x | $3.75 | small, recurring |
| Cache write (1 hour) | Longer-lived store | 2x | $6.00 | small, one-off |
| Cache read | Repeated prefix re-read cheaply | 0.1x | $0.30 | 70 to 90% |
| Output | What the model generates | 5x | $15.00 | 3 to 10% |
The shape of that table is the whole story. The expensive per-token category is output, but it is a rounding error by volume. The category that decides your bill is cache read: cheap per token and enormous by volume.
A fifth category that bills as output
Extended thinking tokens are billed as output tokens, and the default budget can run to tens of thousands per request. On simple work that is money for nothing. Lower it with /effort, disable thinking in /config, or on models with a fixed thinking budget set MAX_THINKING_TOKENS, for example MAX_THINKING_TOKENS=8000. Adaptive-reasoning models ignore a nonzero budget, so use effort levels there.
Why loops multiply
A chat exchange sends context once. An agent loop sends it again on every request, because the model has to see the whole conversation to decide the next action, and every batch of tool results is itself another request carrying that whole history.
Worked example
Suppose a session starts with 20k tokens of system prompt and project context, and each turn adds about 5k tokens of file contents, command output, and reasoning.
Cumulative input tokens across a session. Uncached, to show the underlying growth.
| Turn | Context size | Sent this turn | Cumulative sent |
|---|---|---|---|
| 1 | 20k | 20k | 20k |
| 5 | 40k | 40k | 150k |
| 10 | 65k | 65k | 425k |
| 20 | 115k | 115k | 1.35M |
| 30 | 165k | 165k | 2.8M |
Thirty turns of a session that only ever accumulated 165k tokens of actual content has sent 2.8 million tokens. That is the quadratic term, and it is why a session that felt short can produce a bill that does not.
The cache-miss cliff
The flattening depends on the cache still being warm. The lifetime is an hour on a subscription, five minutes by default on an API key or a cloud provider, and five minutes on a subscription once you are drawing on usage credits. The first message after a longer break reprocesses your full context at 1x, not 0.1x. On a 150k-token session at Sonnet 5 standard rates that is $0.45 for a question you assumed was nearly free, and on Opus 5 it is $0.75.
On a paid plan, /usage flags cache misses as a behavior when they account for 10 percent or more of your recent usage, so you do not have to infer it.
What consumes tokens in a real session
Ranked by how much they typically add to a session.
| Source | Typical size | Controllable? |
|---|---|---|
| File contents read by the agent | 1k to 20k tokens per file | Yes, by naming files |
| Command and test output | 200 to 10,000+ tokens per run | Yes, by scoping commands and using hooks |
| Search and grep results | 500 to 5,000 tokens | Yes, by being specific |
| CLAUDE.md and project memory | Loaded at session start, present on every request | Yes, by moving detail into skills |
| System prompt | A few thousand tokens, every request | No |
| MCP tool definitions | Names only by default; full schemas on demand | Yes, by disabling unused servers |
| Model reasoning and replies | 200 to 3,000+ tokens per turn | Yes, via /effort |
| Agent teammates | A full context window each | Yes; off by default |
What the startup budget looks like
Anthropic publishes a representative breakdown of what loads before you type anything: the system prompt around 4,200 tokens, auto memory around 680, environment info around 280, deferred MCP tool names around 120, and the skill listing around 450. Roughly 6k tokens of floor, present on every request for the life of the session. Your CLAUDE.md sits on top of that.
The CLAUDE.md trap
A project memory file loads at session start and is present in context even when you are doing unrelated work. A tight file is excellent value: it stops the agent rediscovering conventions repeatedly. A sprawling one is a tax you pay on every request of every session forever, and it is one of the most common self-inflicted token costs.
Anthropic's guidance is to keep CLAUDE.md under 200 lines and move workflow-specific instructions into skills, which load on demand only when invoked. A PR-review procedure and a migration checklist do not need to be in context while you fix a CSS bug.
Token cost of common tasks
Rough token consumption by task, Sonnet 5 at standard rates, with caching in effect.
| Task | Input | Output | Approx cost |
|---|---|---|---|
| Explain a file you paste in | 8k | 1k | $0.04 |
| Fix a test you already located | 30k | 4k | $0.15 |
| Small feature, 3 files, known location | 120k | 15k | $0.59 |
| Same, agent has to find the files | 400k | 25k | $1.58 |
| Refactor across 12 files | 900k | 60k | $3.60 |
| Long autonomous run in a large repo | 4M | 200k | $15.00 |
| Idle session, background summarization only | minimal | minimal | under $0.04 |
The two rows worth studying are the middle pair. Identical work, different prompt precision, roughly three times the cost. Nothing else on this page has that leverage.
The last row is worth knowing for a different reason: Claude Code uses a small number of tokens for background work such as summarizing previous conversations for claude --resume, typically under $0.04 per session. It is real but it is not your problem.
Cutting the token bill
In order of leverage, which is not the order people usually try them in.
- Write specific prompts. "Add input validation to the login function in
auth.ts" versus "improve this codebase". The second triggers broad scanning and pays for all of it. /clearbetween unrelated tasks. Free, instant, and it makes the answers better as well as cheaper. Use/renamefirst if you want to/resumelater.- Filter tool output with a hook. A
PreToolUsehook on Bash that greps a test run for failures turns a 10,000-line log into a few hundred tokens before the model ever sees it. - Delegate verbose reads to subagents. The log stays in the subagent context window; only a summary returns to yours.
- Match the model to the job. Sonnet for most work, Haiku for mechanical subagent tasks, Opus for genuinely hard reasoning.
- Move detail out of CLAUDE.md into skills. Under 200 lines in memory, everything else loaded on demand.
- Turn effort down when the task is easy. Thinking tokens bill as output.
- Prefer CLI tools to MCP servers where both exist.
gh,aws, andgcloudadd no per-tool listing at all. Run/mcpand disable servers you are not using.
Applied together these routinely halve a session without changing what gets built. The first three are worth more than the rest combined.
Questions people ask
Because a coding agent reads far more than it writes, and because every request re-sends the accumulated conversation so the model can decide the next action. Every batch of tool results triggers another request carrying that history again. A typical session is 90 to 97 percent input.
Cache reads cost 0.1x base input, a five-minute cache write costs 1.25x, and a one-hour write costs 2x. On a long session where most of each request is repeated prefix, that commonly takes 40 to 70 percent off the total.
An hour on a subscription, five minutes by default on an API key or a cloud provider, and five minutes on a subscription once you are drawing on usage credits. The first message after a longer break reprocesses your full context at full input price.
Yes. Anything a command prints comes back into the conversation and is input on the next request. Running a full test suite that prints thousands of lines is a direct and usually avoidable cost; a PreToolUse hook that filters to failures fixes it permanently.
Run /usage for per-session token counts by model plus, on a paid plan, an attribution breakdown across skills, subagents, plugins, and MCP servers. Run /context for what is occupying the window right now. Both read local session history on that machine only.
Less than you would think. They are five times the price but usually under a tenth of the volume, so input still dominates the bill in nearly every coding session. The exception is heavy extended thinking, which bills as output and can run to tens of thousands of tokens per request.
Yes, on every request of every session, because project memory loads at session start and stays in context. Anthropic recommends keeping it under 200 lines and moving workflow-specific instructions into skills, which load only when invoked.
Yes. Claude 4.7-generation models and later use a newer tokenizer that produces roughly 30 percent more tokens for the same text. The per-token rate can be unchanged and the per-file cost still goes up, so compare cost per task rather than cost per token when a model changes.
Sources
Every figure above was read from these pages on August 2026. Vendors reprice without notice; if you find a stale number, tell us.