Automatic plan file backup and recovery for Claude Code.
Never lose a plan to context compaction again.
Claude Code's plan mode writes plans to ~/.claude/plans/*.md. After context compacting, writes to these files frequently fail with "Error writing file" — wasting tokens and losing your work.
Known issues:
- #12434 — Plan agent cannot write plan file, state lost (but tokens billed)
- #24151 — Plan mode: first file write always fails
- #23389 — Claude saves incomplete/wrong plan content
plan-guard uses three hooks to protect your plan files:
| Hook | Event | What it does |
|---|---|---|
| Backup | PreCompact |
Backs up active plan files before compaction happens |
| Re-inject | SessionStart (compact) |
Feeds plan content back to Claude after compaction |
| Recovery | PostToolUseFailure |
Catches write failures, creates a recovery file, and tells Claude to use it |
/plugin marketplace add kodareef5/plan-guard
/plugin install plan-guard
claude --plugin-dir ./plan-guardOnce installed, plan-guard runs automatically. No configuration needed.
- Backups are stored in
~/.claude/plans/.backups/(last 20 kept) - Recovery files are created alongside the original with a
-recovered-<timestamp>suffix - Run
/plan-guard:plan-statusto see your backup inventory
Before every compaction (auto or manual), all plan files modified in the last 30 minutes are copied to .backups/.
After compaction, the most recent plan file's content (first 150 lines) is fed back to Claude as context, so it remembers the plan file path and contents.
When a Write or Edit to a plan file fails:
- Checks for a backup of that plan
- Creates a new plan file with the backup content (or empty if no backup)
- Tells Claude: "Write to this new file instead"
jq(pre-installed on macOS,apt install jqon Linux)- Claude Code with plugin support
MIT