← All posts

Claude Code Context Window: /compact, /clear, /context

Claude Code context window guide: what fills it, when to use /compact, /clear and /context, what survives compaction, and habits that keep sessions sharp.

The Claude Code context window is everything Claude can see in a session: the system prompt, your CLAUDE.md files, skill descriptions, tool definitions, every file it reads and every message so far. When it fills up, Claude Code compacts automatically by replacing the conversation with a structured summary. You can act before that happens: /context shows what is using the space, /compact summarizes on your terms (with optional focus instructions), and /clear starts a fresh conversation when you switch to unrelated work. Knowing which to use, and when, is the difference between a sharp session and one that slowly forgets what it was doing.

What fills the context window

A lot loads before you type anything:

  • System prompt and output style. Core instructions you never see.
  • Project CLAUDE.md and unscoped rules. Your standing instructions.
  • Auto memory. Claude's own notes from previous sessions, if enabled.
  • Skill descriptions. One-line summaries so Claude knows which skills exist. The full skill body only loads when a skill is used.
  • MCP tool names. By default, full tool schemas stay deferred and load on demand, so connecting many servers costs less than it used to.

Then the session itself adds up: your prompts, Claude's replies, every file read, every command output. File reads and long logs are usually the biggest line items.

The three commands that manage context
Command What it does Keeps Use it when
/context Shows usage as a colored grid with optimization suggestions Everything (read-only) You want to know what is taking space
/compact [instructions] Replaces the conversation with a structured summary A summary, recent files, invoked skills, startup content Same task continues, but the history is long
/clear [name] Starts a new conversation with empty context Nothing from the conversation You are switching to unrelated work
/context: look before you cut

Run /context first when a session feels sluggish or forgetful. It breaks usage down by category and points out context-heavy tools, memory bloat and capacity warnings. If a giant CLAUDE.md or an unused skill set is the problem, compaction will not fix it; trimming them will. Our CLAUDE.md best practices post covers keeping that file lean.

/compact: summarize on your terms

/compact on its own works like the automatic pass. The better habit is to give it a focus:

/compact focus on the payment retry bug and the files we changed for it

The summary then keeps what you chose instead of what the automatic pass guesses is important. Run it at natural breakpoints, such as after finishing an investigation and before starting the fix.

You can also compact part of a conversation. Run /rewind, pick a message, and choose Summarize from here or Summarize up to here.

/clear: start over cleanly

/clear gives you an empty conversation. Old conversation crowds out the files you need next and costs tokens on every message, so clearing between unrelated tasks is the single cheapest habit here. Pass a name, like /clear auth-refactor, to label the old conversation, then get it back later with /resume.

What survives compaction

This is where most confusion comes from. After a compact, whether manual or automatic:

Content After compaction
System prompt, output style Still apply
Project-root CLAUDE.md and unscoped rules Re-injected from disk
Auto memory Re-injected from disk
A plan written in plan mode Re-injected from disk
Files Claude read or edited Up to five re-read, most recently modified first
Skills you invoked Re-injected, capped at 5,000 tokens each and 25,000 total
Path-scoped rules, nested CLAUDE.md Reload on demand when Claude touches matching files
Background commands and subagents Keep running
The skill description listing Not re-injected

Two practical consequences. First, a rule that must survive compaction belongs in the project-root CLAUDE.md, not in a path-scoped rule. Second, put a skill's most important instructions near the top of SKILL.md, because truncation keeps the start of the file.

A file larger than 5,000 tokens comes back after compaction as a path reference rather than its full content, so Claude may re-read it if it needs it again.

Tuning automatic compaction

Claude Code compacts on its own as you approach the limit, so a full window does not end the session. The exact threshold depends on your model and configuration. If you would rather compact earlier, /autocompact sets the trigger point, for example /autocompact 500k, and /autocompact auto returns to the default tuned for your model.

If you need more room rather than a shorter conversation, Opus 4.6 and later and Sonnet 4.6 and later (among other current models) support a 1 million token context window, selected as a [1m] model variant where your plan allows it. Compaction works the same way at the larger size. A bigger window is not a reason to skip /clear: unrelated history still costs tokens on every turn.

Habits that keep context healthy
  1. /clear between unrelated tasks. Every time.
  2. /compact with a focus at breakpoints, not only when forced.
  3. Delegate big reads to subagents. A subagent reads the files in its own context window and returns a summary, so yours stays small. See the Claude Code subagents guide.
  4. Keep CLAUDE.md short and move rarely needed detail into skills, which load only when used.
  5. Audit MCP servers. Deferred schemas help, but servers you never use still add names and noise. Our MCP servers for Claude Code post lists the ones worth keeping.
  6. Run /context when output quality drops. It is often a context problem before it is a model problem.
Where the terminal fits

Context discipline is mostly a Claude Code habit, but it gets easier when you split work across sessions instead of cramming everything into one. One tab per task means each conversation stays focused and /clear is rarely needed mid-task. MOLTamp, a skinnable terminal shell for Claude Code, supports up to 50 tabs with attention badges that show which session needs you or has finished, plus session monitoring across them. Any terminal can run parallel sessions, though; our best terminal for Claude Code guide compares the options honestly.

Verdict

Use /context to see the problem, /compact with a focus to keep the thread of a long task, and /clear to start unrelated work fresh. Keep anything that must persist in the root CLAUDE.md, push big reads to subagents, and treat automatic compaction as a safety net rather than a strategy.

FAQ

What is the difference between /compact and /clear in Claude Code? /compact replaces the conversation with a structured summary so you can keep working on the same task with less context used. /clear starts a brand new conversation with empty context. Use /compact to continue, /clear to switch tasks.

Does Claude Code compact automatically? Yes. It compacts as you approach the context limit, so the session continues. You can change when that happens with /autocompact, for example /autocompact 500k.

Does CLAUDE.md survive /compact? The project-root CLAUDE.md and unscoped rules are re-injected from disk after compaction. Nested CLAUDE.md files and path-scoped rules reload on demand when Claude works with matching files again.

How do I see how much context I am using? Run /context. It shows a colored grid of usage by category, with suggestions for reducing it.

Can I get my conversation back after /clear? Yes. Use /resume to reopen it. Passing a name to /clear labels the old conversation so it is easier to find in the picker.


A quick honest note: MOLTamp is free to use and every feature works. A one-time $10 license removes a recurring popup and unlocks community skin uploads, with no subscription. If you want one tab per task with clear signals on each, download MOLTamp and try it.