How prompt caching works in Claude Code — and how to make the most of it

TL;DR Claude Code caches your prompts as you go. When continuing an existing conversation, the previous part of your prompt that is already cached is billed only at 10% of the full cost. By default, Claude Code in billed-per-token setups sets a prompt cache TTL of 5 mins. This means that if you take longer than 5 mins to continue a Claude Code session, you'll pay full price for the whole conversation every turn.

The time of being more conscious of our token usage is upon us 🙌 So I went down a rabbit hole to figure out how to best make use of Claude Code's prompt prefix caching mechanism. Here's what I came up with. If you're interested, the full official docs are here and are very good and detailed.

How the cache works

Prompt caching is a prefix cache. Every turn, the API matches the start of your request (model + system prompt + project context + full convo history) against what has recently been cached, and only the newly appended bit of the conversation is fresh work.

A cache write is when Claude Code commits the current conversation up to that point to be cached for a certain TTL (time to live): 5 mins or 1 hour depending on auth type or configuration. If following turns in a Claude Code session start with that exact prompt "prefix", then that cache is used and that part of the conversation is billed at a highly discounted rate.

Change anything earlier in that prefix and you'll get a cache miss. Everything will be re-read (or re-committed as a cache) and you'll be billed for the whole context again.

Cached prefixes expire after inactivity, but every cache hit resets the TTL, so an active session stays available as cache.

Cache pricing (relative to base input price)

Default cache TTL depends on how you auth

The cost breakdown: hits vs. misses

To visualize the cost impact of caching, let's take an imaginary example: a 3,000 token base prompt, followed by 5 conversational rounds adding 1,000 tokens each.

The math:

Here is the total token cost for the entire 5-round session compared to a non-cached baseline:

ScenarioTotal costThe verdict
No cache30.0 unitsThe baseline imaginary cost without caching at all.
5m TTL — all hits12.2 unitsCheapest (~60% savings).
1h TTL — all hits18.2 unitsGood (~40% savings).
5m TTL — all misses37.5 unitsWorse than no cache.
1h TTL — all misses60.0 unitsMost expensive (2x base rate).

Some takeaways and tips