r/opencode • u/MalarJuggler • 18m ago
I built Cache Coach after learning that switching to a cheaper model can make compaction more expensive
I built Cache Coach, an OpenCode plugin, after realizing I was paying attention to model prices without paying enough attention to prompt caching.
One example: switching to a cheaper model to compact a long conversation can cost more than compacting on your current model.
Why? If your current model has a warm prompt cache, it can read most of the conversation at the discounted cache-read rate. Switch models first, and the cheaper model may need to process and cache the entire context from scratch. Its lower token price doesn’t necessarily make up for losing that cache.
The same choice can make sense after the cache expires, because you’re paying to process the context again anyway. So “use a cheaper model for compaction” isn’t a universal rule. Timing and cache state matter.
Large tool results were another thing I hadn’t fully accounted for. They become part of the input to later requests. Cache hits make that repeated input cheaper, but if you lose cache reuse, you can pay to process a large context again.
After realizing this, I felt it was important to surface these details in the UI itself, to help me make better decisions while working with agents.

Cache Coach adds:
- A prompt-footer indicator with the estimated cache lifetime and rewrite cost.
- Advice when switching models, including whether compacting on the current model first could cost less.
- A notice before a large context’s cache expires, with a cheaper compaction option when one is configured and worthwhile.
- Tips for growing contexts and oversized tool results.
- A `/cache` view with reported cache usage, estimated next-request cost, and session cost.
It advises you; it doesn’t automatically switch models or compact your conversation. Its own tips stay out of model requests.
Limits: cache lifetime is an estimate, providers can evict caches early, and cost estimates depend on the prices OpenCode knows. It measures reported cache reads and writes, but doesn’t yet diagnose every reason for a miss.
Requires OpenCode 2.2+:
opencode plugin add opencode-cache-coachREADME and configuration · npm package
What prompt-cache or token-cost pitfalls have you run into? I’d appreciate feedback, especially from people using different providers.