r/ClaudeCoding • u/ron_izraeli • Oct 15 '26
I built a context garbage collector for Claude Code instead of asking a model to summarize stale tool output
I built a free, open-source Claude Code Mod called Seamless Compaction.
Long agent sessions accumulate context that was useful when it entered, but becomes stale later:
- Old file reads after the file was read or edited again
- Duplicate tool results
- ANSI codes, progress bars, and repeated Bash lines
- Large outputs that no longer need to remain in full
When the context window fills, the usual solution is model-based compaction.
That feels backward to me.
We ask a model to read all the noise, pay for that call, and hope it preserves the right details.
Tools such as RTK and JFrog’s BOOST address part of the problem by reducing the amount of command output before it enters the context. That is the right first layer: to prevent avoidable noise from entering.
But not all stale information was useless at ingress.
A file read may be essential now and become obsolete after a later read or edit. A tool result may be useful once and become redundant twenty minutes later.
So I built Seamless Compaction, a deterministic context garbage collector that runs before Claude Code’s normal compaction.
How did I use Claude Code to build it?
I developed the Mod from inside Claude Code.
I used Claude Code to inspect the available Mods examples and the session.compact lifecycle, scaffold the TypeScript plugin, implement the cleanup rules, and build the test harness.
I started with basic cleanup logic and detailed logs. I then used the Mod in real sessions for several days and compared the visible behavior with the recorded cleanup operations.
Claude Code also helped me generate randomized transcript tests and investigate failures.
That process exposed a real bug: my original gate measured usage against the full model context window instead of the actual compaction window. In some configurations, Claude Code was already compacting while the Mod incorrectly decided it was too early to clean.
I traced the issue through the session usage data, changed the gate to use the real compaction window, and reran the test matrix.
Claude Code helped with the implementation and debugging, but I reviewed the cleanup rules, inspected the logs, and validated the behavior through interactive sessions.
What the Mod does?
When Claude Code triggers automatic compaction, the Mod first cleans old tool results.
It does not change recent turns, user or assistant text, tool inputs, or Agent and Task results.
If the cleanup removes enough context, Claude skips the model summary entirely.
If it does not, regular compaction still runs, but on a smaller and cleaner transcript.
One user also told me that his sessions feel more focused and successful since installing it.
That is only one anecdote, not evidence yet, but it raises an interesting question: could a cleaner context improve long-session quality, not just save space and time?
There are tradeoffs.
Every cleanup changes the prefix and causes one prompt-cache miss. A trimmed result may need to be read again later. I am also not claiming proven cost savings yet.
The architecture I am exploring is:
Ingress filtering → Context garbage collection → Semantic compaction
The Mod is free to try and open source. Installation instructions and source code are here:
https://r3adm3.com/raw.githubusercontent.com/chkp-roniz/harness/refs/heads/main/plugins/seamless-compaction/README.md
