
/compact Isn't a Save Point: When to Compact, Clear or Rewind in Claude Code
- كاتب موثّق
- Claude Code 2.x
محتويات المقال
/compact a few more times "to keep it fresh". On Wednesday afternoon, Claude calls the legacy HTTP client that, back on Monday, they'd told it never to use. That instruction lived only in the conversation, and the conversation is now a summary of a summary.
The common misconception
/compact keeps everything that matters, so one long session across unrelated tasks is as good as starting fresh." It's easy to see why people think so:
Compaction is automatic. Claude Code compacts as you approach the limit, so a full context window never ends the session, and it feels lossless. The summary is good. The docs say it keeps your requests and key code snippets. Context windows are large. With a 1M-token window on most current models, the docs themselves say running out is rare. Starting over feels like throwing away what Claude "learned" about the code.
What actually happens
What survives a compaction
The system prompt and output style still apply. The project-root CLAUDE.md, unscoped rules and auto memory are re-injected from disk. A plan written in plan mode is re-injected from disk. Up to five files Claude read or edited are re-read, most recently modified first; a file over 5,000 tokens comes back as a path reference without its content. Path-scoped rules and nested CLAUDE.md files reload only when Claude touches a matching file again.
Unrelated history isn't free
/compact is itself a big request
/compact is itself a big request/clear, by contrast, costs nothing.
/rewind reuses what's already cached
/rewind reuses what's already cached/rewind, or Esc twice on an empty prompt, lists the prompts you sent. Pick one to restore the conversation, the code or both to that point, or to summarize the messages after it or before it. A rewind truncates the conversation back to a prefix that's already cached, while compaction has to build a new one. To abandon a path, rewind instead of compacting over it.
One session vs one task per session
> fix the token refresh bug in src/auth/ (fixed and committed)/compact> add CSV export to the reports page/compact> why is checkout.test.ts flaky?> fix the token refresh bug in src/auth/ (fixed and committed)/clear token-refresh> add CSV export to the reports page, following the PDF export/compact keep the export format decisions and the test commands> now add the date range filter to the CSV export/clear token-refresh starts an empty conversation and labels the finished one in the /resume picker. The second /compact happens at a break inside one task, with a focus, so the summary keeps what you choose rather than what the automatic pass guesses is important.
/clear | /compact [focus] | /rewind | |
|---|---|---|---|
How to apply it in your project
Give each task its own conversation Run /clearwhen you switch to unrelated work, and pass a name so you can come back with/resume.Compact at a break, with a focus Within a long task, run /compactbetween steps, such as after a module passes its tests, and say what to keep.Rewind a wrong turn If an approach failed, /rewindto the prompt before it instead of piling corrections on top. After two failed corrections, the docs recommend/clearand one better prompt that folds in what you learned.Move lasting rules out of chat Anything Claude must remember after a compaction belongs in CLAUDE.md, not in a message. Check before you guess Run /contextto see what fills the window, and/usageto see whether long context or cache misses drive your usage. Ask quick side questions with/btw, which adds nothing to the history.
Key takeaways
/compactswaps the conversation for a summary; detail and chat-only instructions can be lost.CLAUDE.md, auto memory, the plan and a few recent files come back after compaction; your chat doesn't. Every request re-sends the whole conversation, so an unrelated old task costs you on every turn. /clearbetween tasks costs nothing;/compactreads the whole history;/rewindreuses the cache.Clear to switch, compact with a focus to continue, rewind to undo a wrong turn.
التعليقات (0)