skip to content

Window Budget & Compaction

What fills the context window, how /context shows it, and how auto-compact, a focused /compact and /clear reclaim it. Asked because long sessions degrade before they fail and compaction drops detail.

part ofClaude Coderead it →
on this pageshow

explore

questions

5

In Claude Code, when do you run /clear instead of /compact, and what does each command keep from the session?

level: juniorimportance: must knowfreq 30%

answer

  1. new task or same task
  2. empty history versus a summary
  3. startup content loads either way
  4. focus text after the command

basics

~10 s

/clear starts a new conversation with empty history, so use it between unrelated tasks. /compact keeps the same conversation but replaces its history with a structured summary, freeing room to continue the current task.

solid answer

~50 s

`/clear` (aliases `/reset` and `/new`) starts a new conversation: the old message history leaves the context, while startup content such as the system prompt, your CLAUDE.md files and auto memory loads as usual. Use it when you switch to unrelated work, because stale history crowds out what the next task needs and is resent with every request. The old conversation is saved, and `/resume` brings it back. `/compact` keeps you in the same conversation but replaces the history with a structured summary of your requests, key concepts, files touched, errors and fixes, and pending work. Full tool outputs and intermediate reasoning are dropped. Add focus text, as in `/compact focus on the auth bug fix`, to tell the summary what to keep. The short rule: a new task gets `/clear`, and the same task in a crowded window gets `/compact`.

go deeper

for a junior

Recall the one-line split: /clear gives a new, empty conversation for new work, and /compact summarizes the current one so the same task can continue.

for a middle

Explain what the summary keeps and drops, and that CLAUDE.md and auto memory come back after either command because they load from disk, not from chat history.

for a senior

Show judgment about timing: compact at a natural break with focus text rather than waiting for the automatic pass mid-step, and move must-hold decisions into CLAUDE.md before compacting.

for a principal

Frame it as a team habit: clearing between unrelated tasks and recording durable decisions in CLAUDE.md keeps sessions sharp, and a shared Compact Instructions section makes summaries consistent across developers.

