Compaction
Also called /compact · Context summarization
Replacing the session so far with a shorter summary of it, freeing the context window at the cost of detail.
Compaction shrinks a session by replacing its history with a summary. The harness asks the model to condense everything so far, throws away the original messages and tool results, and continues with the summary in their place. The context window gets room back; what you keep is a secondary source account of what happened rather than the record itself. In Claude Code the manual command is /compact.
The cost is silent. The summary keeps what the model judged important, which is not always what you will need next. A constraint you mentioned once, a file path, the exact error text, the reason a fix was rejected: any of them can vanish, and the agent that continues has no idea it is missing something. The first few turns after compaction are where confident mistakes cluster.
Compact deliberately, at a natural boundary, and tell the harness what to preserve: “keep the list of files changed and the failing test names.” Better still, write the important state to disk first so it survives regardless. If the summary would need to carry a lot, that is a sign to write a handoff artifact and use clearing instead. Compaction is a bridge, not a memory system.
- Claude Code
/compactaccepts instructions, e.g./compact keep the migration checklist; the summary replaces the transcript. - CodexThe CLI has its own
/compact; treat it the same way and start a new task when a summary would lose too much. - Most toolsAfter any compaction, re-read the files you care about rather than trusting the summary.
“Context is at ninety percent and I'm mid-refactor.”
“Compact it, but tell it what to keep: the module list and the test that's still red.”
“Won't it forget the API constraint?”
“It might. Put that line in the repo notes before you compact, then it can't.”
Course 01 puts every one of these terms to work: you install Claude Code, run the loop, and ship a real project — permission modes, compaction, hooks and all.
Start Course 01 →