Claude Code cost follows two things: the state of the prompt cache and the number of turns. About 80% of the cost of a session is cache traffic. So the changes that lower the bill keep the cache stable and remove turns. Removing tokens alone does not: the token count can go down while the bill goes up.

This post shows where the money goes, and five changes that lower the bill. Each number comes from paired runs of Claude Code on Terminal-Bench 2 tasks, direct and through a tool.

Where the bill comes from

A model API keeps no memory between calls. On each turn, Claude Code sends the full session again: the system prompt, the tool list, each earlier turn and each tool output. The provider caches the start of the request and bills it at a lower price when the next request starts with the same bytes.

Published measurements of Claude Code sessions show the split. About 80% of the cost is cache reads and cache writes. Model output is about 10%. Fresh input is about 1%.

Two prices explain the rest. On Anthropic, a cache read costs 0.1x the input price and a cache write costs 1.25x. A turn that misses the cache pays more than ten times as much for the same text.

1. Keep the prompt cache stable

The cache matches from the first byte. If one byte changes early in the request, the provider writes everything after it again at the higher price. Common causes of a changed prefix:

  • A tool list that changes during the session, for example an MCP server that connects late.
  • A model switch in the middle of a session. Each switch builds the cache again.
  • A compression tool that rewrites old history on each call.
  • Fast mode turned on or off in the middle of a task. Each speed has its own cache.
  • The opusplan setting. Each move into or out of plan mode is a model switch.

Some actions look risky and are free. An edit to a file in the repository, an edit to CLAUDE.md, a change of permission mode or output style, a skill, a command and /recap all keep the cached prefix.

The cache also expires. With an API key, a cloud provider or a gateway, the default lifetime is 5 minutes, so the first turn after a short break writes the full session again. The setting promptCacheTtl with the value 1h keeps it for one hour. A one-hour write costs 2x the input price, so it pays when breaks are longer than 5 minutes. Behind a gateway, the one-hour request travels in the anthropic-beta header, and the gateway must forward that header unchanged.

On this path, a team can also write its own system prompt. A timestamp or another changing value in the system prompt breaks the cache on each request.

A cache bust is a turn that reads less than 90% of what the last turn left in the cache. Claude Code direct had 16 cache busts per 100 trials. Anyray had 8. RTK had 18 and Headroom had 24. cacheLint shows which segment changed.

2. Remove turns, not only tokens

Each turn sends the full history again. So one turn less removes a full request from the bill, not a small part of one.

This is where token removal can backfire. When a tool deletes text that the agent still needs, the agent does not guess. It reads the file again, or runs the command again. That is a new turn, and it costs more than the tokens that were saved.

The agent needed 11.4 turns for a task direct and 8.7 through Anyray, which is 24% fewer.

Four habits remove turns and cache writes with no tool:

  • Use /rewind to leave a wrong path. It goes back to a prefix that is already cached. /compact builds a new one.
  • Run /compact at a break between tasks, while the cache is warm. It costs the most after a long break.
  • Use /clear between unrelated tasks. It costs nothing, and old context stops going out with each turn.
  • Give noisy work to a subagent. Test runs and log reads stay out of the main session, and the cache of the main session does not change.

3. Fix the 200k limit behind a gateway

Behind a custom ANTHROPIC_BASE_URL, Claude Code budgets a flat 200,000 tokens and compacts at about 95% of that, also on a model with a 1M window. Early compaction rewrites the history, and the provider bills that as cache writes. The setting _CLAUDE_CODE_ASSUME_FIRST_PARTY_BASE_URL restores the real window. The post on Claude Code behind a gateway has the details and the side effects.

4. Size the tool schemas

Tool definitions go out with each request. Tool search loads them on demand, but it is not free. In paired runs it cost 33% more with a few MCP tools and saved 33% with many. So turn it on only when the tool schemas are large for the model's window. Where a CLI exists, such as gh or aws, it adds no tool list at all.

5. Compress only with a tool that keeps the cache

Compression lowers the bill when it does three things. It gives the same bytes for the same input on each turn. It keeps code and errors exact. And it lets the agent get removed text back in one call, as retrieval handles do.

ArmTotal cost against directTasks cheaper than direct
Anyray32% lower95%
RTK2% higher53%
Headroom40% higher11%

Through Anyray, the agent also solved more tasks: 82% against 76% direct.

What to measure

  • Cache read share per session. If it drops after a change, the change broke the cache. In Claude Code, /usage shows the share of input from the cache, the number of misses and the likely cause of the last miss.
  • Turns per task. More turns can mean that the agent reads again what a tool removed.
  • Cost per solved task. Divide the full cost, failed runs included, by the runs that passed. A cheap run that does not solve the task is not a saving. It was $0.228 through Anyray and $0.367 direct.

Common questions

What makes Claude Code expensive?

The session history. Each turn sends it again, and about 80% of the cost is cache reads and cache writes of that history.

Do token-saving tools lower the Claude Code bill?

Only when they keep the prompt cache stable and do not add turns. In paired runs on Terminal-Bench 2, RTK raised the total cost by 2% and Headroom by 40%.

What is a cache bust?

A turn that reads less than 90% of what the last turn left in the cache. The provider writes that part again, and a cache write costs more than ten times a cache read.

How much can a team save on Claude Code?

On Terminal-Bench 2 with Claude Sonnet 5.5, total cost through Anyray was 32% lower than Claude Code direct, and the agent solved 82% of the tasks against 76%.

Where to go next

← Back to blog