Claude Code: When to Use /compact and When to Start a New Session
A practical guide to managing context in Claude Code. It explains /compact in plain language, compares it with /clear, /rewind, and a separate new session, clarifies how Claude Web handles long chats, and includes a post-compaction verification prompt, a safe handoff template, and a one-minute decision flow.
Contents
In Claude Code, /compact summarizes older parts of the conversation into a shorter, structured representation. That frees room in the active context window while trying to preserve the task goal, important decisions, and the current state of the work. It is most useful when the task is still the same and the approach is basically sound, but logs, tool output, diffs, and intermediate discussion have made the session noisy.
However, /compact is not a reset button for a confused session. The active context after compaction no longer contains every earlier detail word for word. Exact error messages, rejected approaches, temporary constraints, or instructions mentioned only in chat may become less prominent. If Claude is mixing tasks, repeating a failed solution, or working from the wrong architectural assumption, a clean session with a concise handoff is usually safer than another compaction.
What does /compact do in Claude Code and Claude Web?
In Claude Code, /compact summarizes earlier multi-turn conversation and frees context space without changing your project files. Claude Code can also compact automatically as the context approaches its limit, and you can run the command manually before the session becomes slow or overloaded.
Regular Claude Web chats do not expose a /compact slash command. When code execution is enabled and a long conversation nears its context limit, Claude can automatically summarize older messages and continue. You may occasionally see a status such as Claude “organizing its thoughts.” The full chat history remains available, but the model’s active working context uses a summary rather than resending the entire transcript verbatim.
| Question | Claude Code | Claude Web |
|---|---|---|
| How is compaction triggered? | Manually with /compact, or automatically | Automatic context management near the limit |
| Can the user run the same command? | Yes | No equivalent chat command |
| Does the conversation continue? | Yes, in the same session | Yes, in the same chat |
| Main purpose | Free context for the same development task | Keep long chats going with fewer length interruptions |
| Main risk | Fine-grained errors and chat-only constraints may be weakened in the summary | Older details may become less prominent in the active context |
/compact vs /clear vs /rewind vs a new session
| Choice | What it changes | Best used when | Avoid it when |
|---|---|---|---|
| Continue | Nothing is reset or summarized | Claude still remembers the symptom, constraints, and latest evidence | The session is looping, mixing tasks, or reviving rejected ideas |
/compact | Summarizes older turns and frees context while keeping the session | The task is unchanged and the direction is correct, but logs and tool output are taking over | The core understanding is wrong or exact historical detail is essential |
/clear | Starts a blank conversation in the current Claude Code process; the prior session can still be resumed | You want a fresh chat while keeping the same working directory and files | You need to undo code changes; /clear does not restore files |
/rewind | Opens checkpoints for restoring code, restoring conversation, or summarizing a selected range | The most recent turns went off track and you can identify a good checkpoint | Changes came from Bash, external tools, manual edits, or most subagents |
| Separate new session | Starts clean in another terminal, window, or isolated workspace | You are switching tasks, rethinking the architecture, or doing parallel work | The only problem is excessive logs in an otherwise accurate session |
/clear already starts a new blank conversation. The separate “new session” option in this guide means a more deliberate boundary: a new terminal or window, optionally a separate branch or worktree, plus an explicit handoff containing only verified facts.
First decide whether the problem is context or diagnosis
Suppose you are fixing CSV import behavior. An empty amount should return a validation error and must not write data. Claude has edited the handler twice, reopened the same files, and is now suggesting the first implementation again.
Do not compact or restart immediately. Run the narrowest test first:
npm test -- tests/import/empty-amount.test.ts
Then interpret the result:
- The test does not exist or checks the wrong behavior: the first problem is an unclear specification or missing reproduction. A new session will not create evidence.
- The test reliably reproduces the right symptom and Claude still uses that result correctly: continue the current session.
- The test fails consistently, but Claude forgets excluded causes, expands the scope, or repeats old ideas: context degradation is now a plausible cause.
There is no official token count or message count that determines the right moment to compact. Treat 60%–80% context usage as an early warning to inspect the session, not as a hard rule. The stronger signal is behavior: can Claude still state the goal, constraints, verified facts, and next validation command accurately?
When should you run /compact?
Prefer /compact when all of these are true:
- You are still working on the same task and repository.
- Claude understands the goal and the allowed files correctly.
- The current direction is supported by tests or logs, not just a guess.
- Most context is being consumed by long logs, build output, repeated diffs, or intermediate discussion.
- You can state the facts that must survive in a few sentences.
Before compacting, inspect the working tree:
git status --short
git diff
Then run /context to see whether the window is being consumed by messages, tools, MCP definitions, or CLAUDE.md. If the real problem is one huge first prompt, large attachments, tool definitions, or an oversized memory file, there may be too little earlier conversation for /compact to summarize.
A project-root CLAUDE.md is reloaded after /compact. Instructions that existed only in the chat are less durable. Put long-lived project rules in a concise CLAUDE.md, and restate task-specific facts around the compaction point.
Verify the context immediately after compaction
Do not let Claude edit files immediately after /compact. First send a short verification prompt:
We just compacted the context. Before changing any file, answer four questions:
1. What exact symptom are we fixing, and what is the expected result?
2. Which approach has already been tested and rejected, and why?
3. Which files may be changed, and what must not change?
4. What single command will we run next to test the hypothesis?
If any answer cannot be determined from the current context, say what is missing instead of guessing.
For the example task, Claude should be able to state at least the following:
- An empty
amountmust produce a validation error and no data write. Number(value || 0)was rejected because it converts an empty value into a valid zero.- The scope is limited to the parser and its focused test.
- The next step is one narrow test or tracing command, not a refactor of the import system.
If the answers are accurate, continue in the same session. If they are vague, revive the rejected solution, or expand the scope to README files or the public CSV format, do not trust the summary. Prepare a handoff and use /clear or start a separate session.
When /compact is the wrong tool
1. The task has changed
You began with a validation bug, then added a README update, a deployment change, and a second API issue. Compaction will summarize all of them together; it will not create clean task boundaries. Move the second task to a new session.
2. Claude’s core assumption is already wrong
If Claude repeatedly treats an empty value as zero or misunderstands the data-write path, the problem is not merely a long transcript. A new session grounded in verified facts is usually faster.
3. Exact details must survive verbatim
Some error lines, SQL, stack locations, protocol fields, or security constraints cannot safely be left to a summary. Put the minimum required details in a handoff note or local file.
4. A single input is too large
If the first prompt already contains a huge log, attachments, or many tool definitions, there may be no earlier multi-turn conversation to compact. Reduce the input, reference files by path, or disable MCP servers you do not need.
5. The session is already too full to create a summary
/compact itself can fail when there is not enough free context to produce the summary. Double-press Esc, step back several turns, and try again. If that still fails, use /clear; the previous session remains available through /resume.
When is /rewind better than /compact?
Use /rewind, or press Esc twice while the prompt is empty, when the problem is concentrated in a recent section of the session. The checkpoint menu can:
- restore both code and conversation;
- restore the conversation while keeping current files;
- restore code while keeping the conversation;
- summarize from a selected point forward;
- summarize everything before a selected point.
This is useful when the last three turns went in the wrong direction but the earlier context remains valid.
Checkpointing mainly tracks changes made through Claude’s file-editing tools. File changes made by Bash commands, external programs, manual edits, or most subagents may not be restored. Checkpoints are also not a replacement for Git; use branches, commits, or at minimum inspect git diff at important points.
How to hand the task to a new session safely
A new session does not need the full transcript. It needs verified facts, current file state, and one next step.
First inspect:
git status --short
git diff
Then send a concise handoff:
Goal: an empty amount returns a validation error and does not write data.
Working tree: inspect git status and git diff first; do not assume it is clean.
Target files: parser/amount.ts, tests/import/empty-amount.test.ts
Reproduction: npm test -- tests/import/empty-amount.test.ts
Current result: the test fails.
Rejected approach: Number(value || 0), because it converts an empty value to zero.
Constraints: do not change the public CSV format and do not refactor unrelated modules.
Open question: where should an empty value be distinguished from a legitimate 0?
Next step: trace value from the CSV parser to the validation branch and propose one testable hypothesis.
Before editing, restate the goal, constraints, rejected approach, and next validation command.
Do not include API keys, cookies, .env contents, personal data, or complete raw logs. If an error line matters, include only the minimum fragment and the path to the local log.
The one-minute decision flow
- Reproduce first. Run the smallest test or command that proves the symptom.
- Can the session still proceed accurately? If Claude remembers the goal, constraints, and latest result, continue.
- Is the problem mainly noise? For the same task with a sound direction and excessive logs, use
/compact. - Are only the recent turns wrong? Use
/rewindto restore or summarize a targeted range. - Has the task changed or the model of the problem degraded? Use
/clearor a separate new session with a handoff. - Verify before editing. Make Claude restate the facts before allowing more changes.
Frequently asked questions
What exactly does /compact do in Claude Code?
It summarizes earlier multi-turn conversation into a shorter context representation, freeing space so the same session can continue. The command itself does not modify project files.
Does /compact delete the original chat or code?
It is intended to compress active context, not delete code. The session transcript remains available, but later turns rely mainly on the summary and current active content, so important details should still be checked explicitly.
When should I use /compact instead of a new session?
Use /compact when the task and direction are still correct and the main problem is accumulated logs or intermediate output. Start fresh when tasks are mixed, rejected approaches keep returning, key constraints are lost, or the architectural understanding is wrong.
What is “compact” in Claude Web?
Claude Web can automatically summarize older messages when a long chat nears its context limit. This is not the Claude Code /compact command and normally does not require manual activation. Automatic context management currently depends on code execution being enabled.
What is the difference between /clear and opening a new terminal?
/clear starts a blank conversation inside the current Claude Code process, while the previous session remains resumable through /resume. A new terminal or window is better for deliberate task isolation, parallel work, or use with a separate branch or worktree.