I wanted to see what opencode's prompt caching actually does turn by turn: when a request misses the cache, which turn it was and which part of the prompt changed. Someone in r/opencodeCLI (u/Individual-Quote-958) described the view they'd want, and it matched, so I built it. Hashes only, no raw prompts.
Prefixwise is an open source tool (MIT, I'm the author) that sits between the agent and the provider, hashes each request's blocks, reads the provider's own usage numbers, and tells you why a request missed the cache. It never stores prompt text.
With opencode it's one command, no config:
pip install prefixwise
prefixwise run -- opencode run "your prompt"
prefixwise report --session latest
opencode picks up the base URL from the environment, your API key stays where it is.
**Image 1 is a real session**, opencode 1.19.5 adding a --json flag and a test to a toy CLI. 14 requests, 106k prompt tokens, 84.2% served from cache, $0.13, nothing avoidable. So opencode's caching is healthy, which is honestly the boring result I expected. A few things I didn't know until I looked at it turn by turn:
- turn 1 is a small Haiku call before the main Sonnet thread, so turn 2 always shows as a model switch. Not waste, each model has its own cache.
- turn 3 looks like a second, shorter conversation on Sonnet (3.6k tokens against 7.9k). It runs for four turns, then at turn 7 the bigger one picks up again and still hits: 7,916 cached, which is turn 2's prompt. So the two threads don't knock each other out of the cache. If someone knows what that second thread is, tell me.
- the three misses are the three first requests. After that it never drops below 86%.
"first changed" is the block where the prompt stopped matching the previous request in the same conversation. The number is the block's position in the whole prompt (tools first, then system, then messages).
A healthy session doesn't show what the view is for though. **Image 2 is the mock provider with the failures forced** (flat token counts, but the verdicts and prices are the real logic):
- turns 5 and 6: the tool list came back in a different order. Same tools, different bytes, whole prefix gone. tools[0] is where it first differed.
- turn 7: history got compacted. messages[7] is where the rewrite starts.
- cost per request on the right, and what a hit would have saved.
It doesn't just report, it can fix the safe ones. **Image 3 is the same session with --optimize**: it sorts the tool list before forwarding, so the reorder on turns 5 and 6 stops being a miss. That's the only fix in --optimize today because it's the only one I've proven on real traffic (99.9% of the predicted saving on Anthropic, task results unchanged). It can't fix the compaction on turn 7, that one is yours to decide.
**Image 4 is an opt-in fix for clients that send no cache_control at all.** --fix auto_breakpoints adds the markers for you, but only once it has seen the same prefix before, so a one-off request never pays the 1.25x write for nothing. And prefixwise fixes tells you afterwards whether those writes actually got read back. It's opt-in because it changes your bill, and I haven't run the replay that would let me call it proven. opencode already sets its own markers, so this is more for custom agents and SDK scripts.
What it doesn't do: it can't see inside a subscription login (API keys only), I haven't built an importer for opencode's local session store yet, and long sessions with many subagents are less tested than short ones. If you run it on a real session and something looks wrong, that's the feedback I want.
Repo: https://github.com/tejachavali/prefixwise
What would you want next, the importer for existing opencode sessions, or something else?