Why Coding Workloads Hit 90%+ Prompt Cache Hit Rates
This article explains why coding sessions with AI tools routinely achieve 96%–99% prompt cache hit rates, and why that is expected rather than a statistics error. It covers what KV caching stores, how the hit rate is defined on the input side, the structural traits of coding conversations that keep reusable prefixes large, the two engineering factors that cap hit rates (cache size and eviction pressure, plus tiered cache lifetime), a checklist for diagnosing low hit rates, and practical steps for keeping costs under control.
1. The short answer: high hit rates are normal for coding
Seeing a 96%–99% cache hit rate in an AI coding tool usually triggers one first reaction: “Is the metric being calculated wrong?” In practice, the number is exactly what the mechanics predict. The input structure of coding sessions means most tokens are a repeated prefix, so the cache hits naturally. The case that actually deserves scrutiny is the opposite one — a hit rate that stays low over time, which usually points to a problem in the caching strategy, session handling, or how usage is measured.
It is also worth stating that a high hit rate is not the goal in itself. Its value comes from two things: it directly affects billing, since cached input is typically charged at a lower rate; and it affects time to first token, because the more input is served from cache, the less attention state the server has to recompute.
2. What the cache actually stores: how KV caching works
When a large model processes input, it computes the key and value vectors needed for attention for every token. These intermediate results are collectively called the KV cache and are held in server GPU memory. When the prefix of a new request matches a previous request exactly, the server can skip that computation and reuse the stored results.
That gives a general definition of the hit rate:
hit rate ≈ input tokens served from cache / total input tokens in the request
Note that the denominator is on the input side and does not include generated output. This matters a lot when reconciling a bill — many “the numbers don’t add up” questions come from a mismatch between numerator and denominator.
3. Why coding sessions naturally score higher
Interactions between developers and AI have strong structural characteristics:
- Multi-turn iteration: follow-up change requests arrive within the same session rather than in a brand-new conversation each time.
- Stable prefix: every turn resends the full conversation history and the code generated so far.
- Tiny increments: what is genuinely new is often just a few dozen to a few hundred characters of change instructions.
Substitute these three points into the formula and the pattern is clear: as turns accumulate, the reusable prefix share rises monotonically, while the few-shot system prompt, project conventions, and existing file contents stay unchanged from start to finish. Anything above 90% is therefore a normal range, and 96%–99% is simply the natural result once two conditions hold — the session is never interrupted, and the prefix is never evicted.
4. Two engineering factors that set the ceiling
4.1 Cache size and eviction pressure
The KV cache occupies GPU memory, and capacity is limited. If the cache footprint grows too large, a small amount of concurrency is enough to push a given session’s prefix out, and the hit rate collapses. A common industry response is to compress the intermediate attention representation, reducing size along the sequence dimension so a longer context fits in less space — a general technical direction, with implementation details varying considerably.
4.2 Cache tiering and lifetime
Relying on GPU memory alone is like short-term storage: rising concurrency, a few minutes of session inactivity, or switching conversations can all clear the cache. A more robust approach is to tier it:
L1 GPU memory: current hot sessions, fastest readsL2 host memory: inactive sessions, quick to swap back inL3 storage: persistent stable prefixes, retained from minutes to hours
The direct benefit of tiering is that stepping away to look something up or revise a requirement still leaves the original prefix cacheable on return, instead of forcing a full recompute.
5. Checklist for a low hit rate
- Is a new session created every turn, so the prefix never accumulates?
- Has the session been idle for a long time, letting the hot cache expire?
- Do the system prompt or project conventions embed volatile content such as timestamps or random IDs, breaking prefix consistency?
- Are you switching frequently across platforms or models, whose caches are not shared?
- Is the metric being confused, with output tokens counted in the denominator?
6. Practical recommendations
- Try to finish one requirement within a single session and avoid needless restarts.
- Put stable content first and volatile content last, keeping the prefix byte-for-byte identical.
- Break long tasks into segments to avoid extended idle periods.
- Read the platform’s cache billing notes and monitoring metrics, and use the data to judge whether costs are reasonable.
For developers, holding the hit rate above 90% is a controllable and reusable cost optimization. If it stays significantly below that level over time, investigate session and caching strategy first rather than accepting the higher overhead by default.
