3. Keeping a session healthy
"Context is the resource you manage, and a handful of moves cover almost everything. /clear starts a new, empty conversation and costs nothing, so I use it between unrelated tasks. /compact replaces the history with a summary so I can keep going on the same task, and I give it a focus. /btw asks a side question that never enters the history. /rewind can summarize just one stretch. Claude Code also compacts on its own near the limit, and when you leave a big conversation idle. The rule for what survives: anything loaded from disk comes back, anything said only in chat becomes a summary. So rules that must last go in CLAUDE.md."
8 pictures, in order.
Use the arrow keys or the dots. Tap a picture to see it full size.
The facts someone can check.
The moves, side by side
| Command | What happens to the history | Use it when |
|---|---|---|
/compact [instructions] |
Replaced by a summary; the session continues | Same task, long history, a natural break |
/clear [name] (aliases /reset, /new) |
A new, empty conversation; the old one is saved | Unrelated work, or after two failed corrections |
/rewind, then Summarize |
One stretch compressed, the rest kept word for word | A verbose middle you want to shrink |
/btw [question] |
Untouched: the answer never enters the history | A quick question about what Claude already knows |
/recap |
Untouched: a one-line summary, up to 400 characters | Coming back after a break |
/autocompact [auto|<tokens>] |
Nothing now; sets when auto-compaction runs | Compacting earlier than the default |
/btw has no tools: it answers only from what's already in context. Press f in its overlay to fork the question into a subagent that does have tools. Claude Code also shows a recap on its own when you return after three or more minutes away, once the session has at least three turns.
What survives compaction
- Back in full: system prompt and output style, project-root CLAUDE.md and unscoped rules (re-read from disk), auto memory, skill descriptions, a fresh git status, and the plan from plan mode.
- Back partly: up to 5 recently edited or read files (a file over 5,000 tokens returns as a path only), and invoked skill bodies capped at 5,000 tokens each and 25,000 in total, oldest dropped first.
- Back later: path-scoped rules and subfolder CLAUDE.md files, the next time Claude touches a matching file.
- Folded into the summary: the conversation itself. Your requests and key code stay, but detailed instructions from early on may not.
- Still running: background commands and background subagents.
Two levers: a # Compact instructions section in CLAUDE.md tells every compaction what to keep, and a SessionStart hook that matches the compact source runs again afterwards and can put context back.
When automatic compaction runs
On by default (autoCompactEnabled: true). On Opus 4.7 and later, Sonnet 5 and later, Haiku 5.5 and the Fable models, it triggers at about 967K tokens. Opus 4.6 and Sonnet 4.6 without the [1m] variant, and any model with CLAUDE_CODE_DISABLE_1M_CONTEXT=1, compact at the 200K boundary.
To compact earlier, set the auto-compact window, anywhere from 100K to 1M tokens. Strongest first:
CLAUDE_CODE_AUTO_COMPACT_WINDOW, for scripts and cloud environments.claude --autocompact 500k, for one launch./autocompact 500k, saved per model in your user settings (v2.1.221 or later)./autocompact autoreturns to the tuned window."autoCompactWindow": 200000in a settings file, for every model.
A bare 200 means 200,000 in /autocompact, but 200 tokens in the environment variable. Whatever you set is capped at the model's real window.
Idle compaction
Leave a big conversation for about 54 minutes and Claude Code may compact it while the one-hour prompt cache is still warm, so your next message sends a summary instead of reprocessing the whole conversation cold. It needs all of: an interactive terminal session, auto-compact on, the one-hour cache, feature flags reachable, and at least 200,000 tokens of context. Turn it off with "idleCompaction": false (v2.1.290 or later) or the row in /config.
Which move, when
The rule from the best-practices guide: if you've corrected Claude more than twice on the same issue, the context is full of failed approaches. /clear and start again with a better prompt.
What each move costs
/compact sends a separate request that rereads the conversation. While the cache is warm that costs a fraction of its size. After the cache expires it's the most expensive move you can make, which is why compacting a resumed old session hurts. /clear costs nothing. /rewind truncates back to a prefix that's already cached, so abandoning a dead end is cheaper by rewinding than by compacting. The main conversation's cache lasts 1 hour on a Claude plan within its included usage, and 5 minutes with an API key, usage credits, or a cloud provider.
The switches, and the one error
autoCompactEnabled: falseorDISABLE_AUTO_COMPACT=1: no automatic or idle compaction, but/compactstill works.DISABLE_COMPACT=1: no compaction at all, including/compact.CLAUDE_AUTOCOMPACT_PCT_OVERRIDE: compact at a lower percentage of the window. It can't raise the trigger.autoCompactWindowin a subagent's frontmatter: that subagent compacts earlier.- "Autocompact is thrashing" means one file or output keeps refilling the window right after each summary, so Claude Code stopped retrying. Read the file in pieces,
/compactwith a focus that drops it, move the work to a subagent, or/clear.
Answer out loud, then flip the card.
Mark each one honestly. Cards you miss stay flagged for review, in this browser.
A customer says "after a few hours, Claude forgot our rule about migrations." Why, and what's the fix?
The session compacted, and the rule only existed in the conversation, or in a path-scoped rule. Compaction keeps your requests and key code but can lose detailed instructions from early on, and path rules are summarized away until the next matching file. Put rules that must last in the project-root CLAUDE.md, which is re-read from disk after every compaction, or drop the paths: frontmatter from the rule. A # Compact instructions section in CLAUDE.md tells every compaction what to keep.
When do you use /compact and when /clear?
/compact when you're continuing the same task and need the thread: it summarizes and keeps going, ideally at a natural break with a focus, such as /compact focus on the API changes. /clear when you're switching to unrelated work, or after correcting Claude twice on the same thing: it starts an empty conversation, costs nothing, and the old one is still there through /resume.
Developers say their first message after lunch is slow and burns a lot of usage. Why?
The prompt cache expired. The main conversation's cache lasts an hour on a Claude plan and five minutes with an API key or a cloud provider, and the first request after that reprocesses the whole conversation uncached. Idle compaction exists for this case: on a conversation over 200,000 tokens it compacts at about 54 minutes, while the cache is still warm. Habits that help: /clear before a break when the next task is different, and /compact at a natural break rather than on a cold session.
Their LLM gateway rejects requests over 200K tokens, and sessions on a 1M model start failing. What do you set?
CLAUDE_CODE_AUTO_COMPACT_WINDOW=200000 in the environment that starts Claude Code. Claude Code can't detect a lower limit enforced by a gateway, so you tell it to compact at the boundary the gateway allows. The variable beats the /autocompact command, the flag, and the setting.
A developer turned off auto-compact and now sees "Context limit reached." What do you tell them?
Run /compact to summarize earlier turns, or /clear to start fresh. With auto-compact off, /compact is their job. To turn it back on, use the Auto-compact toggle in /config, unless DISABLE_AUTO_COMPACT is set in their environment, which wins. If DISABLE_COMPACT is set, even /compact is off, and /clear is the only way out.
You see "Autocompact is thrashing." What happened, and what do you do?
Compaction worked, but one file or tool output refilled the window several times in a row, so Claude Code stopped retrying. Read the file in smaller chunks, /compact with a focus that drops the large output, move the work to a subagent, or /clear. If it comes back after /clear, run /context: if Messages is the biggest row, it's still a file; if the other rows together are bigger, what loads at startup is too large.
How do you ask a quick question without growing the context?
/btw. It answers from what's already in the conversation, the question and answer never enter the history, and it works while Claude is busy. It has no tools, so for anything that needs reading files, use a subagent instead, or press f to fork the side question into one.
Someone ran /clear by mistake. Is the conversation gone?
No. /clear saves the previous conversation. /resume brings it back, and in the same Claude Code process the rewind menu shows a "previous session" entry at the top. Tip: /clear release-prep labels the conversation you're leaving so it's easy to find in the /resume picker.
Wrong answers that sound right.
Before you tap, say why each one is wrong.
Three moves in a fresh project.
Facts checked against code.claude.com/docs/en/context-window, commands, interactive-mode, checkpointing, model-config, settings-reference, env-vars, prompt-caching, costs, best-practices, sessions, sub-agents, hooks, errors and troubleshooting on 2026-10-25. Claude Code ships fast: confirm anything that matters against the official docs.