What compaction keeps and what it loses
Compaction swaps your history for a summary, then restores a few things by rule. Knowing which ones lets you steer it, and choose between /clear, /compact and rewind.
A summary replaces the history
When the window nears its limit, Claude Code compacts. The long history is replaced with a structured summary and work continues from there. You can also do it yourself with /compact.
The trade is simple. You get room back, and you lose exact detail. A summary remembers that a decision was made. It may not remember the exact error message or the third line of a diff.
What matters is that compaction is not a blank slate. Several things are put back by rule, and several are not.
What is restored
After compaction, Claude Code does these things:
- It re-reads up to five recently touched files. A file over 5,000 tokens comes back only as a path reference, so Claude knows it exists but must read it again.
- It re-injects the bodies of skills you invoked, capped at 5,000 tokens each and 25,000 in total. The oldest are dropped first, and truncation keeps the top of the file.
- It reruns SessionStart hooks whose matcher is
compact, and adds their output to the compacted context. - It keeps background commands and background subagents running, and reminds Claude they exist.
And the root CLAUDE.md is still there, because it belongs to the project context rather than the history. Text that arrived through the conversation, such as path-scoped rules, is what the summary may absorb.
A 9,000-token file was open before compaction. What does Claude have of it afterwards?
Steering it
You do not have to accept a generic summary. Two levers decide what it keeps.
$ /compact keep the failing test names and the decision to avoid the new cache✻ Summarizes now, with that focus# Run it at a natural break, not mid-task.
First, a focus after /compact. The guide recommends compacting at natural breaks with a focus, rather than letting auto-compaction fire in the middle of something.
Second, a section in CLAUDE.md headed "Compact instructions". Whatever you write there tells compaction what must survive, for every compaction, without typing it each time.
/clear, /compact, or rewind
These look similar and are not.
/clear is for a new, unrelated task. It costs nothing and removes the old history. If you give it a name, /clear name, the old one is labelled for /resume. Right after /clear, the rewind menu even offers a /resume <session-id> (previous session) entry until you exit.
/compact is for the same task that has simply grown.
Rewind is different in kind. Every prompt that starts a turn captures file state first, and /rewind (also /checkpoint, /undo, or Esc Esc on an empty prompt) opens a menu: restore code and conversation, conversation only, code only, summarize from here, or summarize up to here. The summarize options take guidance in the "add context" row.
Rewind has limits
It restores what the edit tools changed. Three things fall outside it:
- Changes made only through Bash are not tracked, unless Claude already edited that same file with its edit tools in the session.
- Subagent edits are generally not restored. Use git for those.
- Symlinked and hard-linked paths are skipped on code restore, with a warning.
Checkpoints cover the 100 most recent and are swept about 30 days after last save. cleanupPeriodDays extends that.
You tried an approach for twenty minutes and want to abandon it without losing the work before it. Which tool fits best?
Chapter complete
You've finished chapter 4 of 6 in Context and memory.
Claude Code is fast and affordable in long sessions because the unchanged start of each request is cached. A few ordinary actions break that cache, and knowing them is most of cost control.
Next chapter