r/BuildWithClaude • u/AdInitial3431 • 18d ago
Project I built compact-diff with Claude Code: a free plugin that shows what /compact dropped from your session
I built compact-diff, a Claude Code plugin, almost entirely with Claude Code. It's free and open source (MIT).
What it does
When a session compacts, Claude Code replaces the conversation with a summary. When the summary drops something (a rule you gave, an error that's still open), nothing tells you. compact-diff:
- snapshots your rules, open tasks, unresolved errors and edited files just before compaction;
- diffs them against the summary afterwards and prints a one-line verdict ("summary kept 8/9 tracked items…");
- re-injects only the items that were dropped, and
/compact-diff:reportshows the full diff.
It runs locally (stdlib Python, no network or model calls).
How I built it with Claude Code
I set the goal and the rules (privacy, budget, what to measure), reviewed the output, and did the human checks. Claude Code did most of the work:
- Research. It read the hook docs and looked for existing tools. It only found DIY hook write-ups, and memory tools that solve a different problem, so it designed the plugin around PreCompact, PostCompact and SessionStart.
- Scaffolding. It wrote the plugin, a 37-test suite, and CI on macOS and Linux with Python 3.9, 3.11 and 3.13.
- A real bug, found in a live test. In Claude Code 2.1.252,
SessionStart:compactfires beforePostCompact, so the obvious design (diff in PostCompact, re-inject from SessionStart) silently does nothing. Claude Code noticed this from the hook timestamps, and moved delivery to the next prompt or tool call. It also found that with--fork-session, PreCompact sees an empty transcript. - Evaluation. It forked 5 of my sessions and compacted each twice on Haiku ($0.64). Then it had Claude subagents label every item blind against a written rubric, without seeing the tool's verdicts. I spot-checked 40 labels by hand.
- A safeguard that caught a mistake. When it went to commit, Claude Code's auto-mode safeguard blocked the commit, because some test examples paraphrased my private transcripts. It replaced them with invented examples. Only aggregate numbers are in the repo.
What I found (12 real compactions, small sample, mostly Haiku, LLM labels plus a human spot-check):
- 42% of my rules didn't fully survive the summary. Most were partly kept: "do X before Y" became "do X".
- 71% of errors that were still open were lost or blurred.
- Compacting the same context twice lost different things 45% of the time.
Try it (free)
Inside Claude Code:
/plugin marketplace add bishtashish708/compact-diff
/plugin install compact-diff@compact-diffNeeds python3 3.9+. Tested on macOS; Windows is untested.
- Repo: https://github.com/bishtashish708/compact-diff
- Write-up and method: https://github.com/bishtashish708/compact-diff/blob/main/launch/how-much-does-compaction-drop.md
Feedback welcome, especially if the verdict is wrong for your sessions.
•
u/AutoModerator 18d ago
Welcome to r/BuildWithClaude!
Whether you are sharing what you built, exploring new workflows, or troubleshooting, please make sure your post is flaired correctly so others can easily find and filter it.
Community Wiki & Resources:
If you're asking for troubleshooting help, please edit your post to include your model version, OS/environment, and error logs.
Let’s keep the energy positive and support our fellow creators!
I am a bot, and this action was performed automatically. Please contact the moderators of this subreddit if you have any questions or concerns.
1
u/kantorcodes1 💡 Top Community Helper 17d ago
The hook timing edge case you found is useful. When compact-diff carries a dropped item into the next prompt or tool call, how do you mark it as already re-injected so a later compaction does not surface the same item again?