compache: fitting context compaction and prompt caching together cuts chat cost ~79%
BarendPotijk · reddit · 2026-11-27
An open-source package, compache, argues context compaction and prompt caching are one decision, not two: compacting rewrites the prefix and kills the cache you paid for, while keeping a cache warm costs in proportion to what you keep.
- On a modeled 30-turn, retrieval-heavy chat (25k retrieved tokens/turn) on Claude Sonnet 5.5: full history + caching costs $16.48, OpenClaw defaults $7.69, compache $3.47.
- Fit 1 decides what to keep when compacting: retrieved text was 95% of history but reused in only 1/8 of turns, so it keeps questions 4 turns, answers 9, retrieved text 1 — 82% of history-needing turns still hit.
- Fit 2 decides when to ping the cache warm vs. let it lapse and cut; cuts wait for expired-cache returns so the rewrite costs nothing extra. One chat cut 8 times, last request 25k vs 89k tokens.
- Policies fitted to user return cadence cost 30–70% less than the best cache-only setting. Includes a browser-side cost calculator, one-line integration (compache.wrap(Anthropic(), "policy.json")), record mode then compache fit. Live on Claude Haiku 5.5: $2.68 → $1.45 per 1,000 messages. Apache-2.0, zero dependencies.
More from coding & agent
- Neural Core War: two LLMs battle by rewriting the weights of a shared third model — StartupYou · 2026-11-27
- Google's Antigravity to let users create AI agents directly from its UI — testingcatalog · 2026-11-27
- AI agency postmortem: boring agent use cases survive, autonomous ones die in weeks — rocketeams · 2026-11-27
- nichochar: agent-to-agent communication remains basically unsolved — _AustinCalvert_ · 2026-11-27
- Researchers open-source QuantMind, a free AI alternative to $25K/year Bloomberg Terminal — mdancho84 · 2026-11-27
- shadcn adds Report a Bug to ui-sdk skill: agents confirm, dedupe, then file — shadcn · 2026-11-27