Why Is My Claude Code Bill So High? A Four-Step Audit: Measure, Find the Leak, Fix It, Cap It
Claude Code bills by tokens, and nearly all of them come from context: every request carries the conversation and its tool results. Audit your bill in four steps, using only what Anthropic's cost and prompt-caching docs describe: measure with /usage, find the leak (long sessions, cache misses, verbose output, thinking), fix that one habit, then cap automated runs.
1. Measure first: what /usage tells you and what it doesn't
Run /usage inside Claude Code. The Session block at the top lists the session's total cost and, per model, its input, output, cache read and cache write tokens. Three caveats decide how you read it. The dollar figure is computed locally from token counts at list price, so it is an estimate: Anthropic's documentation points you to the Usage page in the Claude Console for authoritative billing, and if you route through a gateway or relay, that provider's billing record is the real number. Pro and Max subscribers have usage included in their plan, so the session cost does not represent a charge for them; they see plan usage bars and a breakdown on the same screen. And current versions add a Prompt cache (main) line showing how much of the session's input was served from cache, how many misses occurred and whether the cache is still warm. That one line tells you which of the following sections matter most for you. The totals reset when /clear starts a new session. For a sense of scale, the cost documentation reports enterprise averages of about $13 per developer per active day and $150 to $250 per month, with 90% of users under $30 per active day. Your number depends on model choice, codebase size and habits, so collect a week or two of your own figures before comparing.
/usage # session cost, tokens per model, prompt cache line
/context # what is taking up space in the context window2. The core mechanism: you pay for the whole conversation every time
The cost documentation opens with the rule that explains almost everything: token costs scale with context size. Claude Code sends the full conversation with every request, and each time Claude uses a tool it sends another request carrying that batch of tool results. Prompt caching means the history is re-read at the cached rate rather than full price, but it is still re-read, so a one-line question in a session that has been open all day draws usage for the entire conversation. The practical consequence is that the cheapest habit is a clean context: when you move to unrelated work, run /clear so the old context stops riding along with every message. If you want to come back to it, /rename the session first and /resume it later. The same documentation lists ways usage climbs while you are not even typing: session-scoped scheduled tasks that fire on their interval, messages from your other sessions delivered as new turns, idle check-ins on an active goal, and teammates or subagents still running. Each of those starts a turn that sends your full context. Background housekeeping such as summarizing conversations for --resume costs very little by comparison, typically under $0.04 per session according to the docs.
3. Cache misses: model switches, effort changes and long breaks
Anthropic's prompt caching documentation is specific about what throws the cache away. Each model has its own cache, so after /model the next request reads the entire conversation history with no cache hits, even though the content is identical; you see one slower, more expensive turn, after which the new prefix is cached. In the terminal, /model asks you to confirm while the cache is still warm and the new model did not produce the last response, so treat that prompt as a price tag. Effort changes invalidate the cache on most models. The exception the docs name: with an API key or a Claude subscription, changing effort on Opus 5.5, Sonnet 5.5, Haiku 5.5 and Fable 5.1 keeps the cache, but not on Amazon Bedrock, Google Cloud's Agent Platform or a Claude apps gateway. If you use another Anthropic-compatible gateway, change effort once and check the cache line in /usage rather than assuming. Breaks matter too: cached prefixes expire after a period of inactivity, so your first message back after a long gap reprocesses the full context. Connecting or removing an MCP server, enabling or disabling a plugin, and upgrading Claude Code can also cause a partial or full miss on the next request.
No overseas card needed: cocodot's OpenAI-compatible API — switch your base_url to call the models on sale.
Top up via Alipay / WeChat Pay, USDT / USDC · billed per token · switch your base_url to connect
4. Pick the model per task, including for subagents
The documentation's guidance is plain: Sonnet handles most coding tasks well and costs less than Opus, so reserve Opus for complex architectural decisions or multi-step reasoning. Set your default in /config and switch mid-session with /model, keeping section 3's cache cost in mind. Two details change the real bill. First, switching your session to Opus also switches the subagents that inherit the session's model, so a single /model can multiply across every helper the session spawns. Second, for simple subagent tasks you can specify model: haiku in the subagent's configuration and keep the main session where it is. On cocodot, Haiku is paused: set ANTHROPIC_DEFAULT_HAIKU_MODEL=claude-sonnet-5 so those tasks use Sonnet. Fees follow the pricing page. In the /model picker, pressing s switches the current session without saving the choice as your default, which suits a one-off hard problem. To decide which tier a kind of task deserves, measure instead of guessing: run that task type on Sonnet a few times, note how often you have to redo the result, and only make Opus the default for the task types where rework clearly costs more than the price difference.
5. Compaction, CLAUDE.md and MCP: shrink the fixed overhead
/compact is itself a large request, because it reads the conversation it summarizes. While the cache is warm, that request reads the prefix from cache and costs a fraction of what the context size suggests; after a break longer than the cache lifetime there is nothing left to read from, so compacting right after resuming an old session is the most expensive time to do it. The docs recommend compacting at a natural break, such as between tasks, rather than letting auto-compaction trigger mid-task, and you can say what to keep, for example /compact Focus on code samples and API usage. If you went down a path you want to abandon entirely, /rewind to an earlier turn instead: it truncates to a prefix that is already cached, while compaction builds a new one. And when you just want a fresh start, /clear costs nothing. Two fixed costs load before you type anything. CLAUDE.md is loaded at session start, and the docs suggest keeping it under 200 lines, moving specialised workflows such as PR reviews or database migrations into skills that load only when invoked. MCP servers can be inspected with /context and disabled in /mcp when idle; command-line tools such as gh remain more context-efficient than an equivalent MCP server.
6. Thinking tokens are output tokens
Extended thinking is on by default because it substantially improves complex planning and reasoning. The cost side is that thinking tokens are billed as output tokens, and the documentation says the default budget can be tens of thousands of tokens per request depending on the model. For simpler work, lower the effort level with /effort or in /model, or disable thinking in /config. Two exceptions apply. Opus 5.5, Sonnet 5.5, Haiku 5.5 and the Fable models always use extended thinking, so effort is your only lever there. On models with a fixed thinking budget you can also lower it with the MAX_THINKING_TOKENS environment variable, for example MAX_THINKING_TOKENS=8000, while adaptive-reasoning models ignore nonzero budgets and respond to effort instead. A test you can run yourself: give the same simple task once at your default effort and once lowered, compare the output tokens in /usage, and keep the lower setting for that kind of task if the result is just as usable. Remember section 3: on most models an effort change mid-session also costs a cache miss, so make the change at a task boundary.
7. Keep verbose output out of the main conversation
Test runs, documentation fetches and log processing can produce thousands of lines, and once that output is in the main conversation every later message pays for it again. The docs describe three ways to stop it. Preprocess with a hook: the official example is a PreToolUse hook that rewrites npm test, pytest or go test commands to keep only failures and the lines around errors, which can take a result from tens of thousands of tokens down to hundreds; after configuring it, /hooks should list it under PreToolUse. Delegate to a subagent: the verbose output stays in the subagent's own context and only a summary returns to you; the subagent's requests still count toward usage, so give it a smaller model. Write specific prompts: "improve this codebase" triggers broad scanning, while "add input validation to the login function in auth.ts" reads what it needs. For bigger work, press Shift+Tab into plan mode so Claude proposes an approach before editing, and press Escape the moment it heads the wrong way. Be careful with agent teams: the docs say they use roughly 7x more tokens than a standard session when teammates run in plan mode. For file access, use the documented permissions rules rather than relying on an unverified ignore-file convention. Review the current settings documentation for the scope of each rule.
{
"permissions": {
"deny": [
"Read(./.env)",
"Read(./.env.*)"
]
}
}8. Cap it: budgets for automation, and where cocodot fits
For scripts and CI using claude -p, the --max-budget-usd flag stops a run once estimated spend reaches the amount you set. The CLI reference is careful about its limits: it checks against a client-side estimate that can differ from your bill, spending by subagents counts toward the cap, and spend can pass the cap, so leave headroom. If you pay Anthropic directly through the Console, you can also set workspace spend limits on Claude Code usage and use the Console's cost and usage reporting; a Claude Code workspace is created automatically when you first authenticate with a Console account. If you run Claude Code through cocodot instead, /usage still shows a list-price estimate, and your cocodot console records and the pricing page are what count. Listed Claude / GPT / Gemini rates are at or below the official list price; check the pricing page for each model's current rate. Cache hits are billed at half the input price, and Claude cache writes at 1.25x the input price (2x for the portion written to the 1-hour cache), the same structure as the official pricing. To be straightforward about it: in a session dominated by cache reads, the cached portion is cheaper direct from Anthropic. cocodot's advantage is on output, on uncached input, and on payment for people whose local cards are refused. Compare using your own cache hit rate and output share from /usage against both pricing pages. To connect, set ANTHROPIC_BASE_URL and ANTHROPIC_AUTH_TOKEN as described on /hub/claude-code; new users complete identity verification and a first top-up before calling the API, and the trial credit is usable after that top-up.
claude -p --max-budget-usd 5.00 "query"Claude Code cost leaks: what you see, why, and the fix
| What you see | Why it happens | Fix |
|---|---|---|
| The same short question costs more as the day goes on | Every request carries the full conversation and its tool results | Use /clear between unrelated tasks; /rename first if you want to /resume later |
| One slow, expensive turn right after /model | Each model has its own cache, so the next request gets no cache hits | Switch models between tasks, not in the middle of one |
| The first message after a break is expensive | The cache expired and the whole context was reprocessed | Wrap up or /compact before a long break |
| A single test run eats a large slice of context | Thousands of lines of output landed in the main conversation | Filter it with a hook, or delegate it to a subagent that returns a summary |
| High output tokens on simple tasks | Thinking tokens are billed as output | Lower /effort, or turn thinking off in /config where the model allows it |
| Context is already large before any work | A long CLAUDE.md or many MCP servers | Check /context; trim CLAUDE.md, move workflows into skills, disable idle servers in /mcp |