## The problem both commands solve Everything Claude knows during a Claude Code session lives in one **context window**: the system prompt, your CLAUDE.md files, auto memory, the skill and MCP tool listings, every prompt you typed, every file Claude read, every command output and every reply. The window has a fixed size, and a long conversation slowly fills it. Before it is full, quality usually drops: old, irrelevant turns compete for attention with the files the current step needs. Claude Code gives you two commands to take space back, and they make opposite trade-offs. ## What `/clear` does `/clear` starts a **new conversation with empty context**. Its aliases are `/reset` and `/new`. - The previous message history no longer reaches the model. - Startup content loads again as it does for any new conversation: the system prompt, CLAUDE.md files, auto memory, the skill listing and MCP tool names. Project knowledge you wrote down therefore survives. - Nothing from the chat survives unless it was written somewhere Claude Code loads, such as CLAUDE.md, or is still on disk in the repository. - The old conversation is **not deleted**. Pass a name, as in `/clear auth-fix`, to label it, then return to it with `/resume`. Use it when you move to **unrelated work**: the bug is fixed and the next job is a new feature. Carrying the old history forward only adds noise, and the history is resent on every request. ## What `/compact` does `/compact` frees context **while continuing the same conversation**. Claude Code sends the history to the model with a summarization instruction and replaces the verbatim history with a **structured summary**. The summary keeps: 1. your requests and intent; 2. key technical concepts; 3. files examined or modified, with important code snippets; 4. errors and how they were fixed; 5. pending tasks and the current work. What goes is the raw material: **full tool outputs and intermediate reasoning**. Claude can still refer to that work, but no longer has the exact text. Startup content such as the project-root CLAUDE.md and auto memory is re-injected from disk, and the most recently modified files are re-read, so the conversation continues with its project grounding intact. Claude Code also runs this automatically as the window approaches its limit (**auto-compaction**). Running it yourself lets you choose the moment, ideally at a natural break between steps rather than in the middle of one. ## Choosing between them | Question | `/clear` | `/compact` | |---|---|---| | Conversation afterwards | A new, empty one | The same one, history summarized | | Chat history | Leaves the context; can be resumed | Replaced by a summary | | CLAUDE.md and auto memory | Loaded fresh | Re-injected from disk | | Best for | Switching to unrelated work | Continuing a long task in a crowded window | | Steering | Nothing to steer | Optional focus instructions | ## Steering the summary The automatic pass guesses what matters. You can tell it instead: - **Focus text** on the command: `/compact focus on the API changes` keeps what you name. - A **"Compact Instructions" section** in the project CLAUDE.md, such as "focus on test output and code changes", which applies whenever the conversation is compacted, so you do not retype it. Focus text shapes the summary, but it is still a summary. Anything that must hold for the rest of the session, such as "never edit the generated client", belongs in CLAUDE.md, which is re-read from disk, rather than in an early chat message. ## A worked example Suppose you spend the morning fixing a token-refresh bug and the afternoon building an export feature. 1. Midway through the bug fix the window is crowded with test output. Run `/compact focus on the refresh-order fix and the failing test`, and keep going in the same conversation. 2. The fix lands. Run `/clear token-refresh-fix` to start the export work and label the finished conversation in the `/resume` picker; a bare `/clear` works too. 3. The new conversation starts with CLAUDE.md and auto memory loaded, but none of the bug-fix chatter. If the export work later needs a detail from the morning, `/resume` the earlier conversation to look it up. ## Common mistakes - Compacting again and again to start new work. The summary drags the old task forward. `/clear` is the clean break. - Clearing in the middle of a task. You lose the summary of decisions taken so far and have to re-explain them. - Believing `/clear` wipes CLAUDE.md. It reloads like any new conversation. - Treating the summary as a transcript. Exact error text and long outputs are gone; re-run the command if you need them verbatim.

  • Does /clear delete the conversation it replaces in Claude Code?
    No. The previous conversation is saved, and `/resume` lists it so you can return to it. `/clear` accepts a name to label it in the `/resume` picker, which helps when you plan to come back. Within the same Claude Code process the rewind menu also offers an entry for the conversation before the clear.
  • How can you shape what Claude Code keeps on every compaction without typing focus text each time?
    Add a section headed "Compact Instructions" to the project CLAUDE.md, for example asking the summary to focus on test output and code changes. Claude Code takes it into account when the conversation is compacted. Focus text on a single `/compact` still applies for that run.

  • /clear also wipes CLAUDE.md, so project instructions must be pasted in again
  • /compact keeps the full history and only hides old messages from view
  • /clear permanently deletes the previous conversation
  • Running /compact repeatedly is the right way to start an unrelated task
  • Focus text after /compact is ignored because the summary format is fixed
open as a page

In a four-hour Claude Code session, Claude ignores a path-scoped rule and an early decision after auto-compaction — what survived, and what do you change?

level: seniorimportance: must knowfreq 15%

basics

~20 s

Content loaded from disk comes back after compaction: project-root CLAUDE.md, unscoped rules, auto memory and the plan are re-injected. Path-scoped rules, nested CLAUDE.md and chat-only decisions are summarized away, so move what must persist into project-root CLAUDE.md.

open as a page

When does Claude Code auto-compact a session, and how do you make it compact earlier with /autocompact or its overrides?

level: middleimportance: should knowfreq 9%

basics

~10 s

By default Claude Code auto-compacts when the conversation reaches the model's context limit, or about 967K tokens on native 1M-window models. /autocompact 500k, --autocompact, autoCompactWindow or CLAUDE_CODE_AUTO_COMPACT_WINDOW sets an earlier window.

open as a page

In Claude Code, what already fills the context window before your first prompt, and how does /context show it?

level: middleimportance: should knowfreq 14%

basics

~20 s

Before the first prompt Claude Code loads the system prompt, environment details, every applicable CLAUDE.md, the start of auto memory, skill descriptions and MCP tool names. /context shows usage by category, the files that loaded and suggestions to cut it.

open as a page

Why does a Claude Code session stop with 'Autocompact is thrashing' after reading a huge log file, and how do you recover?

level: seniorimportance: nice to knowfreq 5%

basics

~20 s

Auto-compaction succeeded, but an oversized file or tool output refilled the window after each summary, so Claude Code stopped retrying. Read in smaller chunks, run /compact with focus that drops the output, or use a subagent.

open as a page