It names the one cause of every cache miss, prices it the way your provider bills it, and fixes the common ones. It runs on your machines and never stores prompts.
# see it work: no key, no network $ pip install prefixwise $ prefixwise demo # then on your own traffic $ prefixwise import claude-code $ prefixwise run -- claude $ prefixwise serve --upstream https://api.anthropic.com
| Names the cause | One of 19 causes per miss, from a timestamp in the instructions to a GPU that evicted the cache. Where the evidence is missing it says unknown, rather than guess. |
| Prices it | Each call costed from the provider's own usage and a dated price table, and the cost of each completed task. |
| Fixes the common ones | Tool order and cache markers corrected before the request is sent, off by default, stepping aside if the provider rejects the change. |
| Guards releases | prefixwise check runs your agent's scenarios against a local stand-in and fails the build when a change would break reuse. |
Each request is compared with the previous turn of its own conversation, on the same model. The first difference in prompt order is the cause; anything later is kept as a secondary cause.
| Cause | What happened | Waste? | Typical fix |
|---|---|---|---|
| volatile_system | Only dates, times, ids or numbers changed in the instructions | waste | Move them to the end of the prompt or the latest message, in one fixed format |
| tool_reserialize | The same tools, in a different order or serialization | waste | Sort tools, or let the proxy do it (canonical_tools) |
| history_edit | Earlier messages rewritten without a compaction | waste | Append; don’t rewrite history |
| tool_result_mutation | An earlier tool result re-rendered or removed | waste | Freeze tool output once sent |
| retry_replay | An identical request within 60 seconds, nothing cached | waste | Check the retry logic |
| breakpoint_misplaced | Anthropic: no cache marker, or one left behind as the prompt grew | waste | Mark the end of the stable prefix, or use auto_breakpoints |
| system_edit | The instructions were reworded | depends | Batch prompt edits; don’t reword every turn |
| param_rendered | Tool choice, thinking, reasoning or format changed | depends | Keep those settings stable within a session |
| below_min_prefix | Shorter than the provider’s minimum cacheable prompt | depends | Mark a prefix at least the model’s minimum |
| evicted | The engine dropped this conversation’s blocks | depends | More KV-cache memory, or an offload tier |
| ttl_expired | The cache entry outlived its lifetime | not waste | Compact before long breaks, or a longer TTL |
| model_switch | First call to a different model | not waste | — |
| compaction_rewrite | The context was compacted | not waste | Compact at task boundaries, not every turn |
| tool_catalog_change | A tool was added or removed | not waste | Mask tools instead of removing them, if frequent |
| routing_miss | Sent to a server that never saw the conversation | not waste | Session affinity or a stable prompt_cache_key |
| fork_boundary | First turn of a forked conversation | not waste | — |
| first_write | First request of a session or conversation | not waste | — |
| none | Prefix reused; only new content uncached | not waste | — |
| unknown | Not enough evidence; never guessed | — | Send session and TTL headers, or turn on engine events |
| Test | Setup | Result |
|---|---|---|
| False alarms on real conversations | 71,346 calls replayed through LiteLLM, GitHub and eight Hugging Face datasets | 0 |
| Planted causes on open models | Qwen3-4B on vLLM, vLLM with LMCache, and SGLang | 120 / 120 |
| Changes named at scale | 5,994 requests, six kinds of change injected at random | 1,772 seen, 0 misnamed |
| A public two-week trace | Real provider traffic, read from cache-block fingerprints | 252,549 / 252,549 appends |
| Reasoning models re-read their last answer | Qwen3 and a DeepSeek-R1 distill on vLLM, engine events on | named on 47/50 and 25/25 turns |
| Tool-order fix: saving delivered | Same sessions, fix off and on, on a hosted API and on vLLM | 97.5–99.9% |
| Every verdict on a real session | 10,517 Claude Code calls, checked against the raw logs | all match |
| Proxy overhead | 2,000-token requests on a 4-CPU container | 2 to 4 ms |
| Under load | 300-second soak, one process | 33,358 requests, 0 errors |
Not yet measured live: Gemini and Azure against the real services. Each record is in the repository under experiments/.
The method, the evidence each cause needs, and the evaluation on real and injected agent traces.
@misc{chavali2026prefixwise,
title = {Why Did the Prompt Cache Miss? Per-Request
Cause Attribution for Agent Workloads},
author = {Chavali, Tejaswi},
year = {2026},
publisher = {Zenodo},
doi = {10.5281/zenodo.24331594}
}