compact-prep — Claude Code command: what it does, how to install
compact-prep — a Claude slash command that tidies the work state before the context window fills up, then hands you prompts for compacting the session and resuming it.
Apache-2.0 ★ 173 updated 2026-10-24
.claude/commands/compact-prep.mdWhat compact-prep does
Reach for this command when a Claude session is running out of context. It tells the agent to tidy up the work state first, then hands you two short prompts: one for whatever compacts the transcript, one for picking the work back up.
State updates happen only where they apply. A development plan gets refreshed, CLAUDE.md too if that is where you keep in-flight work rather than rules, stale lines are dropped and next steps corrected. Mid-debug, the agent writes down how far it got and which attempts failed.
Then come the prompts. The compacting agent already knows its job, so it only needs the parts that are easy to lose, above all the reasoning behind decisions. The continuation prompt assumes the next session opens the same files under the same CLAUDE.md rules. Neither is indented or decorated, so you can paste it straight in. Extra instructions can be passed as an argument. Skip the state step and the compactor works from the transcript alone, while your plan keeps yesterday's next steps.
What it helps with
- Keep the dev plan current before compaction
- Drop stale next steps from
CLAUDE.md - Record how far a tricky debugging session got
- Hand the compactor the reasoning, not just the task list
- Restart work in a fresh session without losing the thread
Example prompts for the agent
/compact-prepcontext is nearly full, get the state and the prompts ready/compact-prepwe already ruled out the mutex fix, keep that in mind/compact-prepwe track this work in the dev plan, update it first
How to install compact-prep
Manually: put the files in place
.claude/commands/compact-prep.mdCall it with /compact-prep. For all projects use ~/.claude/commands/
Manually: put the files in place
~/.codex/prompts/compact-prep.mdCall it with /prompts:compact-prep. Codex marks this format deprecated in favour of skills
Manually: put the files in place
.github/prompts/compact-prep.prompt.mdManually: put the files in place
.gemini/commands/compact-prep.tomlGemini stores commands as TOML: the prompt text goes into the prompt field
Questions about compact-prep
How do I install compact-prep in Claude Code?
Copy the command file to .claude/commands/compact-prep.md in your project. It is then available as /compact-prep.
What does compact-prep do?
It asks the agent to bring the current work state up to date, then produces two short prompts: one for the compaction step, one for continuing afterwards.
Do I have to pass an argument?
No. [optional additional instructions] is optional and only adds extra guidance to the request.
Source text
compact-prep.md · Apache-2.0
--- description: Ask the agent to prepare for conversation compaction by updating any relevant state and providing guidance for the compaction agent and to kick off the session there after argument-hint: "[optional additional instructions]" --- # This is an automated message to state that the context window usage is getting high and the user is going to run a compaction As such, could you please: 1. (Only if applicable) Update any state that tracks the work currently in progress / the state of the tasks being worked on, e.g. A development plan if operating from one, the CLAUDE.md ( Only if that is where the user has asked you to track in flight work and it does not only contain rules), etc... to ensure it's up to date without any now outdated or invalid information, if it has next steps that they are correct, and if you're mid troubleshooting a complex problem - where you've got to and what you've tried so far (but keep it concise). 2. Give me a concise prompt that I can provide to the compaction agent that will be compacting our conversation to ensure the signal to noise ratio is kept high and focused. The agent will already be aware of it's task to compact the conversation so only needs additional guidance on specific things that may not be obvious but are important to keep (e.g. the WHY not just the WHAT). 3. Give me a concise prompt that I can provide to continue our work after compaction is complete. Keep in mind that the new agent / session will have access to the same files and will have the same CLAUDE.md agent rules in context. Be terse / concise. Don't add filler. Less is more. The agent reading this is a capable model, not an audience. TLDRs are great. Note: You must not quote, indent or format the prompts in any way that might impact me copying and pasting them without cleaning them up. --- `$ARGUMENTS`
© sammcj · Apache-2.0 · sammcj/agentic-coding