{"slug": "the-compaction-plugin-i-was-releasing-warned-me-mid-release", "title": "The Compaction Plugin I Was Releasing Warned Me Mid-Release", "summary": "Developer Kenimo49 released compact-ops, a Claude Code plugin that protects AI coding sessions from context compaction by preserving operational state. During the release, the plugin successfully warned the developer when context usage hit 67% and later demonstrated fail-open behavior when hooks failed due to a stale path. The plugin stores structured state including session decisions and failed attempts for 30 days, re-injecting it on session resume.", "body_md": "At 3 a.m. I was finishing the release of [compact-ops](https://github.com/kenimo49/compact-ops), a Claude Code plugin that protects sessions from context compaction. Context usage hit 67%, and a notification appeared in my own session: threshold crossed, run `/compact`\n\nat a clean stopping point, here is your current plan and your latest decision. I wrote that warning. I was also the person it saved.\n\nTwenty minutes later the same session made the opposite point. I ran `/compact`\n\n, and all three of the plugin's hooks failed. During the release I had restructured the plugin's directory layout, so the running session was still holding a stale path. Compaction itself finished normally, because every hook is fail-open: if it breaks, it steps aside instead of blocking the built-in behavior. One session, one night, and I got to watch the feature work and watch it fail safely. You can't buy dogfooding like that.\n\nThis post covers what `/compact`\n\nactually throws away, what I borrowed from the plugin this one is derived from, and the six things I hardened before making the repo public.\n\nWhen a Claude Code session fills its context window, the whole conversation gets compressed into a single built-in summary and the original messages are discarded. Manual `/compact`\n\nand auto-compact both work this way.\n\nThe summary is decent at code. What it drops is operational state: \"the push was already approved\", \"we tried that approach and it failed\", \"that number came from this file\". When the post-compaction agent forgets those, it re-asks for permissions you already granted and re-attempts fixes you already buried. That's the failure mode I wanted insurance against.\n\nHere is the timeline with and without the plugin:\n\n| Moment | Standard Claude Code | With compact-ops |\n|---|---|---|\n| Usage passes 60% (configurable) | No warning; auto-compact arrives unannounced | One-shot reminder plus a 3-line recitation of plan / phase / latest decision |\n| At compact time | Built-in summary only | Same compression, plus a transcript backup and a separate LLM writing a 10-heading state file |\n| Right after compact | Agent continues from the summary alone | State file and a \"re-read the originals first\" note injected into the fresh context |\n| After the session ends | Summary exists only inside that session | State persists for 30 days and is re-injected on `claude --resume`\n|\n| If a hook fails | -- | Fail-open; standard compaction proceeds untouched |\n\nThe compaction algorithm itself is untouched. Everything runs through official hooks, from the outside.\n\nThe core idea is not mine. [u-ichi's compact-plus](https://github.com/u-ichi/compact-plus) (MIT) got there first: a PreCompact hook that calls a separate LLM to write structured state before the summary eats everything. It's the kind of tool you want installed the moment you read its README.\n\nMy setup had three mismatches with its assumptions, so I built a derivative instead of a fork and changed exactly three things:\n\n`message.usage`\n\nin the transcript.`$TMPDIR`\n\n, which is gone after a restart. If you resume yesterday's work every morning, that's no insurance at all. State now lives under `~/.claude/compact-ops/`\n\n, organized per project, kept for 30 days.`--resume`\n\n.I also made the LLM backend Claude-only (Sonnet primary, Haiku fallback). compact-plus falls back to Codex, which assumes a ChatGPT Pro subscription sitting next to your Claude one.\n\nBefore each compaction, a separate LLM writes a markdown file that always has the same 10 headings: Active Plan, Current Phase, TaskList Summary, Session Decisions, Constraints and Blockers, Worker Topology, Skills Invoked, Editing Files, Failed Attempts, Recovery Notes. The interesting ones are Session Decisions and Failed Attempts -- precisely the operational facts that built-in summaries tend to thin out.\n\nThe warning side reuses the same file. When usage crosses the threshold, the injected reminder isn't just \"compact soon\" -- it recites the top of your current state so the agent keeps the big picture during the messy turns right before a compact:\n\n```\n[COMPACT WARNING] Context usage reached 67% (134,102 / 200,000 tokens).\nState recitation:\n- Active Plan: Ship compact-ops v0.2.0 (hardening + marketplace fix)\n- Current Phase: post-release verification\n- Recent Session Decision: circular symlink removed; source is \"./\" now\n- At a natural work boundary, tell the user they can run /compact as-is.\n```\n\nThat recitation is what appeared in my session at 3 a.m. Reading your own plan back, written by a hook you wrote, is a strange kind of code review.\n\nSo the post-compaction agent restarts with two anchors: the standard summary and the structured state file. But the state file is never treated as authoritative. The injected recovery guidance explicitly says to re-read the original project files before trusting anything. An LLM summary trusted blindly by another LLM is just a faster game of telephone.\n\nIt's also a plain markdown file. When a handoff feels off, you can open it and see exactly what the previous session thought it was passing along.\n\nv0.1.0 was \"works on my machine\". Before flipping the repo public I ran my own review plus a second pass with an independent CLI reviewer, and shipped v0.2.0 with six fixes:\n\n`umask 077`\n\n; directories are 700, files are 600.`._-`\n\n, no `..`\n\n) before touching the filesystem.`COMPACT_OPS_DEBUG=1`\n\nnow logs every swallowed failure. If you're writing fail-open hooks, write the logging first. I did it in the wrong order and got lucky.The Claude Code ecosystem already has heavier answers to context loss: full memory layers with MCP tools, BM25 retrieval over past sessions, three-file dev-docs systems you maintain by hand. Good tools, different trade-offs.\n\ncompact-ops stays intentionally narrow: no MCP server, no database, no new workflow to learn, no daemon. It's shell scripts behind official hooks, and state is plain markdown you can `cat`\n\n. If it ever misbehaves, you uninstall the plugin and you're back to stock Claude Code -- there's nothing to migrate out of. I wanted the insurance to cost nothing when it isn't paying out.\n\nThe other non-feature: it never replaces the built-in summary. Tools that intercept or rewrite compaction itself break whenever Claude Code changes internals. Hooks are the supported surface, so that's the whole footprint.\n\n```\ngit clone https://github.com/kenimo49/compact-ops.git\nclaude plugin marketplace add /path/to/compact-ops --scope user\nclaude plugin install compact-ops@compact-ops-local\n```\n\nRequirements: Claude Code v2.x, `jq`\n\n, and the `claude`\n\nCLI as the state-writing backend. Linux and macOS. After installing, just run `/compact`\n\nas usual -- each compact costs one extra LLM call (Sonnet by default, downgradable to Haiku or off).\n\nThe plugin's first beneficiary was the session that built it: saved by its own 67% warning, then stress-tested by its own hook failure, in the same night. Agent tooling is like that -- the reasons for a design only get written down where something actually broke.\n\nWhat does your agent forget after `/compact`\n\n? If you have a story where a post-compaction session confidently undid your afternoon, I want to hear it.", "url": "https://wpnews.pro/news/the-compaction-plugin-i-was-releasing-warned-me-mid-release", "canonical_source": "https://dev.to/kenimo49/the-compaction-plugin-i-was-releasing-warned-me-mid-release-2f25", "published_at": "2026-07-07 13:00:00+00:00", "updated_at": "2026-07-07 13:28:51.699533+00:00", "lang": "en", "topics": ["developer-tools", "large-language-models", "ai-tools"], "entities": ["compact-ops", "Claude Code", "Kenimo49", "compact-plus", "u-ichi", "Sonnet", "Haiku"], "alternates": {"html": "https://wpnews.pro/news/the-compaction-plugin-i-was-releasing-warned-me-mid-release", "markdown": "https://wpnews.pro/news/the-compaction-plugin-i-was-releasing-warned-me-mid-release.md", "text": "https://wpnews.pro/news/the-compaction-plugin-i-was-releasing-warned-me-mid-release.txt", "jsonld": "https://wpnews.pro/news/the-compaction-plugin-i-was-releasing-warned-me-mid-release.jsonld"}}