Last month I tracked Claude Code and Codex pass rates for 95 days. The question I got most in response was not about quality at all. It was "what does this actually cost you?"
Fair question. Claude Code is an agentic tool, not a chat window. One request from you can trigger dozens of model calls, and every call re-sends the entire growing conversation as input tokens. Input volume, not output, drives the bill. Output is usually a rounding error.
So I sat down and did the session math properly. Here it is.
Where the tokens actually go
- System prompt and tool definitions: roughly 15 to 20K tokens, re-sent with every single model call.
- CLAUDE.md, rules files, MCP schemas: loaded at session start, carried in every subsequent call.
- File reads: a 500-line source file is 5 to 7K tokens, and it stays in the window after being read once.
- Tool results: test output, grep hits, terminal logs all get appended 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.
Two mechanics soften this. Prompt caching bills cache reads at about a tenth of the normal input rate, and /compact summarizes history to shrink the window. Both help a lot. 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 in a fresh session with a lean CLAUDE.md is cheap. The same question 30 turns deep, after a dozen large file reads, rides on top of a six-figure token window.
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, about 40K tokens total.
At Anthropic direct list rates, before caching discounts:
| Session profile | Input tokens | Output tokens | Sonnet 4.6 ($3/$15) | Opus 4.7 ($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 |
Treat these as ceilings. Prompt caching discounts the repeated prefix heavily, so cached sessions usually land lower. But the shape matches what people report: occasional afternoons cost a few dollars, and running Opus as a daily driver on the API can clear several hundred dollars a month.
Plan vs API break-even
Anthropic sells Claude Code two ways: flat-rate plans with usage caps enforced in rolling windows, or metered API billing with no cap.
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 with a failing build.
Many heavy users end up hybrid: a plan for interactive work, an API key for CI jobs and overflow.
The six levers that actually cut the bill
- Keep CLAUDE.md lean. Every line is a recurring charge on every model call in every session.
-
Fresh session per task,
/compactwhen it drifts. A 150K-token window bills 150K on each call. - Scope reads. Point it at specific files instead of letting it crawl. 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. Opus for architecture and gnarly debugging, Sonnet as the default, cheap models for boilerplate, test scaffolding, and commit messages.
- Lower the per-token rate itself by changing where requests are billed.
The last two compound. Routing a cheap model through a discounted endpoint can turn a $10 session into well under a dollar for routine work.
Full disclosure on lever six: I operate keaiapi, an OpenAI-compatible gateway with pay-as-you-go billing and no subscription. Global models are priced 20% below official list. The routing ladder I actually use:
| Model | 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 |
Repointing Claude Code takes one settings change
Claude Code reads ANTHROPIC_BASE_URL on startup, so switching where tokens are billed is a config change, not a workflow change. Model IDs stay the same, tool execution stays local, and rollback is deleting one line.
// ~/.claude/settings.json
{
"env": {
"ANTHROPIC_BASE_URL": "https://api.keaiapi.com",
"ANTHROPIC_AUTH_TOKEN": "sk-keaiapi-...",
"ANTHROPIC_MODEL": "claude-sonnet-4-6",
"ANTHROPIC_DEFAULT_OPUS_MODEL": "claude-opus-4-7"
}
}
Verify the endpoint with a one-off curl before pointing your daily driver at it:
curl https://api.keaiapi.com/v1/chat/completions \
-H "Authorization: Bearer sk-keaiapi-..." \
-H "Content-Type: application/json" \
-d '{
"model": "claude-sonnet-4-6",
"messages": [{"role": "user", "content": "Reply with one word: ok"}],
"max_tokens": 16
}'
Run /cost inside a session to see what you are actually burning. If your numbers look very different from my table, I would genuinely like to hear them: repo size, session length, and which model you run as the driver.
The full breakdown with the plan comparison table and FAQ lives here.
Top comments (0)