الانتقال إلى المحتوى
Claude وأدوات الـ AI للبرمجةإدارة الـ Context· 6 دقائق للقراءة

/compact Isn't a Save Point: When to Compact, Clear or Rewind in Claude Code

Compaction swaps your history for a summary. Clear between tasks, compact within one, and rewind a wrong turn.

ReadIn

مقال كل يوم يفرق معاك

21 نوفمبر 2026
  • كاتب موثّق
  • Claude Code 2.x
محتويات المقال

A developer keeps one Claude Code session open all week. Monday it fixes a token refresh bug, Tuesday it builds a CSV export, Wednesday it chases a flaky test. Auto-compaction has run twice, and they've typed /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.

The half-truth: compaction does preserve a lot, and some things reload from disk afterward. But it's a summary, not a save point. It loses detail by design, and it doesn't separate Monday's task from Wednesday's.

What actually happens

What survives a compaction

replaces the conversation history with a structured summary. Then Claude Code rebuilds part of the context:

  • 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.

The conversation itself, including every instruction you gave in chat, now exists only as the summary's version of it. The docs warn that detailed instructions from early in the conversation may be lost.

Unrelated history isn't free

The model remembers nothing between requests, so Claude Code re-sends the full context on every turn. With prompt caching, that history is re-read at the cached rate, but the costs page is blunt: "a one-line question in a session that has been open all day still draws usage for the whole conversation." The context-window guide adds that old conversation crowds out the files you need next.

/compact is itself a big request

To write the summary, Claude Code sends a request that reads the history being summarized. While the is warm, that prefix comes from the cache and the request costs a fraction of its size. After a break longer than the cache lifetime, the same history is reprocessed as uncached input. /clear, by contrast, costs nothing.

/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

text Claude Code 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?

In the first session, every new task inherits summaries of the old ones. In the second, /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
ConversationA new one, with empty contextReplaced by a summaryCut back to a prompt you pick, or partly summarized
What carries overCLAUDE.md and auto memoryThose, plus the summary, the plan and up to 5 filesEverything before that prompt
Files on diskUntouchedUntouchedCan be restored to that checkpoint
CostNothingReads the whole conversationReuses the cached prefix
Use it whenYou switch to unrelated workOne task has a long historyA wrong turn you want to undo

How to apply it in your project

  1. Give each task its own conversationRun /clear when you switch to unrelated work, and pass a name so you can come back with /resume.
  2. Compact at a break, with a focusWithin a long task, run /compact between steps, such as after a module passes its tests, and say what to keep.
  3. Rewind a wrong turnIf an approach failed, /rewind to the prompt before it instead of piling corrections on top. After two failed corrections, the docs recommend /clear and one better prompt that folds in what you learned.
  4. Move lasting rules out of chatAnything Claude must remember after a compaction belongs in CLAUDE.md, not in a message.
  5. Check before you guessRun /context to see what fills the window, and /usage to see whether long context or cache misses drive your usage. Ask quick side questions with /btw, which adds nothing to the history.

Key takeaways

  • /compact swaps 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.
  • /clear between tasks costs nothing; /compact reads the whole history; /rewind reuses the cache.
  • Clear to switch, compact with a focus to continue, rewind to undo a wrong turn.

📚 المصادر

  1. Explore the context window — Claude Code Docs
  2. How Claude Code uses prompt caching — Claude Code Docs
  3. Commands — Claude Code Docs
  4. Manage costs effectively — Claude Code Docs
  5. Checkpointing — Claude Code Docs

التعليقات (0)