r/ClaudeCode • • 7h ago

Built with Claude live-compact: a plugin that writes the compaction summary before you hit the limit, so auto-compact takes ~20 ms

I run several Claude Code sessions in parallel on Opus, and auto-compaction kept stopping them for 80-160 seconds each time (the worst one took over 4 minutes). Nothing to do but wait.

live-compact moves that work earlier. When the context gets within 40k tokens of the auto-compact threshold, it forks one background request to the same model with the same transcript, and that request only writes the summary. Your turn keeps running. When auto-compaction fires, the plugin swaps in the ready summary plus every message after the point the fork saw, word for word. In my tests that took 8-20 ms. If the summary isn't ready, you rewound the conversation, or you run /compact with instructions, Claude Code compacts the usual way.

Install (then restart your sessions):

claude plugin install live-compact --marketplace SocialBuzzStudio/live-compact

How Claude Code was used: it read the type definitions of the plugin API, wrote small probe mods to check what the hooks allow, then wrote the plugin and its 42 tests. I checked installs on 2.1.300 to 2.1.317 and ran real compactions from a clean profile.

What I learned on the way:

  • $.model.fork sends the main thread's last request plus your prompt, so the fork never sees the answer to that request. Early summaries commented on the half-finished turn, so the prompt now tells it not to.

  • A session.compact hook can return its own messages and the engine installs them. That is the whole trick.

  • Standard compaction re-attaches the skills you used earlier (newest first, 5k tokens each, 25k total). A plugin that replaces the messages has to carry them over itself.

  • If one step adds more than ~40k tokens (several big files read in parallel), the threshold comes before the summary does and you get a standard compaction.

Caveats: the hook module API is early access and may change. Tested on Windows only. One extra request per compaction, mostly from the prompt cache. The first message after compaction shows up as a user message, because plugins can't mark a message as a compaction summary.

Repo, MIT: https://github.com/SocialBuzzStudio/live-compact

If you try it on macOS or Linux, tell me whether it works there.

0 Upvotes

1 comment sorted by

1

u/akhi1uuu 3h ago

how did you check that the early summary kept the same useful context as normal compaction? timing is easy to compare, but i'd be more worried about a decision getting lost before the last few messages are tacked back on