Claude Code token cost: what a session actually burns
Updated 2026-07-15
A serious Claude Code session burns millions of input tokens because the agent re-sends the growing context on every model call, so an hour of work on Sonnet 4.6 typically lands between a couple of dollars and a few tens of dollars at direct API rates. Prompt caching, model routing, and a lower per-token rate are the three levers that bring that down.
Quick answer: expect dollars per session, not cents.
Claude Code is an agentic tool, not a chat window. One request from you can trigger dozens of model calls, and each call re-sends the entire growing conversation as input tokens. That makes input volume, not output, the driver of cost. Output tokens are usually a rounding error next to input. Approximate community-reported numbers put a serious hour-long session on a medium repo at roughly 5 to 20 million tokens. At Anthropic direct rates for Sonnet 4.6 ($3 per million input, $15 per million output), most sessions land somewhere between about $2 and $40 before caching discounts, and heavy Opus days go well past that. Prompt caching pulls real bills below the naive math, but the shape holds: long sessions on big repos cost real money. You have three levers. Reduce what enters the context window, route routine work to cheaper models, and lower the per-token rate by changing where requests are billed. The rest of this page works through each one with concrete numbers.
Where the tokens actually go.
Two mechanics soften this. First, Anthropic prompt caching: Claude Code marks stable prefixes as cacheable, cache writes cost a premium, and cache reads bill at about one tenth of the normal input rate. Second, context compaction: the /compact command summarizes history and drops the raw transcript. Both help a lot, and neither changes the fundamental rule: everything sitting in the window is paid for on every call that includes it. This is why the same prompt costs wildly different amounts in different repos. A question asked in a fresh session with a lean CLAUDE.md is cheap. The same question asked 30 turns into a session that has read a dozen large files rides on top of a six-figure token window.
- System prompt and tool definitions: roughly 15 to 20K tokens, re-sent with every single model call.
- CLAUDE.md, rules files, and MCP tool schemas: loaded at session start and carried in every subsequent call.
- File reads: a 500-line source file is roughly 5 to 7K tokens, and it stays in the window after being read once.
- Tool results: test output, grep hits, and terminal logs get appended to the conversation and re-billed as input on every later turn.
- The agentic loop itself: a single "fix this failing test" can produce 10 to 40 model calls before Claude Code reports back.
Realistic session cost math.
Model it turn by turn instead of guessing. A typical mid-size session runs about 40 model calls. Once a few files and some test output have accumulated, the full window averages around 90K tokens per call. Forty calls at 90K is 3.6M input tokens. Output stays small: 40 calls at roughly 1,000 tokens each is about 40K output tokens. The table below prices three session profiles at Anthropic direct list rates. Treat these as ceilings: prompt caching discounts the repeated prefix heavily, so cached sessions usually come in lower. The pattern still matches what developers report. Occasional afternoons cost a few dollars; running Opus as a daily driver on the API can clear several hundred dollars a month.
| Session profile | Input tokens | Output tokens | Sonnet 4.6 direct ($3/$15) | Opus 4.7 direct ($5/$25) |
|---|---|---|---|---|
| Light (10 calls, small repo) | ~0.6M | ~12K | $1.98 | $3.30 |
| Typical (40 calls, medium repo) | ~3.6M | ~40K | $11.40 | $19.00 |
| Heavy day (3 long sessions) | ~12M | ~120K | $37.80 | $63.00 |
Plan vs API: which way is Claude Code cheaper?
Anthropic sells Claude Code two ways: bundled into flat-rate subscription plans with usage caps enforced in rolling windows, or metered per token on the API. Claude Code API pricing is simply the model rates above applied to whatever your sessions burn, with no cap and no cut-off. The break-even is plain arithmetic. If your typical session costs about $11 on Sonnet at direct rates, a $20 plan pays for itself at roughly two sessions a month, provided you stay under its caps. The catch is the caps themselves: heavy agentic use is exactly the pattern that trips rolling limits, and a flat rate stops being cheap the moment you are locked out mid-session. API billing inverts the trade. You are never cut off, and you pay for exactly what you burn. Many heavy users end up hybrid: a plan for interactive work, an API key for CI jobs and overflow.
| Option | Price | Limits | Fits |
|---|---|---|---|
| Claude Pro plan | $20/month (approx.) | Rolling usage windows, weekly caps, modest Claude Code allowance | Occasional sessions, small repos |
| Claude Max plans | $100 to $200/month (approx.) | Higher caps, still rate-limited under sustained agentic load | Daily users who can live with caps |
| Anthropic API, pay as you go | Per token at list rates | No usage cap, every token metered | Bursty or team usage, CI, full control |
| API through a gateway | Per token, below list | Same metering, lower unit price | Same as API, cost-sensitive |
How to cut Claude Code token cost.
The last two levers compound. Routing a cheap model through a discounted endpoint can turn a $10 session into well under a dollar for routine work. One gateway option is APIsRouter, an OpenAI-compatible API with pay-as-you-go billing and no subscription: global models are priced 20% below official list, Chinese models sit below their official rates, the first top-up adds +100% balance, and the no-signup checkout at /topup takes payment first and emails the key. The catalog below shows what a routing ladder looks like in practice. Kimi K2.6 (kimi-k2.6) is also available if you prefer it as the budget tier.
- Keep CLAUDE.md lean. Every line is a recurring charge on every model call in every session.
- Start a fresh session per task and run /compact when a long session drifts. A 150K-token window bills 150K on each call.
- Scope reads. Point Claude Code at specific files instead of letting it crawl, and exclude build output and vendored directories.
- Disable MCP servers you are not using. Their tool schemas ride along in the system prompt on every call.
- Route by model. Keep Opus for architecture and gnarly debugging, run Sonnet as the default, and push boilerplate, test scaffolding, and commit messages to cheaper models.
- Lower the per-token rate itself by pointing the base URL at a gateway instead of billing at direct list prices.
| Model ID | Input $/1M | Output $/1M | Use it for |
|---|---|---|---|
| claude-opus-4-7 | $4.00 | $20.00 | Architecture, hard debugging |
| claude-sonnet-4-6 | $2.40 | $12.00 | Default coding driver |
| glm-5 | $0.514 | $2.314 | Routine edits, agentic sub-tasks |
| deepseek-v4-pro | $0.3915 | $0.783 | Boilerplate, tests, commit messages |
| deepseek-v4-flash | $0.126 | $0.252 | Summaries, quick lookups |
Config example: repoint Claude Code and verify.
Claude Code reads ANTHROPIC_BASE_URL on startup, so switching where tokens are billed is a settings change, not a workflow change. Put the endpoint and key in ~/.claude/settings.json and every session picks them up. Model IDs stay the same, tool execution stays local on your machine, and rollback is commenting out one line. For OpenAI-compatible tools and scripts, the base URL ends at /v1 (https://api.apisrouter.com/v1). Verify the key with a one-off curl before pointing your daily driver at it:
{
"env": {
"ANTHROPIC_BASE_URL": "https://api.apisrouter.com",
"ANTHROPIC_AUTH_TOKEN": "sk-APIsRouter-...",
"ANTHROPIC_MODEL": "claude-sonnet-4-6",
"ANTHROPIC_DEFAULT_OPUS_MODEL": "claude-opus-4-7",
"ANTHROPIC_DEFAULT_SONNET_MODEL": "claude-sonnet-4-6"
}
}FAQ
How much does Claude Code cost per hour?
Approximate community-reported figures for an active hour on a medium repo are 5 to 20 million tokens, which prices out between about $2 and $40 on Sonnet 4.6 at direct rates before caching. Prompt caching usually lands real bills below that, and Opus roughly doubles the per-token rates.
Why does Claude Code use so many tokens?
Every model call re-sends the whole context window: system prompt, CLAUDE.md, every file it has read, and all prior tool output. One user request can trigger dozens of calls, so the same tokens get billed as input again and again as the window grows.
Is Claude Code included in the Claude Pro subscription?
Yes, the subscription plans include Claude Code usage under rolling rate windows and weekly caps. Light users often fit inside a plan. Sustained agentic sessions are the exact pattern that hits the caps, which is why heavy users add an API key for overflow or CI.
How do I check how many tokens Claude Code has used?
Run /cost inside a session to see the current session spend when you are on API billing. For account-level history, check the billing console of whatever endpoint you point ANTHROPIC_BASE_URL at; gateways typically show per-request model, token, and dollar breakdowns per key.
Can Claude Code use a cheaper model to save money?
Yes. ANTHROPIC_MODEL sets the default, and the ANTHROPIC_DEFAULT_OPUS_MODEL, SONNET, and HAIKU overrides remap the tier picks. A common setup keeps Sonnet as the driver, reserves Opus for explicit hard tasks, and sends scripted or repetitive jobs to a budget model like deepseek-v4-pro through an OpenAI-compatible endpoint.
Does prompt caching make Claude Code cheaper automatically?
Largely, yes. Claude Code applies prompt caching without configuration, so the stable prefix of your context bills at a fraction of the input rate on repeat calls. You still pay full price for new content entering the window, and clearing a session discards the warm cache, so batch related work into one session where it makes sense.