Prompt compression squeezes the bulky, repeated context that AI coding agents resend every turn, cutting up to 92% of those tokens while accuracy holds. Claude Code and Codex carry a growing history of old context into each request, and you pay full price for it again and again. Compression shrinks the older, repetitive parts of that history before the request reaches the model, so the same work costs far less. This page explains, in plain terms, how it works and where it does and does not save.
The problem: you pay for the same context over and over
An AI coding agent does not send one prompt and stop. It works in a loop. On every turn it resends the running context, the earlier messages, the tool results, the files it looked at, so the model can keep the thread. That history only grows as the session goes on. By the time the agent is deep into a task, most of what it sends on each turn is old material it already sent before.
The catch is that the model bills you for the full input on every single turn. You are paying, again and again, to resend context the agent already paid to send earlier. On a long agentic session across a big codebase, that repeated context is the majority of the bill. This is a big reason Claude Code runs about $13 per developer per active day, roughly $150 to $250 per developer per month in Anthropic's own figures, with heavy users well above that.
Prompt caching helps a little here, and both providers offer it. But caching only discounts context that repeats byte for byte, and it expires. It never actively shrinks what you send. That gap is what compression fills.
How prompt compression works, in plain terms
The idea is simple: compress the old, repeated context and leave the fresh work alone. When a request comes through the gateway, Clawgate looks at the message history and compresses the older, repetitive parts of it before forwarding the request to the model. The meaning is preserved, but the token count drops.
What matters most is what compression never touches. To be specific and honest, these parts are always left exactly as they are:
- The recent turns. The latest user messages and tool results stay untouched, so the agent's current line of work is never altered.
- The system prompt. The instructions that shape how the model behaves are passed through unchanged.
- The tool definitions. The schemas the agent uses to call tools are left as is.
- Thinking blocks. When a model returns reasoning, those blocks are preserved byte for byte, because the provider validates them exactly.
And it always fails open. If compression cannot help a given request, or anything looks off, the request still goes through unchanged. It never blocks work and never puts a request at risk to chase a saving. The worst case is that a request simply is not compressed, which is exactly how it would have run without the feature on.
So compression works on the safe part: the older, repetitive context that piles up over a long session. That is where the tokens are, and it is the part the model does not need verbatim to keep doing good work.
Being honest about "up to 92%"
The savings vary by workload, and any honest answer has to say so. The 92% figure is an upper bound, not a promise for every request.
Where does it come from? Heavy agent workloads tend to be full of repetitive, structured material: JSON payloads, tool output, logs, the same file headers seen again and again. That kind of content compresses hard, because it is bulky and predictable. Those are the sessions that approach the top of the range.
Sessions that are mostly unique code and prose save less, and that is by design. Compression preserves unique code and prose rather than squeezing it, because that is the material the model actually needs in full to stay accurate. So a session of dense, one-of-a-kind reasoning will see a smaller cut than a session of repetitive log-chewing. We are not going to hand you a benchmark table of invented numbers. The honest pattern is this: the more repetitive structure your agent workload carries, the more compression saves, and repetitive workloads are common in real agentic coding.
This is also why compression pairs well with the other big token lever, model choice. The same task can cost many times more on one model than another, so routing routine work to a cheaper capable model and compressing the context that remains stack together.
Why the AI providers will not do this for you
Here is the plain reason compression is not built into Claude Code or Codex: tokens are the providers' revenue. Every token you resend is money in their pocket. They have little reason to actively shrink your input. They do offer prompt caching, which discounts exact repeats, but nothing that actively compresses context or routes your work to a cheaper model. Those levers move money away from them, so they leave them out.
That gap is why we built Clawgate, and it is worth being clear about what makes it different. No single existing tool did all three of the things a team actually needs, so we built one that does. Clawgate does all three in one place:
- Monitor and control. Hard-stop budgets in dollars, tokens, or sessions, per user and per project, plus model control. When a limit is hit the request is blocked, and it returns a 403 so the developer sees the message instead of a 429 that coding agents silently retry.
- Cut token usage. Prompt compression, up to 92% on heavy agent workloads, plus the ability to route work to cheaper capable models.
- Catch abuse and impersonation. Content-fingerprint detection catches leaked or shared keys and flags a request whose content does not match the project it claims.
Compression is the token-cutting piece of that picture. It sits next to hard-stop budgets and abuse detection, so you are not just watching a meter climb. This all started as an internal tool at Virstack that cut our own team's AI bill by 70% before it became a product, and compression was part of how we got there.
It is one switch, and the savings show up in dollars
Turning it on is not a project. Prompt compression is opt-in, per organization, and an admin flips one toggle in the dashboard. Developers change nothing. They keep using Claude Code or Codex pointed at the same gateway key, and the compression happens inside the gateway before the request goes out. There is nothing to install and no local config to touch.
Because Clawgate already sits in the request path, it can measure exactly what compression saved and show it back to you in dollars on the dashboard, not as a vague percentage. You see the real number for your own team's workload. Pair that with hard-stop budgets and full spend control, and you get both halves of the job: spend less per request, and never blow past the cap you set.
You can see how compression fits alongside budgets, model control, and abuse detection on the features page.
Frequently asked questions
What is prompt compression?
Prompt compression is a technique that shrinks the bulky, repeated context an AI coding agent sends to the model, so you pass along the same meaning in far fewer tokens. AI agents like Claude Code and Codex resend a growing history of context on every turn. Compression squeezes the older, repetitive parts of that history while leaving the fresh work untouched, which cuts the token count you pay for on each request.
Does compression hurt the model's accuracy?
Done carefully, no. Good prompt compression only touches older, repetitive context and preserves unique code and prose. In Clawgate the recent turns, the system prompt, the tool definitions, and thinking blocks are never altered, and compression always fails open, so if it cannot help a request the request still goes through unchanged. Savings are largest on repetitive material like JSON and logs, which is exactly the part a model does not need verbatim to stay accurate.
How much can prompt compression save?
It varies by workload. On heavy agent workloads full of repetitive JSON and logs, prompt compression can cut up to 92% of the tokens the agent resends each turn. Sessions that are mostly unique code or prose save less, because that material is preserved rather than squeezed. Clawgate shows the actual savings in dollars on the dashboard, so you see the real number for your team rather than a headline figure.
Do developers have to change anything?
No. Prompt compression in Clawgate is one switch an admin flips in the dashboard. Developers keep using Claude Code or Codex exactly as before, pointed at the same gateway key. The compression happens inside the gateway before the request reaches the model, so there is nothing to install and no local config to change.
Written by Chathuranga K, an engineer at Virstack.
Cut the tokens you resend on every turn
Flip on prompt compression, keep your team on Claude Code and Codex exactly as they are, and watch the savings land in dollars on the dashboard, alongside hard-stop budgets and abuse detection.