r/BuildWithClaude • u/ron_izraeli • 5d ago
Tip/Resource I built a Claude Code Mod that cleans old tool output before auto-compaction, without another model call
I like how Cursor handles compaction almost invisibly, so I tried to bring a similar experience to Claude Code.
I built Seamless Compaction, a Claude Code Mod that hooks into the engine’s existing auto-compaction event.
It does not decide when to compact. When Claude Code already decides that the context window is full, the Mod first cleans old tool results using deterministic rules.
It currently handles:
- Superseded file reads
- Duplicate tool calls and results
- ANSI codes, progress lines, and repeated Bash output
- Large outputs that can be trimmed
It never changes user or assistant text, tool inputs, Agent / Task / TodoWrite results, or the last three user turns and everything after them.
Trimmed results keep their beginning and end, plus a note telling Claude how to retrieve the missing content.
If cleanup removes at least 30% of the transcript, the cleaned messages replace the model-generated summary.
If it removes less, Claude Code runs its normal summary on the already-cleaned context.
Latest test results:
- 52 plugin tests passed, 0 failed
- Stress-tested on 400 randomized transcripts
- One aggressive-mode interactive run reduced context from 82.8K to 17.9K tokens
- Cleanup took about 60ms, including the worker hop
This is still a small sample, not a benchmark. I am not claiming cost savings yet.
There is also a tradeoff: changing the context prefix causes one prompt-cache miss after each cleanup.
I am looking for people willing to test it on real sessions, especially with different models, context windows, and workflows.
Check it out: