Is a 99% Cache Hit Rate in AI Coding Tools Normal?

    This article explains whether a 96%–99% input cache hit rate in AI coding tools is normal, how prefill and decode differ, why coding workflows often produce high hit rates, how to verify the metric, and what a high cache hit rate does and does not indicate about cost, latency, and code quality.

    1. Short answer: A high hit rate can be normal, but the metric definition matters

    When an AI coding tool shows an input cache hit rate of 96%–99% across multiple consecutive requests, this is technically possible. However, the number alone does not prove that the tool is highly efficient, nor does it prove that something is wrong with the service.

    To judge whether the rate is normal, three questions need to be answered first:

    1. What is being cached? Is it the computed state corresponding to an input prefix, or a complete response?
    2. How is the ratio calculated? Is it the proportion of cached input tokens among all input tokens, or the proportion of requests with a cache hit among all requests?
    3. Is the context highly repetitive? Does the tool submit a large amount of the same system instructions, tool descriptions, code context, and conversation history in every turn?

    In many AI coding scenarios, a high hit rate often comes from the third point: each turn adds only a small amount of new content, while the request carries a long history of previous context. As a result, the model service can reuse most of the input prefix and only process the new or changed portion.

    This is a conditional explanation. Without request logs, usage details, and service-side rules, a single percentage cannot confirm the exact cause of a particular run.

    2. Before understanding caching, distinguish prefill from decode

    For a typical autoregressive large language model, one generation process can usually be divided into two stages: prefill and decode.

    2.1 Prefill: processing the input context

    The prefill stage processes the input tokens of the current request, including system instructions, user questions, historical messages, code snippets, and tool results.

    The model computes intermediate states for these input tokens and forms key and value states in the attention layers that can be used for subsequent generation. These are commonly referred to as the KV cache. Here, a token is the basic unit the model uses to process text, and it does not necessarily correspond to one Chinese character or one English word.

    Prefill is often highly parallelizable. In general, longer input means more computation and higher memory requirements. However, the actual cost also depends on the model architecture, attention implementation, hardware, batching, and scheduling strategy. It is not correct to assume that all long inputs have the same cost curve.

    Prefill does not happen only when a user starts a session. Whenever a later request submits context that needs to be processed, prefill work may occur. A cache hit can reduce repeated computation for the reusable portion.

    2.2 Decode: generating output step by step

    The decode stage continuously predicts subsequent tokens based on the existing context and already generated content, and adds new states to the cache.

    In common low-concurrency, small-batch situations, decoding may be more constrained by memory bandwidth and state-reading overhead. Under other deployment conditions, the bottleneck may be different. Therefore, the claim that “compute cores are idle during decoding” is not universally true.

    For cache benefits, the most important distinction is:

    Input caching mainly reduces repeated processing of input; it does not directly eliminate the work of generating a new answer.

    Even if the input hit rate reaches 99%, the model still needs to generate code, explanations, or analysis for the current task. If the output is long, decoding may still account for a significant portion of time and cost.

    3. An input cache hit does not mean returning an old answer directly

    The word “cache” can mean different things in different systems. At least two categories need to be distinguished.

    3.1 Input prefix caching

    Input prefix caching reuses the computed state corresponding to the same input prefix.

    For example, the input of a previous request may be:

    Fixed instructions + tool definitions + project background + conversation history

    The next request becomes:

    Fixed instructions + tool definitions + project background + conversation history + new question

    If the preceding token sequence remains unchanged and satisfies the service-side caching rules, the system may reuse the existing state and only process the newly added portion.

    The model is not skipping understanding of the current question. It is avoiding recomputation of the same prefix that has already been processed.

    3.2 Complete response caching

    Complete response caching stores a mapping between a request and a final answer. After a hit, the system may directly return the previously saved answer without performing the same generation process.

    This is not the same mechanism as input prefix caching. Therefore, seeing a high “input cache hit rate” does not imply that the model is constantly copying old code or that it is not generating answers again.

    Similarly, the KV cache used during ordinary generation needs to be distinguished from a cross-request prefix cache. The former is used to reuse historical states within a single generation. The latter requires service-side support for cache retention, lookup, isolation, and reuse.

    4. Why AI coding tools often show hit rates of 96%–99%

    4.1 Coding tools often repeatedly submit a long shared prefix

    The content an AI coding tool sends to the model is usually much more than the single question visible in the interface. A request may include:

    • Stable role and behavior instructions;
    • Tool-calling instructions;
    • Project directories and development conventions;
    • Code content that has already been read;
    • Conversation history;
    • Results from the previous execution round.

    If this information is placed at the front of the input and remains unchanged across multiple turns, it forms a long reusable prefix.

    The following hypothetical example is only used to illustrate the calculation relationship:

    Item Tokens
    Total input tokens for this request 40,000
    Cached input tokens 39,200
    Uncached input tokens 800

    Using the input-token metric:

    Cache hit rate = 39,200 ÷ 40,000 = 98%

    This number reflects how much of the input can be reused. It does not mean that total inference cost has dropped by 98%.

    4.2 Multi-turn coding naturally creates append-style context

    Coding tasks often proceed in the order of “read code → modify a local part → run checks → fix issues.” Each step needs to carry forward the previous task background, but the newly added information may be only an error message or a modification request.

    When the tool appends new information to the end of the existing context, the earlier content is likely to remain unchanged, and the cache hit rate may be high.

    4.3 Local modifications help stabilize context, but they are not sufficient

    Modular development usually reduces the amount of new information that must be introduced in each turn. However, “only one file is modified” does not automatically mean a high cache hit rate.

    What really affects prefix caching is: at which position the token sequence sent to the model changes.

    If the tool inserts the latest file content at the very beginning of the request, even a one-line code change may break a long shared prefix. In contrast, if the changed content is concentrated at the end, it is more favorable for reusing the stable content before it.

    Therefore, a modular workflow helps, but the way the request is constructed matters more directly.

    4.4 Tool orchestration may deliberately maintain cache-friendly request structures

    Some general orchestration designs fix the order of tool definitions, avoid unnecessary content reordering, and place frequently changing information at the end. These practices can improve prefix stability.

    However, a high hit rate alone is not enough to conclude that the model has been specially trained with some kind of caching capability for coding. Caching is often a mechanism at the inference-service and tool-orchestration levels, and specific evidence is needed to determine the implementation.

    5. Verification metrics: confirm the numerator, denominator, and observation scope first

    5.1 Token hit rate and request hit rate are different

    Input token hit rate can usually be expressed as:

    Input token hit rate = cached input tokens ÷ all input tokens

    Request hit rate can be expressed as:

    Request hit rate = requests with a cache hit ÷ all requests

    These two metrics describe different things. A request may be counted as a “hit request” even if only a small amount of input was cached. Conversely, if most long requests reuse a large prefix, the token hit rate may be very high.

    5.2 Do not simply average per-turn percentages when aggregating

    Suppose the data for two requests is as follows:

    • Request A: 100 input tokens, 0 cached;
    • Request B: 10,000 input tokens, 9,900 cached.

    Averaging the two percentages directly gives 49.5%. Calculating by total tokens gives approximately 98.02%.

    To evaluate overall input reuse, use:

    Overall hit rate = sum of cached tokens across all requests ÷ sum of input tokens across all requests

    Unless the observation target is specifically “average performance per request,” a simple average can be significantly misleading.

    5.3 Confirm whether counted items overlap

    Usage records may have different structures across services. Some include cached input within total input, some list cached and uncached input separately, and some include additional cache-write counts.

    Before calculating, confirm the field definitions to avoid double counting. Do not treat cache-write volume as cache-read hit volume, and do not mix output tokens into the denominator of an input hit rate without a clear metric definition.

    6. How much can a high hit rate actually save?

    6.1 Cost benefits depend on pricing

    If a service charges different prices for cached input, uncached input, and output, the total cost can be estimated conceptually as:

    Total cost = cached input volume × cached input unit price + uncached input volume × normal input unit price + output volume × output unit price + other applicable fees

    Some plans may also include cache-write, retention, or other fees, so the actual rules should be used.

    A high input hit rate usually helps reduce the cost of repeated input. However, if output accounts for a large proportion, the total cost reduction may be much smaller than the hit rate.

    6.2 Latency benefits mainly appear in repeated input processing

    Prefix reuse may reduce prefill work and improve the time to the first output token. However, end-to-end latency also includes queuing, cache-state access, network transmission, decoding, and tool execution.

    If most of the time in a task is spent running checks or generating long code, the total latency improvement from input caching may be limited.

    6.3 A high hit rate does not equal high efficiency

    If a tool carries a large amount of irrelevant history in every turn, the hit rate may look good, but the total context size is still large.

    Developers should also monitor:

    • Whether total input per turn keeps expanding;
    • Whether outputs are verbose or repeatedly rewritten;
    • Whether there are too many ineffective tool calls;
    • How many turns are needed to complete the task;
    • Whether the final code is correct.

    The truly valuable goal is to reduce the total cost of completing effective tasks, not to pursue a single percentage.

    7. How to organize more reasonable coding context

    7.1 Put stable information first and changing information later

    A conceptual order can be:

    Stable instructions → stable tool descriptions → project conventions → necessary background → history → current question and latest results

    This is not a mandatory format, but a general approach that helps maintain a shared prefix.

    7.2 Avoid changing the prefix unnecessarily

    Timestamps, random identifiers, field-order changes, and tool-definition reordering may all cause changes in the early tokens.

    Prefix caching usually relies on exact sequence matching, not on “roughly the same meaning.” Therefore, semantically similar content with different wording may not reuse the same cache.

    7.3 Provide only necessary and up-to-date code

    Do not keep outdated code just to improve the hit rate. Caching should serve correct context, not make the tool continue using old file versions.

    A more reasonable approach is to clearly indicate the current code state, remove duplicate material, and rebuild the context when necessary. Even if the hit rate decreases, it is still a valid optimization as long as task correctness and total cost improve.

    7.4 Evaluate context reduction together with cache optimization

    Long-conversation summarization may reduce input size, but replacing original history with a summary may also break the existing cache prefix.

    Compare total cost, latency, and completion quality before and after summarization, rather than treating a lower hit rate as a regression. Sometimes a “shorter but lower-hit” request is more efficient than an “extremely long but high-hit” request.

    8. Troubleshooting: use controlled experiments to verify explanations

    Within the allowed environment and usage scope, record several groups of requests:

    1. Submit a fixed context for the first time;
    2. Submit the same input again;
    3. Keep the prefix unchanged and append only a short question;
    4. Modify a section at the front of the input;
    5. Repeat the request after waiting for a period of time.

    For each group, record input volume, cached volume, output volume, time to first output, and total latency.

    These observations can help determine whether caching exhibits prefix-reuse characteristics. However, the results are still affected by the minimum cache length, chunking method, retention time, model version, isolation scope, and scheduling. A single miss should not be directly judged as a failure, and a single high hit should not be treated as evidence that all scenarios are effective.

    If short requests consistently show a hit rate close to 100%, or if the statistics remain completely unchanged after the front part of the input has clearly changed, check the display metric, cumulative statistics scope, data refresh, and field interpretation first. The client cannot observe all service-side states, so troubleshooting should verify the data before inferring the mechanism.

    9. Summary: A high hit rate is a signal of context reuse, not a quality guarantee

    A 96%–99% input cache hit rate in AI coding is reasonable under the conditions of a stable long prefix, little new content per turn, and continuously valid caching.

    It usually means that the computed states of a large amount of repeated input are being reused, not that the model is directly returning old answers. It also cannot alone prove code quality, task efficiency, or total cost performance.

    The most reliable way to judge whether this metric is valuable is to check the metric definition, actual request structure, total input volume, cost, latency, and task results at the same time. The ultimate goal of cache optimization should be to reduce ineffective repeated computation and let the model complete tasks with correct and necessary context, rather than making the hit-rate number as close to 100% as possible.