How to cut Claude Code token costs: theory and practice of prompt caching

by•

Hi, I'm Julia from the Hystax team. When we launched Kompressor, Claude Code wasn't compressed yet. Our CTO Max and the team have fixed that, and here is what they learned in the process.


THEORY: on Claude Code, the cache is the bill

  • 92-95% of Claude Code's prompt tokens are cache reads. On Opus 5.5, a cache read costs $0.20 per million tokens and a cache write $5, 25 times more.

  • A cache entry lives five minutes. When a build or a training run keeps the agent idle for longer, the whole prefix is written again at full price. In our baseline, that was a third of everything billed at full price.

  • Changing any byte inside the cached prefix forces a rewrite, so compressing old history costs more than it saves.

So the question is not "how many tokens can I remove?" but "how often am I paying for the same tokens twice?"


PRACTICE: four levers

  1. Keep the cache warm during long tool runs: re-send the last request every 4.5 minutes with max_tokens: 1. This alone saved about 11%.

  2. Switch to one-hour cache entries only after the first idle gap longer than five minutes. Using them everywhere cost more.

  3. Compress only the uncached tail, and skip cuts under 4,000 characters.

  4. Measure on the real bill, starting with the cache-write line.

RESULTS (Terminal-Bench 2.1, Claude Code on Opus 5.5, 89 tasks)


Anthropic bill −20% ($35.35 → $28.30), tokens lost to cache expiry −99%, solve rate unchanged (89.9% → 90.6%). On tasks with long tool runs: −34%. On short tasks, a single step costs about the same as before.

TRY IT

kompressor wrap claude

Keep-warm is off by default. The README shows how to turn it on with the full Claude Code profile. MIT-licensed, runs as a single binary or inside OptScale AI.


Full breakdown:

Repo:


How long do your tool calls usually run, and what share of your Anthropic bill is cache writes?

6 views

Add a comment

Replies

Be the first to reply

Have a question or a thought to share? Add a comment above to start the conversation.