Guides · Updated October 24, 2026
Why Claude Code uses so many tokens, and how to use fewer
You asked for a few bug fixes and half your 5-hour window is gone, or the API bill for one afternoon is bigger than last week’s. Claude Code’s token use is driven less by what you type than by how much context gets re-sent and how many requests a task fans out into. Here is where the tokens actually go, how to see which one is hitting you, and the changes that cut usage the most.
Where the tokens go
From Anthropic’s Manage costs effectively page, plus what that means in practice:
- Every request re-sends the whole conversation. Each time Claude uses a tool, Claude Code sends another request carrying the conversation plus that batch of tool results. Prompt caching bills most of the repeated history at the cheaper cache-read rate, but it still counts, so a one-line question in a session that has been open all day draws usage for the whole conversation.
- Cache misses after a break. Your first message after a pause longer than the cache lifetime reprocesses the full context at the normal input rate.
- Subagents and parallel work. Every subagent sends its own requests with its own context, on top of the main conversation. Ask an agent to “fix all 12 issues” and it may fan out into many subagents at once; each one is roughly a session’s worth of usage. Agent teams, per the same docs, use about 7x more tokens than a standard session when teammates run in plan mode.
- Extended thinking. Thinking tokens are billed as output tokens, and the default budget can be tens of thousands of tokens per request. Output costs several times more than input.
- Opus as the default. Anthropic names “long sessions that were never cleared” and “Opus left as the default model” as the usual causes of unexpectedly high spend. A switch to Opus also applies to subagents that inherit the session’s model.
- Always-loaded context.
CLAUDE.mdis loaded at session start and sent with every request, as are MCP server instructions and tool names. - Work while you are idle. Session-scoped scheduled tasks (
/loop) fire on their interval and send the full context each time; so do goal check-ins and messages from your other sessions. - Loops. The same failing command rerun ten times is ten full-context requests that produce nothing. This is the multiplier on all of the above.
Find out which one is hitting you
/usage: on Pro, Max, Team and Enterprise it shows plan usage bars plus an attribution breakdown (skills, subagents, plugins, individual MCP servers as a share of recent usage) and recommendations, one per row, for anything behind 10% or more of your usage, such asTrim ~/code/api/CLAUDE.md · 49k tokens per request. Pressdorwto switch between the last 24 hours and 7 days. On recent versions,fapplies the recommendations it can. On API billing, the Session block shows token counts and an estimated dollar cost for the current session, plus a prompt-cache line with the hit rate and misses./context: what is taking up the context window right now (system prompt,CLAUDE.md, MCP, conversation).- Per session, after the fact: Claude Code writes every session’s token counts to local transcripts. See tracking token costs per session to turn those into an estimated cost per session, or run
loopguard report --by session.
The changes that save the most
/clearbetween unrelated tasks. Stale context is re-sent with every later message./clearcosts nothing;/compacthas to read the whole conversation to summarize it, so compacting a huge context is itself a big request. Use/renamefirst if you want to/resumeit later.- Match the model to the job. Sonnet for routine edits, Opus for hard design problems. Switch with
/model; setmodel: haikufor simple subagents. - Turn thinking down for simple work. Lower the effort with
/effort(or in/model). On models that allow it, thinking can be disabled in/config. - Bound the fan-out. Say how many subagents you want (“use at most 2 subagents”) or ask it to fix issues one at a time. “Fix everything you flagged, be extra careful” on Opus is the most expensive sentence you can type.
- Trim what is always loaded. Keep
CLAUDE.mdunder about 200 lines and move workflow-specific instructions into skills, which load only when used. Disable MCP servers you aren’t using with/mcp; a CLI likeghcosts no context until it runs. - Keep verbose output out of the main context. Ask for failures only (
pytest -q,grepthe log) or have a subagent read the 10,000-line log and return a summary. Anthropic’s docs include aPreToolUsehook that rewrites test commands to show only failures. - Plan first, correct early. Plan mode (
Shift+Tab) before a big change avoids paying for a wrong implementation. If it heads the wrong way, pressEscand/rewindinstead of letting it finish. - Watch idle features. Stop
/looptasks you no longer need, and remember a session left open over lunch will miss the cache on your next message.
Stop the expensive mistakes automatically
The habits above reduce normal usage. The spikes, the session that eats a whole window in 30 minutes, usually come from a loop or a fan-out nobody was watching. Claude Code’s native caps are coarse: plan windows, monthly usage-credit and Console workspace limits, and --max-budget-usd for headless claude -p runs only (see Claude Code spending limit). Nothing native stops an interactive session at $10, or notices the same test run with the same result for the eighth time.
LoopGuard is an open-source (MIT) CLI that adds those checks as Claude Code hooks. It needs no proxy and no API key, so it works on Pro and Max as well as API billing:
npm i -g loopguard-cli loopguard init --agent claude # PreToolUse, PostToolUse, PostToolUseFailure and Stop hooks loopguard config set sessionCapUsd 10 # estimated $ per session (default 25) loopguard config set dailyCapUsd 40 # estimated $ per local day (default 100) loopguard report --by session # what your recent sessions cost, estimated
- Loops: the same tool call repeated 5 times in 10 minutes with no progress in between (no file changed, same output) is denied, and Claude is told to diagnose instead of rerunning. The 3rd loop block in a row ends the session.
- Spirals: an estimated $10 jump within 5 minutes ends the session (
loop.spiralUsd). That is the “13 subagents at once” case. - Caps: past the session or daily cap, Claude Code stops. Costs are estimated at API list prices from the transcripts Claude Code writes, subagents included. On a subscription that is “API-equivalent” spend, which is still a good proxy for how fast you are burning your window.
Checks run at each tool call, so a single long response isn’t cut off mid-stream, and work outside Claude’s tool calls (a background process it started, another app calling the API) isn’t seen. Keep your billing-side limits set too.
Related
- How to stop runaway Claude Code, Codex and Cursor agent loops
- How to track AI coding agent token costs per session
- How to set a spending limit for Claude Code
- How to limit Cursor agent usage costs
- How to cap OpenAI Codex CLI spend
- Claude Code usage limit reached: why it happens and how to monitor it
- How to set a hard budget for AI coding agents in CI
- Claude Code stuck in a loop: how to break it and stop it repeating the same command
- Codex usage limit reached: 5-hour and weekly limits explained
- Cursor agent stuck in a loop: how to stop it, roll back, and keep it from repeating
- How to set a budget limit for Aider
- GitHub Copilot agent mode stuck in a loop: how to stop it and keep it from repeating
- Cline stuck in a loop: how to stop it, roll back, and cap what it spends
- Gemini CLI usage limits: daily quotas, the June 2026 change, and keeping costs in check
- Codex stuck in a loop: how to stop it, undo it, and keep it from repeating