A new open-source tool called Kvleak is challenging the assumption that a high cache hit rate equates to efficient spending in Claude Code environments. Developed by shangliy, the tool analyzes local session files from Claude Code, Codex CLI, Gemini CLI, and OpenCode to reveal where input spend is actually leaking. In the maintainer's own 30-day audit, despite a reported cache hit rate of 95.4%, nearly a fifth of the input spendβspecifically $537.72 out of $2,602βwas lost to cache rebuilds and cold starts. This discrepancy highlights a critical blind spot in how developers monitor API costs for agentic workflows.
The Illusion of Efficiency
The core issue Kvleak identifies is that standard metrics fail to capture the true cost of cache misses. A cache hit typically costs 0.1Γ the input price, while a rebuild can cost 1.25β2Γ. Because a single miss on a large context window can negate the savings of dozens of hits, the aggregate hit rate remains deceptively high even when significant dollars are wasted. Kvleak prices only the avoidable portion of each miss, distinguishing between necessary reads and wasteful rebuilds. The audit revealed that 69.2% of the leak came from idle gaps that outlived the cache TTL, while 15.2% stemmed from new session cold starts.
Automated Tuning and Fixes
Beyond diagnostics, Kvleak offers a suite of commands to optimize configuration. The kvleak tune command replays the last 30 days of usage under various settings to determine optimal values for autoCompactWindow, cache TTLs, and idle compaction thresholds. In the example provided, adjusting the auto-compact window from automatic (~967k) to 200k resulted in a projected $720.52 saving over 30 days. Similarly, reducing the bashOutputMaxChars limit from 30,000 to 8,000 saved $32.54, addressing the fact that Bash results accounted for 29% of context entry. These changes are applied directly to settings.json with a backup option for easy reversal.
Context Hygiene and Live Monitoring
The tool also addresses context bloat through hooks and refinement rules. kvleak hooks keeps long shell outputs out of the context by archiving them and replacing them with head/tail summaries, while kvleak refine injects evidence-gated hygiene rules into CLAUDE.md. A live status line plugin provides real-time feedback, displaying a cache TTL countdown and the cost of a potential rebuild. This allows developers to make informed decisions about when to manually compact context or keep a session alive, turning opaque API usage into visible, actionable data.
Key Takeaways
- High cache hit rates (e.g., 95.4%) can still mask significant financial leaks from rebuilds and cold starts.
- Kvleak analyzes local session files from multiple CLI tools without requiring API keys or network calls.
- Tuning settings like
autoCompactWindowandbashOutputMaxCharscan yield substantial savings, as shown by a $720 saving from window adjustment alone. - The tool provides a live status line to monitor cache TTL and rebuild costs in real-time.
- Idle gaps are the primary source of cache leaks, accounting for over 69% of the wasted spend in the example audit.
The Bottom Line
If you are running agentic workflows at scale, your dashboard is lying to you; Kvleak proves that visibility into cache rebuild costs is just as critical as the hit rate itself.