compact-guard — Claude Code command: what it does, how to install
compact-guard is a Claude Code command that saves working state before context compaction and restores critical data afterward. Run it before manual compaction or when auto-compaction warnings appear.
MIT ★ 2,966 updated 2026-09-29
/plugin marketplace add rohitg00/pro-workflow
/plugin install pro-workflow@pro-workflowWhat compact-guard does
Command records the current task, open files and session decisions, runs /compact, then brings back what matters. Claude Code restores only five files after compaction — five thousand tokens per file, fifty thousand total.
Run compact-guard before manual /compact or when you see auto-compact warnings. Command helps preserve active editing context and prevents loss of intermediate findings.
Prioritize the file you are editing now. Pass exploration results to subagents, keep drafts in a separate scratch file.
What it helps with
- save task state before forced context compaction
- restore critical data after automatic compaction
- avoid losing decisions and files when crossing task boundaries
Example prompts for the agent
- Run
/compact-guardbefore manual compaction. - Execute
/compact-guardwhen you get an auto-compact warning. - Use
/compact-guardat a task boundary to preserve intermediate results.
How to install compact-guard
1Plugin marketplace
/plugin marketplace add rohitg00/pro-workflow/plugin install pro-workflow@pro-workflow2Manually: put the files in place
.claude/commands/compact-guard.mdCall it with /compact-guard. For all projects use ~/.claude/commands/
Manually: put the files in place
~/.codex/prompts/compact-guard.mdCall it with /prompts:compact-guard. Codex marks this format deprecated in favour of skills
Manually: put the files in place
.github/prompts/compact-guard.prompt.mdManually: put the files in place
.gemini/commands/compact-guard.tomlGemini stores commands as TOML: the prompt text goes into the prompt field
Questions about compact-guard
How to install compact-guard in Claude Code?
Run /plugin marketplace add rohitg00/pro-workflow, then /plugin install pro-workflow@pro-workflow. The command will appear at .claude/commands/compact-guard.md.
What does compact-guard do?
Command records the current task, open files and decisions, runs /compact, then restores critical data. Claude Code brings back only five files after compaction.
How many files survive compaction?
Claude Code restores at most five files — five thousand tokens per file, fifty thousand total. Command compact-guard helps choose priorities.
Source text
compact-guard.md · MIT
--- description: Smart context compaction with state preservation — saves critical state before compact and restores after --- # /compact-guard - Protected Compaction Protect your working context through compaction. ## Quick Start Run before `/compact` to: 1. Save your current task state 2. Note which files you're editing (max 5 survive compaction) 3. Record decisions made this session 4. Compact safely 5. Restore critical context after ## When To Use - Before manual `/compact` - When you see auto-compact warnings - At natural task boundaries ## Key Insight Claude Code only restores **5 files** after compaction, with **5K tokens per file** and **50K total budget**. Plan accordingly: - Prioritize the file you're actively editing - Move exploration results to subagents - Keep notes in a scratch file ## Usage ```text /compact-guard ```
© Rohit Ghumare · MIT · rohitg00/pro-workflow