If you have ever built anything on top of a large language model, you know the quiet dread of the token bill. Every file you paste into the prompt, every log dump, every fat JSON response from an API, it all gets counted and charged. And a huge slice of what you are paying for is repetition the model does not actually need to see. Claw Compactor is an open-source tool that tackles exactly that: it shrinks the text you send to a model before it leaves your machine, so you are paying for signal instead of padding.
Quick facts
License: MIT (do basically whatever you want with it). Primary language: Python, with a bit of JavaScript around the edges. Last active: release v7.1.0 landed in March 2026, and the project sits at around 2,200 stars on GitHub as of 4 Jul 2026. You can install it straight from PyPI with pip install claw-compactor, and it runs with zero required dependencies.
What it actually is
At its core, Claw Compactor is a token compression engine. A token is just the unit an AI model reads and bills you for, roughly a word-chunk, and the fewer of them you send, the less you pay and the more room you have in the context window (the model's limited short-term memory).
The clever part is that it does this without calling another AI model to do the trimming. A lot of prompt-compression tools quietly run a second model to decide what to cut, which means more cost and more waiting. Claw Compactor runs a chain of 14 plain, rule-based stages it calls the Fusion Pipeline. Each stage is a small specialist. One folds up thousands of near-identical log lines into a single line with a count. One samples a giant JSON array down to a representative slice while keeping the schema and any errors intact. One reads code structure through a parser so it can compress around identifiers without ever renaming your variables.
The stages are picky on purpose. Before any stage does work, it checks whether the content is even its kind of job. Feed it a Python file and the log-folding stage just steps aside. That gate-first design means it is fast, usually under 50 milliseconds, because nothing runs where it does not belong.
The problem it solves
Picture an AI coding agent working through a bug. To do its job it gets handed the failing file, a stack trace, the output of a search across the repo, and a chunk of git diff. Half of that payload is noise: forty identical timeout warnings in the log, the same import block repeated across files, unchanged context lines wrapping a two-line diff. The model pays full price to read all of it.
Claw Compactor sits in front of that moment. It looks at each piece, works out what type it is, and compresses it in a way that keeps the meaning a model needs while dropping the dead weight. On a real benchmark the project ran, a mixed workspace of 47 files went from about 235,000 tokens to 108,000, a bit over half, in under a tenth of a second.
Where it is useful
A solo developer running an AI agent on their own codebase can slot it in before each model call and watch a workspace that used to blow past the context limit suddenly fit, with the monthly API bill dropping alongside it.
A team shipping a customer-support bot that pulls in long JSON records from a database can hand those records to the JSON stage, which samples them down to a representative shape so the model still answers correctly on a fraction of the tokens.
An infra engineer feeding build logs to a model for automated triage can fold thousands of repeated lines into counts, so the model sees the one error that matters instead of scrolling past the same warning five hundred times.
A researcher benchmarking prompt costs can use the built-in dry-run report to measure exactly where tokens are going across a workspace, before changing a single line of their pipeline.
Why it stands out
Two things make it worth a look. First, it is reversible. When a stage compresses a section, it can stash the original in a small hash-addressed store and leave a marker behind. If the model later decides it really does need that full JSON blob, it can ask for it back by the marker's ID. Most compression throws the original away and hopes for the best; this one keeps a receipt.
Second, it is genuinely content-aware. Instead of one blunt rule applied to everything, it routes code, JSON, logs, diffs, and search results down different paths, because squeezing a stack trace and squeezing a Python function are not the same problem. The project also claims 1,600-plus tests behind it, which for a tool sitting in your prompt path is reassuring rather than decorative.
The honest caveat: compression rates swing a lot with what you feed it. The project quotes anywhere from 15% on dense source code to about 82% on repetitive JSON. So the win depends heavily on your workload. If your prompts are already lean prose, do not expect miracles. If they are stuffed with logs and API dumps, this is where it shines.
How to get started
The quickest way in is the non-destructive benchmark, which tells you what you would save without touching anything:
pip install claw-compactor
claw-compactor benchmark /path/to/workspace
That prints a per-stage report: how much each stage trimmed, how long it took, and the estimated dollar savings. When you are ready to actually compress, swap benchmark for compress. If you want exact token counts rather than estimates, pip install claw-compactor[accurate] pulls in the tokenizer. For programmatic use there is a FusionEngine class you can call on a single string or a whole list of chat messages, and it hands back the compressed text plus per-stage stats.
Takeaway
Claw Compactor is a practical answer to a boring, expensive problem: you are paying a model to read the same thing over and over. It will not rewrite your prompts or think for you, and the payoff depends on how repetitive your inputs are. But it is free, it is fast, it keeps a way back to the originals, and it does not need a second AI to work. If your token bill has been creeping up, an afternoon spent running the benchmark against your own workspace will tell you pretty quickly whether it is worth wiring in.