Every message you send to Claude Code also sends the whole conversation so far, so a long session costs more with each turn. On a subscription that shows up as plan limits arriving sooner, and on an API key it shows up on the bill. Either way the fix is to find out where the tokens go and stop paying for the ones that aren’t helping.
What follows comes from the official Claude Code docs as of December 2026, plus two tools I built, claude-stats and claude-mods. Defaults move between versions, so I’ve linked the doc page behind each claim.
Where the tokens go
Here’s roughly what a few turns look like:
The conversation is more than what you typed. It starts with the system prompt, your CLAUDE.md files and the names of your MCP tools. Then it collects every file Claude has read, every command’s output and every MCP response. If a test run prints 3,000 lines, those lines ride along in every later turn until you clear or compact.
Claude’s own output counts as well, and thinking is billed as output. The docs say the thinking budget “can be tens of thousands of tokens per request depending on the model” (costs). Subagents run in context windows of their own and spend their own tokens while they work (subagents).
Prompt caching softens all this. Claude Code does it for you, and cached tokens cost much less (prompt caching). They still count, though, and some actions throw the cache away. So the number worth watching is how big the context is.
For a sense of scale, Anthropic puts the average across enterprise deployments at “around $13 per developer per active day and $150-250 per developer per month”, with 90% of users under $30 per active day (costs). Treat it as a rough reference point.
Measure before you cut
Guessing at where tokens go is how you end up optimising the wrong thing. Claude Code gives you four ways to look.
/usage shows the session’s cost, your plan limits and activity stats (commands). /cost and /stats open the same view. The dollar amount is worked out locally at list price, unless your organisation has set its own pricing, so read it as an estimate. On Pro, Max, Ultra, Team and Enterprise plans it also breaks down what’s eating your plan limits.
/context draws the current context as a coloured grid and points at context-heavy tools and bloated memory files. It’s the first thing I’d run when a session starts to feel sluggish.
The status line can show context_window.used_percentage and cost.total_cost_usd at all times, so you watch the context fill up instead of finding out afterwards (status line).
Teams can export metrics with OpenTelemetry. Set CLAUDE_CODE_ENABLE_TELEMETRY=1 and an exporter such as OTEL_METRICS_EXPORTER=otlp, and token and cost metrics flow into your own monitoring (monitoring).
All four describe the session in front of you. For the longer view, across weeks and projects, I built claude-stats. It loads Claude Code’s local session files into SQLite and opens a TUI, a dashboard that runs in your terminal, with tabs for sessions, costs, projects, an activity heatmap and queries. Your data never leaves the machine. The one download is a public price list, and --offline skips it.
brew install cnu/tap/claude-stats
claude-stats
claude-stats query "cost by project"
claude-stats query "most expensive session"
This is the dashboard tab on my machine:

