Claude Code /compact — What Do You Keep When Context Shrinks?
In a long Claude Code session, when the window fills up, /compact replaces conversation history with a structured summary so you can keep going. Automatic compaction uses the same axis. If you trust the summary alone, Goal · decisions · Next blur. Safer practice: freeze a minimum state before compact—outside the chat, or in the compact instructions.
This post covers only minimum info before compact · restart prompts · what to keep in files. Grounding: Commands (/compact, /context, /clear) and Explore the context window (What survives compaction). No plan prices, invented quotas, or affiliates. No C++ samples.
What minimum info do you keep before compact?
One-line answer: Freeze Goal · Done · a single Next · Decisions · one-line repro · key paths that live only in chat right before compact. Mechanisms: /compact instructions and on-disk CLAUDE.md · memory · plan · checkpoint files.
/compact [instructions] summarizes the conversation; optional arguments steer the summary. Docs example: /compact focus on the auth bug fix. Your stated axes beat whatever the automatic pass guesses is important.
Pre-compact checklist:
| Item | Chat-only risk | Before compact |
|---|---|---|
| Goal | Diluted in the summary | One line in /compact instructions or a file |
| Done / Do-not-redo | Mixed with long debug trails | Spell verified and abandoned approaches |
| Next (one) | Multiple candidates blur | Keep exactly one next step |
| Decisions | Design rationale lost | One or two lines: choice + rejected alternative |
| Repro | Failure logs truncated | Command + symptom + path |
| Key paths | Only some reads reload | Name the files you will open next |
Practical order:
- Run
/contextto see what fills the window (categories and optimization hints). When over the window, the UI/docs may warn and point at space-freeing commands. - Unrelated work →
/clear. Same task →/compact./clearstarts empty;/compactcontinues the same conversation via a summary (Commands docs). - Pass focus instructions before compact. Example:
/compact Keep: Goal=<…>; Done=<…>; Next=<one step>; Decisions=<…>;
Repro=<cmd + symptom>; Key paths=<…>. Drop: stale debug tangents, abandoned approaches.
- Whatever already lives on disk is re-injected (next section). Move chat-only contracts into instructions or files.
- Delegate large reads to a subagent so bulky contents stay out of your window (docs). That slows fill rate; it is not a substitute for compact.
Automatic compaction follows the same summary path as /compact. Before a long new task, a focused manual /compact is more predictable than “whatever auto thought mattered.” /autocompact can adjust when auto-compact fires; this post does not invent thresholds or plan numbers—use current UI/docs values.
What restart prompt do you use?
One-line answer: Right after compact, do not “start from scratch.” Stay on summary + re-injected disk state and run one Next step. After /clear, read the checkpoint / CLAUDE.md path first.
Continue in the same session after compact:
After compact: treat the summary as lossy. Re-state Goal and the single Next.
Do not re-explore Done/Do-not-redo. Open only the Key paths listed.
First action: <one concrete Next step>. Report blockers in one line.
True restart after /clear or a new conversation:
Read `PATH/TO/CHECKPOINT.md` (and project CLAUDE.md) first.
Do not reconstruct the old chat. Goal / Done / Next / Blocked only.
Execute exactly one Next step. Do not expand scope.
Compare (per docs):
| Situation | Command | Prompt focus |
|---|---|---|
| Same task, free space | /compact [instructions] | Verify summary → one Next |
| Unrelated work | /clear | Checkpoint / CLAUDE.md first |
| Shrink only part of history | /rewind → Summarize … | Summarize from/up to a message |
| Inspect fill | /context | Decide what to shed |
Do not: “just continue somehow,” launch a huge new exploration right after compact, or re-run experiments already in Done. Summaries are lossy. Re-state Goal / Next / paths once.
What belongs in files?
One-line answer: Separate what reloads from disk after compact from what survives only inside the summary. Put durable contracts, plans, and memory in files; leave one-off noise in chat.
From What survives compaction (product behavior; see official docs for version notes):
| Mechanism | After compaction |
|---|---|
| System prompt and output style | Still apply |
Project-root CLAUDE.md, unscoped rules | Re-injected from disk |
| Auto memory | Re-injected from disk |
| Plan written in plan mode | Re-injected from disk |
Rules with paths: | Reload when matching files are read again |
Nested CLAUDE.md in subdirs | Reload when files in that subdir are read |
| Files Claude read or edited | Re-reads up to five, most recently modified first; oversized files may return as path references only |
| Invoked skill bodies | Re-injected (per-skill and total caps; oldest dropped first) |
| Background commands / subagents | Keep running; Claude is reminded not to duplicate them |
| Context hooks added earlier | Summarized with the conversation |
SessionStart hooks matching compact | Run; output added to compacted context |
File vs chat:
| Put it here | What | Why |
|---|---|---|
Root CLAUDE.md / unscoped rules | Team invariants, deny paths | Re-injected after compact |
| Plan file (plan mode) | Agreed implementation plan | Re-injected |
Auto memory / /memory | Recurring prefs | Re-injected; edit via /memory |
| Checkpoint md (agreed repo path) | Goal · Done · Next · Blocked · paths | Do not trust chat summary alone |
Chat + /compact instructions | This turn’s focus | Instructions steer summary quality |
| Chat only | Long failed log dumps | Collapse to one-line repro in file/instructions |
One-line rules:
- Need it after the next compact/session? → Put it in a file.
- Path-scoped rules / nested CLAUDE.md alone may be empty until their trigger files are read again. If it must always apply, promote to root / unscoped (docs).
- Post-compact auto re-reads are capped. Name the next files in the checkpoint or instructions.
- Skills re-inject but truncate under caps—put critical instructions near the top of
SKILL.md(docs).
Bottom line: Claude Code compact = focused /compact · one Next afterward · disk reloads CLAUDE.md / memory / plan · chat-only contracts move to files or instructions. Do not confuse it with /clear.
FAQ
/compact vs /clear?
/compact continues the same conversation via a summary. /clear (aliases /reset, /new) starts an empty conversation. Switch tasks with /clear; free space on the same task with /compact.
Is automatic compact enough?
Auto uses the same summary axis. Before a long new task, /compact with instructions locks focus better. Observe/adjust timing with /context and /autocompact (when your build supports it)—do not invent quota numbers.
Files look “unread” after compact?
At most five recently modified files auto re-read; large ones may be path references only. Ask Claude to open needed paths again, or list them in the checkpoint.
Why did a path-scoped rule disappear?
It entered history when the trigger file was read, then was summarized away with the rest. If it must survive compact, drop paths: or move it into root CLAUDE.md (docs).
Sources
- Commands —
/compact [instructions],/context,/clear,/autocompact,/rewind,/memory - Explore the context window — What survives compaction, When your context fills up
- Using Claude Code: session management and 1M context —
/compactvs/clearpractice (no pricing figures)