Stop paying for your whole chat history on every message.
compache makes long chats and coding-agent sessions cheaper, with as many answers right. It sits between your app and the model API, sends the part of the history that still matters and makes the most of the prompt cache. You add one line.
Live on Claude Haiku 5.5, as billed. The chatbot already used the 5-minute prompt cache, Claude Code ran as it comes. All results
Highlights
- A lower bill for the same work. 42% to 49% less in live chats, 51% to 85% less in long coding sessions.
- One line. Wrap the client you have, or type
compache wrap claude. - Nothing to tune. It learns from your own traffic what later messages need and when users come back.
- Works with the prompt cache. It trims when the cache has expired anyway, and keeps it warm when that pays.
- Nothing is gone for good. The model can fetch trimmed text back before your app sees the reply.
- Private. Runs in your process, has no dependencies and talks only to your model provider.
Get started
pip install compache
A coding agent. One command, nothing to set. Also codex, opencode, gemini and others.
compache wrap claude
Your own chatbot. Record for a while, fit, then apply:
import compache
from anthropic import Anthropic
client = compache.wrap(Anthropic(), record="compache-record", sample=0.1) # changes nothing yet
compache fit compache-record --model claude-haiku-5-5 # prints what you would save
client = compache.wrap(Anthropic(), "policy.json") # saves it
The record holds sizes, times and token usage, never text. Recording adds about 5% to the bill, and some 600 messages were enough in our runs. Already have chat logs?
Or try it first, on four sample chats, without an API key:
compache demo
Fitted on 4 sample threads, 71 turns (71 labelled) for claude-sonnet-5-5.
Keep questions from the last 4 turns, answers from the last 9 turns and retrieved text from the last turn.
Send up to 1 keep-warm ping while a user is away.
82% of what the labelled turns need from earlier turns stays in view. The rest is fetched back, and that call is in the cost.
$16.10 per 1,000 turns against $50.25 keeping everything: 68% less.
Caching alone, at its best, would cost $18.66.
How it works
Models have no memory, so your app sends the whole conversation again with every message. Prompt caching makes that cheap until the user takes a break and the cache expires. Trimming sends less, but rewrites the history and throws the cache away. compache decides the two together.
- It trims when the cache is already gone, so rewriting the history costs nothing extra.
- It keeps the cache warm with a tiny request while a user is away, if that costs less than losing it, or asks Claude for its 1-hour cache.
- It leaves a short notice where text was trimmed, and the model fetches the text back when it needs it.
Every request is priced by the provider's cache rules on your own conversations, and the cheapest setting wins. Read more
Results
Less to pay than without compache, on conversations it had not seen:
| Live, billed | Modeled | |
|---|---|---|
| Document chats | 42% to 49% | 43% to 89% |
| Document chats already on the 1-hour cache | 18% | 30% to 79% |
| Coding agents, long sessions | 51% to 85% | – |
| Coding agents, sessions of some 50 calls | 16% | – |
| Coding agents, 174 public runs | – | 5% to 43% |
Live is on Claude Haiku 5.5, modeled on Claude Sonnet 5.5. As many answers were right and as many tasks solved, within chance. The modeled range comes from how long users are away:
It saves least in short chats and where the cache outlasts the breaks: 2% to 5% on GPT-6 Luna, whose cache lasts 30 minutes, with slightly fewer answers right, on too few messages to call. All benchmarks
What would you save? Try the cost calculator. Drop a chat log on it: it is read in your browser and sent nowhere.
Works with
| Your stack | What you add |
|---|---|
| Claude Code, Codex, OpenCode, Gemini CLI, Copilot CLI, Aider, Goose and other agents | compache wrap <agent> |
| OpenAI, Anthropic and Google GenAI SDKs, sync, async and streaming | compache.wrap(client, ...) |
| LangChain and LangGraph | compache.langchain.middleware(...) |
| LiteLLM | compache.litellm.install(...) |
| OpenAI Agents SDK, Pydantic AI, LlamaIndex, Google ADK, Hermes and more | One line each |
| Anything with a base URL | compache proxy |
FAQ
I already use prompt caching. What does this add? Sending less, and knowing when. Modeled on document chats it costs 30% to 70% less than the cheapest cache setting alone.
How does it compare with Headroom or Kompressor? They make each tool result smaller. compache decides which parts are sent at all. Live on the same document chats it was 36% and 26% cheaper, with at least as many answers right. Those chats are prose, and Headroom is made for structured tool output.
Does it work in serverless functions? Trimming does: no state is kept outside the process. Keep-warm pings need a process that stays up, so fit with ping_counts=(0,).
What if something goes wrong? A request the provider refuses after compache changed it is sent again as your app wrote it.
Documentation
Guide · Agents · Integrations · How it works · Other tools compared · Benchmarks · Calculator · Issues
License
Metadata
Release files for compache 0.15.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| compache-0.15.1.tar.gz | 1.3 MB | With provenance | Details for compache-0.15.1.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| compache-0.15.1-py3-none-any.whl | Python 3 | none | any | Details for compache-0.15.1-py3-none-any.whl |
Total release size: 1.9 MB
Release files / compache-0.15.1.tar.gz
| Download URL | compache-0.15.1.tar.gz |
|---|---|
| Size | 1.3 MB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
0a97b0d79b2900edbe23f9059b4665d5902fbfc04d205e638df8013e741341a8
|
|
BLAKE2b-256 checksum How to use checksums |
603189cc070bb5a6b97b79bfcdc84c4e483c8a8addac6395c03430fc550d6121
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Nov 25, 2026.
Transparency logRelease files / compache-0.15.1-py3-none-any.whl
| Download URL | compache-0.15.1-py3-none-any.whl |
|---|---|
| Size | 538.1 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
5bacf33c2694b9009a8a6eb4ad1c60e544d118341c08e8d58f107963aa56b9a9
|
|
BLAKE2b-256 checksum How to use checksums |
44aabda19d684647d24329f73cdf5a14e83000c1fb0f282f77c241708d6b4d51
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Nov 25, 2026.
Transparency logSecurity for compache 0.15.1
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
Full provenance
Both files in this release have been uploaded with provenance metadata.
Attestation for compache-0.15.1.tar.gz
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Nov 25, 2026.
Transparency logA note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.