# 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.

**Question:** A 9,000-token file was open before compaction. What does Claude have of it afterwards?

- The full file, re-read automatically
- A path reference only, because it is over 5,000 tokens
- Nothing at all
- A one-line summary of its contents

**Answer:** A path reference only, because it is over 5,000 tokens. Recently touched files are re-read, but anything over 5,000 tokens comes back as a path reference. Claude must read it again if it needs the contents.


## Steering it

You do not have to accept a generic summary. Two levers decide what it keeps.

```terminal
$ /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.

> **Write what you cannot rediscover**
Good compact instructions name things the code cannot give back: which approach you rejected and why, the open question, the next step. Things Claude can re-read from the repo do not need protecting.


## /clear, /compact, or rewind

These look similar and are not.

```flow
/clear: empty window, old session kept for /resume
/compact: history becomes a summary, work continues
/rewind: go back to an earlier point, code and conversation
```

`/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.

> **Rewind is not git**
It is a safety net for the last few steps, not a history of your project. Commit what matters.


**Question:** You tried an approach for twenty minutes and want to abandon it without losing the work before it. Which tool fits best?

- /clear
- /rewind to the point before the attempt
- /compact
- Starting a new terminal

**Answer:** /rewind to the point before the attempt. Rewind returns code and conversation to an earlier checkpoint. /clear would throw away the good work too, and /compact would keep the failed attempt in a summary.


> **Compact on purpose**
At the end of a real piece of work, run `/compact` with a focus sentence. Then ask Claude what it remembers of the decision you cared about. If it is missing, add that kind of fact to your "Compact instructions".
