Claude Code context guide

Claude Code /compact vs /clear and what survives compaction

Use /compact to continue the same conversation from a summary when context runs low. Use /clear to start an empty conversation at no cost when you switch tasks. Both commands reload project memory from the root CLAUDE.md. To go back to an earlier turn, use /rewind.

Last updated · Published

By CWYN · Published · Checked against docs, not run · Command reference, costs, project memory and prompt caching (as of )

1. Choose the command for your next step

Your next stepCommandWhere you pick up
Keep debugging the same failure/compact [instructions]Continue from a summary. The optional instructions tell Claude what to keep, such as the failing test and the fixes you ruled out.
Start an unrelated task/clear [name]Begin a new conversation. The old one is available through /resume. The aliases for /clear are /reset and /new.
Try a different approach/rewindChoose the turn before the detour. Later messages drop out of context, leaving the earlier cached part of the conversation. See which file edits a checkpoint can restore.

For shortcuts to inspect context or reopen a conversation, see the commands for managing a session.

If you need to keep both tasks open and edit files in parallel, give each Claude Code session its own worktree.

Command arguments and aliases and rewinding to a cached turn (as of ).

2. Check what is filling the context window

Run /context at the Claude Code prompt. The colored grid shows what is using space and suggests ways to free it. If the conversation is already over the context limit, the readout shows how far over you are and which command frees space. Command reference for /context and context windows by model (as of ).

If CPU or memory use is high during a long conversation, run /compact regularly to reduce the context size. Troubleshooting resource use (as of ).

3. What survives compaction?

Part of the sessionAfter compaction
System prompt and output styleBoth still apply.
Project instructionsClaude Code rereads the project-root CLAUDE.md and unscoped rules from disk. Nested CLAUDE.md files reload when Claude reads a file in their directory. Rules with paths: reload when a file matches.
Auto memory and planClaude Code restores auto memory and the plan from plan mode.
Recent filesClaude Code rereads up to five recently modified files that it read or edited. A file over 5,000 tokens comes back as a path reference.
SkillsClaude Code rebuilds skill descriptions in v2.1.304 or later. It restores the bodies of invoked skills, up to 5,000 tokens per skill and 25,000 tokens total.
Background workBackground commands and subagents keep running.
HooksContext supplied by hooks goes into the summary. SessionStart hooks that match the compact source run again.

Claude Code’s table of what survives compaction (as of ).

4. When does compacting a conversation cost more?

Compaction sends a separate request to read the conversation and write the summary. During an active session, that request can read the earlier messages from a warm prompt cache for a fraction of the cost of processing them again. Once the summary replaces those messages, the conversation cache is invalidated. Compaction costs and how the summary uses the cache (as of ).

If you resume a long session after the cache has expired, the summary request has to process the history uncached. That is when /compact costs the most. For a fresh start, /clear costs nothing and resets the session totals shown by /usage. Cache lifetime and when to compact and session usage totals (as of ).

5. How to stop automatic compaction while idle

In v2.1.290 or later, set idleCompaction to false to stop Claude Code from compacting a long conversation while it is idle. This setting applies to idle compaction with the one-hour cache lifetime. During an active task, you can run /compact at a natural break while the cache is warm and tell Claude which decisions to keep. Idle compaction setting (as of ).

6. Fix compaction messages

“Not enough messages to compact.”

There are too few turns to summarize. A single large paste can fill the window even in a short conversation. If the paste is all you need, save the relevant excerpt, run /clear and bring just that excerpt into the new conversation. Compaction troubleshooting and starting a new conversation (as of ).

“Autocompact is thrashing”

A file or tool output has repeatedly filled the window again after compaction. Read the file in smaller chunks. To drop the large output while keeping the work in progress, try /compact keep only the plan and the diff. You can also move the large-file work to a subagent, or use /clear if the earlier conversation is no longer needed. Fixing repeated auto-compaction (as of ).

7. Keep project instructions across compaction

If you told Claude which test command to run and where to run it, write both in the project-root CLAUDE.md. Claude Code rereads that file after compaction. A rule given only in conversation can drop out of the summary. How Claude Code reloads project instructions (as of ).

8. Claude Code compaction FAQ

Does /clear delete CLAUDE.md?

No. It clears the conversation history from the active context. Your project-root CLAUDE.md stays on disk and its instructions load in the new conversation. The /clear command and project memory (as of ).

Can I get a cleared conversation back?

Yes. Run /resume and choose the previous conversation. See how to resume a local Claude Code session for the steps. Resuming after /clear (as of ).

Why did Claude forget an instruction after compacting?

Check where the instruction lives. A chat-only rule may have been left out of the summary. For a nested CLAUDE.md, ask Claude to read a file in that directory. For a path-scoped rule, have it read a matching file. Put instructions that apply throughout the project in the root CLAUDE.md. Diagnosing missing instructions (as of ).

Does compacting count toward my usage?

Yes. The summary is a request that reads the conversation. A warm cache lowers its cost. If you use an API key, see how API usage is billed. On a subscription, use the Claude Code usage limits guide to check your shared allowance. Claude Code costs and cached summary requests (as of ).

Next steps

Write instructions for your project

Open the free AI instruction builder

Set up your Claude Code project

Put your test command in the starter CLAUDE.md from the Claude Code Complete Setup Pack ($12.95) and save it at the project root so Claude can reload it after compaction.