Prompt caching makes re-sent context cheaper; context compression sends less of it. Cached tokens are still billed, still count against your plan and still fill the window. In a coding agent most of the bill is already cache reads, so the two stack, as long as compression does not break the cache.
How prompt caching works
The first time a prefix is seen it is billed as a cache write, a bit above normal input. Every later request with the same bytes is a discounted cache read. OpenAI caches long prompts automatically; see each provider’s pricing page for rates.
- It is a prefix match. The cache helps only up to the first byte that differs.
- It expires. About five minutes, refreshed on every read. Anthropic sells a one-hour tier at a higher write price.
What prompt caching saves, and what it does not
Across twelve coding sessions (18,333 assistant turns) almost nothing was raw input. Caching did its job, and the bill was still mostly cache reads.
- cache read67.7%
- cache write18.9%
- output13.2%
- uncached input0.2%
- Still billed on every turn, just cheaper.
- Still counts toward plan limits. See why Claude Code runs out of usage so fast.
- Still fills the window, so caching does nothing to delay auto-compact.
- Still distracts the model. Old logs are just as noisy from cache.
Why your prompt cache hit rate drops
Hit rate is cache_read_input_tokens over the sum of it, cache_creation_input_tokens and input_tokens. OpenAI reports cached tokens under prompt_tokens_details; /cost shows the Claude Code session total on an API key.
| Cause | What happens |
|---|---|
| Idle longer than the cache lifetime | The whole prefix is written again on the next turn |
| Switching models with /model | Caches are per model, so the new model starts cold |
| Adding or removing MCP servers mid-session | Tool definitions sit near the top, so the prefix changes |
| /compact or auto-compact | History is replaced by a summary that has never been cached |
| A tool that rewrites old messages | Everything after the first edited byte is a miss |
What context compression does differently
Compression cuts the number of tokens, which goes after the 67.7% caching leaves behind and frees window space. But a compressor that rewrites history every turn turns cheap reads into writes. More in what is context compression.
| Prompt caching | Context compression | |
|---|---|---|
| What it reduces | Price per re-sent token | Number of re-sent tokens |
| Setup | Automatic in Claude Code and Codex | A proxy, library or manual habits |
| Counts toward plan limits | Yes, at the cached rate | Fewer tokens to count |
| Frees context window | No | Yes |
| Risk | Misses after idle or edits | Dropping information, breaking the cache |
How the two levers multiply
Caching sets the price of a re-read; compression sets how much gets re-read. That only holds if the compressed prefix stays stable turn to turn. For a full bill, see Claude API pricing explained.
Prompt caching vs compression: which saves more?
They are not alternatives. Do all three.
- 1Keep the cache warm
Avoid long idle gaps, pick a model before you start, set up MCP servers before the session.
- 2Carry less by hand
Shorter sessions and quieter tool output. See /compact vs /clear.
- 3Compress cache-aware
condense trims new content with Helene before it is cached, and Adeline rewrites finished stretches once, then freezes them byte-identical. The system prompt, your messages and final answers are never rewritten.
| Session | Result through condense |
|---|---|
| Under about 4k tokens | We lose money |
| Under about 20 turns | Overhead outruns the savings |
| Live run, about 179k tokens of context | 37.3% off the bill |
| 938 turns, priced cache-aware | 72.3% under baseline |
The saving grows with depth. If your sessions are short, caching alone is the right answer.
Frequently asked questions
Does Claude Code use prompt caching automatically?
Yes. Claude Code marks cache breakpoints for you, so the system prompt, tool definitions and history are cached with no setup.
Do cached tokens count against my Claude usage limit?
Yes. Cache reads are cheaper but still billed on the API and still count toward plan usage, which is why long sessions drain a subscription.
How long does the prompt cache last?
About five minutes, refreshed on every read. Anthropic also offers a one-hour tier at a higher write price.
What is a good prompt cache hit rate for a coding agent?
Very high: we measured 98.6% across twelve real coding sessions. If yours is much lower, look for idle gaps, model switches or edits to early history.
Does context compression break prompt caching?
It can. A tool that rewrites history every turn pays full write prices again; cache-aware compression trims new content before it is cached and rewrites old spans only once.
Is prompt caching or compression better for saving money?
Use both. Caching is already on; compression cuts the tokens the cache holds and re-reads every turn.