Show HN: Prefixwise – names why each LLM request missed the prompt cache A developer released Prefixwise, a proxy that sits between an AI agent and a model provider and names the specific cause of each prompt-cache miss, with a `pip install prefixwise` command and `--optimize` mode that repairs requests before they are sent. In a real run against the Anthropic API with Claude Sonnet 4.6, an eight-turn agent that reordered its tool list on turn 4 and again on turn 6 logged 26,932 prompt tokens, a 74.6% cache hit rate and $0.0356 in cost, of which 3,375 tokens ($0.0116, 12.5% of prompt tokens) were avoidable; turn 4 alone re-paid for 3,329 tokens ($0.0115) after a `tool_reserialize` change at `tools[0]`. Prefixwise also offers `prefixwise check` to fail CI when a code change would break the cache, auto-detects vLLM and SGLang behind a URL, and stores only hashes and counts rather than prompts. Your agent resends its whole conversation every turn, and one changed byte near the top means the provider charges full price for everything after it. Prefixwise tells you which byte, what it cost, and fixes the common causes for you. Providers and engines report how many tokens missed the prompt cache, not why . Prefixwise sits between your agent and the model and does four things: - Identify. One named cause for every request, with its evidence, its cost and its fix. - Fix. --optimize repairs the request before it is sent. Only fixes that passed a replay against live models. - Prevent. prefixwise check fails CI when a code change would break the cache. - Auto-detect. It recognises vLLM and SGLang behind a URL and, when the engine publishes KV events, subscribes to them on its own. It stores hashes and counts, never your prompts. pip install prefixwise prefixwise run -- claude any agent with an API key: claude, codex, opencode, your own prefixwise report --session latest the session turn by turn prefixwise run --optimize -- claude the same agent, with the proven fixes applied No API key Claude Code or Codex on a subscription ? prefixwise import claude-code reads the logs already on your machine. A real run against the Anthropic API Claude Sonnet 4.6 : an eight-turn agent whose tool list comes back in another order on turn 4 and returns on turn 6 the run, with the agent https://github.com/tejachavali/prefixwise/blob/main/experiments/demo/2026-11-10-optimize-real-run.md . bash $ prefixwise run --ledger before.db -- python agent.py 8 requests, 26,932 prompt tokens, 75% served from cache. Cost $0.0356. Avoidable: 3,375 tokens $0.0116 , 12.5% of prompt tokens. Fix these, biggest first: 1. The same tools were sent in a different order or format 2 requests, 3,375 tokens, $0.0116 . Fix: Send tools in a fixed order with deterministic serialization or let the proxy do it: prefixwise serve --fix canonical tools . Prefixwise can do it for you: prefixwise run --fix canonical tools proven Expected misses not waste : 1 x first request of a session: nothing to reuse yet. Four lines of the output are left out here: the proxy's address, the -- prefixwise: this run -- header, a note on 46 tokens written and never read, and the pointer to the ledger. The record has all of it. prefixwise report --ledger before.db --session latest shows where it happened: Session run-20261110-010636: 8 requests, 26,932 prompt tokens, cache hit rate 74.6%, 3,375 avoidable, cost $0.0356 claude-sonnet-4-6 turn prompt cached hit cause first changed cost avoidable avoidable $ ---- ------ ------ ----- ---------------- ------------- ------- --------- ----------- 1 3,286 0 0.0% first write - $0.0125 0 $0.0000 2 3,309 3,283 99.2% none messages 8 $0.0017 0 $0.0000 3 3,332 3,306 99.2% none messages 10 $0.0016 0 $0.0000 4 3,355 0 0.0% tool reserialize tools 0 $0.0132 3,329 $0.0115 5 3,378 3,352 99.2% none messages 14 $0.0019 0 $0.0000 6 3,401 3,329 97.9% tool reserialize tools 0 $0.0016 46 $0.0002 7 3,424 3,398 99.2% none messages 18 $0.0020 0 $0.0000 8 3,447 3,421 99.2% none messages 20 $0.0013 0 $0.0000 "first changed" is the block where the prompt stopped matching the previous request, counted over the whole prompt: tools, then system, then messages. Turn 4 paid for the whole prompt again. Turn 6 went back to the first order and read 3,329 tokens, the prefix turn 3 had written under that order: the older entry was still cached. With --optimize , same agent and same prompts: | | before | with --optimize | |---|---|---| | Served from cache | 74.6% | 87.1% | | Cost of the run | $0.0356 | $0.0250 | | Avoidable tokens | 3,375 | 0 | Every number is from a live run against real models, and each links to its record. The full table is in the guide https://github.com/tejachavali/prefixwise/blob/main/docs/GUIDE.md results . | Claim | Result | |---|---| | Agrees with Anthropic's own miss reason | 32 of 32 misses Anthropic named 1 https://github.com/tejachavali/prefixwise/blob/main/experiments/e1 hosted/runs/2026-11-06-anthropic-claude-haiku-5-5.md , 2 https://github.com/tejachavali/prefixwise/blob/main/experiments/e1 hosted/runs/2026-11-06-round4.md | | Names injected causes on open models | 120 of 120 on vLLM, vLLM + LMCache and SGLang vLLM https://github.com/tejachavali/prefixwise/blob/main/experiments/e1 open/runs/2026-11-06-colab-l4-qwen3-4b.md , LMCache and SGLang https://github.com/tejachavali/prefixwise/blob/main/experiments/e evict/runs/2026-11-07-colab-l4.md | | Tells an engine eviction from everything else | 5 of 5 , confirmed from KV events vLLM https://github.com/tejachavali/prefixwise/blob/main/experiments/e evict/runs/2026-11-07-colab-l4.md , SGLang https://github.com/tejachavali/prefixwise/blob/main/experiments/e evict/runs/2026-11-07-colab-l4-sglang-events.md ; a prefix LMCache or HiCache restored counted as a hit 5 of 5 , through the proxy and inside vLLM record https://github.com/tejachavali/prefixwise/blob/main/experiments/e evict/runs/2026-11-08-colab-l4-host-restored.md , inside vLLM https://github.com/tejachavali/prefixwise/blob/main/experiments/e evict/runs/2026-11-10-colab-l4-middleware-lmcache.md | | The tool-order fix saves what was predicted | 99.9% on Claude, 97.5% on vLLM, task success flat one of 60 turns changed on Qwen3-4B record https://github.com/tejachavali/prefixwise/blob/main/experiments/e4/runs/2026-11-06-live.md | | The cache-marker fix pays for itself | 106.8% of predicted savings, prompt cost down 85.6% with the write surcharge included, task success flat record https://github.com/tejachavali/prefixwise/blob/main/experiments/e4/runs/2026-11-09-auto-breakpoints-live.md | | Works with real agents | Claude Code, Codex, opencode, the Anthropic and OpenAI SDKs record https://github.com/tejachavali/prefixwise/blob/main/experiments/compat/2026-11-07.md , opencode https://github.com/tejachavali/prefixwise/blob/main/experiments/compat/2026-11-09-opencode-run.md | | Costs almost nothing | 3 ms per request at 2k tokens, 13 ms at 120k record https://github.com/tejachavali/prefixwise/blob/main/benchmarks/runs/2026-11-07-vm.md | Each takes about thirty seconds. All write the same ledger and print the same report. | You have | Do this | |---|---| | An agent you run from a terminal | prefixwise run --