compact-guard — survive /compact
What this prevents
"After context compaction occurs during plan mode execution, Claude Code fails to re-read or reference the existing plan." — issue #24686
"Plan mode state lost after context compression." — issue #26061
You're 30 turns into a careful refactor. /compact runs (manually or
because you hit the auto-compact threshold). The summarizer
condenses everything, including the plan you were halfway through.
Claude wakes up on the other side without the plan, and you have to
re-prompt from scratch.
compact-guard snapshots the plan before compaction touches it,
then re-injects the snapshot as context immediately after, so the
post-compact turn starts knowing the current task, active todos,
files touched, and the most recent plan.
How it works (zero manual work for the user)
/compact (manual) or auto-compact at threshold
│
▼
PreCompact hook fires
│
▼
Read transcript → extract:
• Most recent user message (the current task)
• Latest TodoWrite todos (pending + in_progress only)
• Files edited this session (Edit / Write / MultiEdit)
• Last assistant text block (likely the working plan)
│
▼
Write .papercuts/compact-snapshots/<timestamp>.md
(keeps 5 most recent — oldest pruned)
Compaction runs. The summarizer eats most of the context.
Next session start with source="compact"
│
▼
SessionStart hook fires
│
▼
Read the latest snapshot → print to stdout
Claude Code auto-injects stdout as additional context
When you (the model) should invoke this skill manually
- User runs
/claude-papercuts:compact-guard - User asks "what was I doing before the compact?"
- User asks to see the latest pre-compact snapshot
- User says they lost their plan / their todos / their work after a compact ran
Manual invocation procedure
When asked to show compact-guard state:
- Check if
.papercuts/compact-snapshots/exists in the project root. - If not, tell the user no compaction has happened yet in this project — the directory will populate on the first PreCompact. Then stop.
- Otherwise, list the snapshots (sorted newest first). Tell the user:
- How many snapshots are stored
- The timestamp of each
- If asked for a specific snapshot, cat it to the user verbatim. The format is plain markdown — don't summarize.
- Never modify or delete snapshots automatically. If the user asks you to clean them up, ask for explicit confirmation first.
Snapshot format
Each snapshot is a markdown file in
.papercuts/compact-snapshots/<UTC-timestamp>.md:
# compact-guard snapshot
- **When:** 2026-05-16 09:14 UTC
- **Trigger:** auto-compact
- **Session:** abc123def456
## Current task (last user message)
> <the most recent user prompt>
## Active todos
- [in_progress] <todo content>
- [pending] <todo content>
## Files edited this session
- `src/middleware/auth.ts`
- `src/__tests__/auth.test.ts`
## Last assistant message (plan / summary)
<the last assistant text block — usually the working plan, capped at 1500 chars>
Sections that have nothing useful are omitted. Total snapshot file is uncapped because it's read on demand, not auto-injected into the system prompt.
What this skill does NOT do
- It does not block compaction. PreCompact runs read-only and exits 0.
- It does not modify the transcript. The snapshot is a separate file.
- It does not deduplicate snapshots. Five most-recent are kept, in case you want to inspect a series of compactions.
- It does not survive across projects. Snapshots live in
.papercuts/compact-snapshots/relative to the project's cwd. - It does not inject context on
/clear,/resume, or startup — only post-compact. Useamnesia-fixfor cross-session continuity.
Privacy
Snapshots are written to a local file in your project's .papercuts/
directory. No network calls. Add .papercuts/ to your .gitignore if
not already.
Deprecation plan
If Anthropic ships a compact-resilient plan-mode (per issues #24686 and #26061), this skill becomes a no-op and gets deprecated in the next monthly release with the date.