It also catches something the session counts miss. Subagent transcripts live in separate files, and their tokens aren’t included in the parent session’s totals. claude-stats folds them back in, which matters because subagents can be a big part of the spend.
Habits that cut tokens
None of these need any setup (costs).
Clear between tasks. Old context gets paid for again on every message after it, so when you move on to unrelated work, run /clear. If you might want the old session back, /rename it first.
Compact with a focus. /compact swaps the conversation for a summary, and you can tell it what to hold on to: /compact Focus on code samples and API usage. Standing instructions can live in CLAUDE.md under a # Compact instructions heading. One catch: compacting has to read the whole conversation it’s summarising, so compacting an enormous context is an expensive request in itself. Do it before things get enormous.
Ask for the specific thing. The docs’ own example is good: “add input validation to the login function in auth.ts” sends Claude straight to one file. “improve this codebase” sends it wandering, and everything it opens on the way ends up in context.
Plan the big changes. Shift+Tab cycles to plan mode, where you settle the approach before any code gets written. The docs pitch this as a way to avoid expensive re-work.
Stay on one model for a task. Each model keeps its own cache, so after /model the next request reads the entire conversation with nothing cached. On most models a mid-session effort change does the same. There’s one useful exception: with an API key or a Claude subscription, Fable 5.1 and later, Opus 5.5, Sonnet 5.5 and Haiku 5.5 keep the cache when you change effort (prompt caching).
Shrink what loads on every turn
Whatever loads at the start of a session gets paid for in every request after it. This is where small trims add up.
Keep CLAUDE.md under 200 lines. That’s the docs’ number, and their reason is that longer files “consume more context and reduce adherence” (memory). Splitting the file up with @path/to/file imports won’t help, because imports get expanded and loaded right alongside it. What helps is moving things out. Instructions that only matter for part of the codebase can become path-scoped rules, which load only when Claude touches matching files. Workflows can become skills, which load only when someone invokes them. Notes meant for humans can go in HTML comments (<!-- like this -->), since block-level comments are stripped before CLAUDE.md reaches the model.
Prune your MCP servers. On current models MCP tool definitions are deferred by default, so only the tool names and server instructions sit in context until Claude actually uses a tool (costs). It’s a small cost, but you pay it every turn. Switch off servers you aren’t using with /mcp, or /mcp disable <server>. And if there’s a CLI for the job, consider it first. The docs describe tools like gh, aws and gcloud as “more context-efficient than MCP servers”.
Keep large or private files out the right way. A .claudeignore file does nothing (permissions). Add a Read deny rule such as Read(./secrets/**) to your permissions instead. That covers Claude’s file tools; shell commands like cat fall under Bash rules.
Cap large tool outputs
Tool output can easily be the biggest thing in a session’s context. Claude Code caps it by default, and you can set tighter limits (environment variables):
| Variable | What it limits | Default |
|---|---|---|
MAX_MCP_OUTPUT_TOKENS |
Tokens in an MCP tool response (a warning shows above 10,000) | 25,000 |
BASH_MAX_OUTPUT_LENGTH |
Characters of command output read back (ignored if the bashOutputMaxChars setting is set) |
30,000 |
CLAUDE_CODE_FILE_READ_MAX_OUTPUT_TOKENS |
Tokens in a single file read | 25,000 |
Rather than cutting output off at a limit, a hook can filter it before Claude ever sees it, which is usually better. The costs page has a PreToolUse hook that trims test output to its last 100 lines, and the same trick works for grepping a log down to its ERROR lines (costs).
Pick the model and effort for the job
The docs say it plainly: “Sonnet handles most coding tasks well and costs less than Opus” (costs). Here’s how that plays out in practice (model configuration).
Use /model sonnet for everyday work and save Opus for the hard design problems. opusplan does this split for you, with Opus in plan mode and Sonnet for execution. Bear in mind that every plan-mode toggle is a model switch, so each one starts a fresh cache.
Turn effort down for quick, supervised work like a rename or a first sketch: /effort low. In the docs’ words, lower effort is “faster and cheaper for straightforward tasks”. medium is already the default on Opus 5.5, Sonnet 5.5, Haiku 5.5 and Fable 5.2, so think twice before going up to high or max. Thinking can’t be switched off on these models, so effort is the control you have.
Give subagents a cheaper model. Put model: haiku in a subagent’s definition for searching and summarising. Or set CLAUDE_CODE_SUBAGENT_MODEL, which becomes the default for any subagent that doesn’t name its own model. It leaves the built-in Explore and Plan subagents alone, and if you want every subagent on one model you also need CLAUDE_CODE_SUBAGENT_MODEL_FORCE=1 (subagents).
Keep the cache warm, and compact sooner
How long the cache lasts depends on how you pay. The main conversation gets one hour on a Claude subscription, within your plan’s usage. On usage credits, an API key or a cloud provider it gets five minutes. In those cases you can set promptCacheTtl to 1h (Claude Code v2.1.242 or later), but cache writes cost more at that length. It pays off when you step away from a session and come back to it later; in short bursts you’d pay the higher write price for nothing (prompt caching).
A cold cache means the next turn pays full price for the entire context. Two less obvious ways to lose it: Claude Code updates apply on the next launch, so the first turn after a restart is uncached, and if MCP tool search is off, connecting or removing an MCP server mid-session wipes it too.
Then there’s the auto-compact window. On current models with a 1M-token window, the default auto setting compacts at around 400K tokens, and sometimes later. With /autocompact (v2.1.221 or later) you can set a smaller window, saved per model from v2.1.288, say /autocompact 200k, and /autocompact auto puts it back. The docs explain why you might: compacting sooner keeps later requests smaller, so long sessions use fewer tokens overall (model configuration).
The price is that Claude remembers less detail from early in the session.
Mods that do some of this for you
Most of this guide is about habits, which are easy to forget. claude-mods is a set of eight Claude Code mods I wrote to handle some of it automatically. Install the ones you want and skip the rest:
/plugin marketplace add cnu/claude-mods
/plugin install input-router@cnu-mods
| Mod | What it does | Caveat |
|---|---|---|
input-router |
A cheap model digests big Read and MCP results (optionally Bash); instruction files always pass whole | Saved full copies may contain secrets; they’re swept after retentionDays |
research-router |
Condenses big web results; /research-router runs a small research job |
The command’s own web calls go through the permission check and a private-address filter |
model-router |
Routes general-purpose subagents to a cheaper or stronger model |
Can’t see a model pinned in an agent definition |
effort-optimizer |
Suggests or applies an effort level per prompt | Can’t change the session’s own effort setting |
cache-clock |
Counts down to the prompt cache going cold, with optional keep-warm pings | Assumes a 5-minute cache unless it detects otherwise; set ttlMinutes |
handoff |
At a token threshold, writes a handoff note so you can continue in a fresh chat | “Clear and continue” is destructive and needs a second press |
savings-proof |
A /savings pane summarising the shared savings ledger |
Shows avoided tokens, helper tokens and a signed dollar estimate side by side; all estimates |
mods |
A /mods pane to list and toggle installed mods |
Needs a restart |
I’d take the savings numbers with a pinch of salt, and the README says as much: the dollar figures use list input prices and ignore caching. They’re useful for comparing the mods against each other, and that’s about all I’d use them for.
Questions people ask
Why does Claude Code use so many tokens? Every turn resends the whole session, every file read and command output included. So a long session with big tool results costs more per message the longer it runs.
How do I see my Claude Code token usage? Run /usage (or /cost) for the current session and /context to see what’s filling it, and add a status line if you want it on screen all the time. For history across sessions and projects you’ll need something like claude-stats.
Does /compact save tokens? For the rest of the session, yes, because later requests carry a summary instead of the full history. The compaction itself reads everything, though, so compact early.
Does .claudeignore work? No, it has no effect. Use Read deny rules in your permissions.
Where should I start? Run /clear between unrelated tasks, and keep test and log output out of the context. After that, trim CLAUDE.md, turn off MCP servers you don’t use, and do routine work on Sonnet.