Skip to content
,

Claude Code Context Window Guide (2026): /compact, /clear, /context and Auto-Compact

7–10 minutes
Woman in a brick-walled loft holding a tablet with a CONTEXT WINDOW card, hook never run out of context

Long Claude Code sessions slow down, cost more and start forgetting earlier instructions. The reason is almost always the context window: everything Claude knows about your session has to fit inside it, and it fills faster than most people expect.

This guide explains what fills the Claude Code context window, how to check it with /context, when to use /compact versus /clear, how auto-compaction works (including the 400K default on 1M models) and what survives a compaction. It follows Anthropic’s Claude Code documentation as of December 2026.

TL;DR

  • Check usage: /context shows a live breakdown with tips.
  • Shrink it: /compact focus on the auth fix summarizes the conversation and keeps what you name.
  • New task: /clear starts fresh; the old chat stays in /resume.
  • Auto-compact: 1M models compact near 400K by default. /autocompact 1M uses the full window.
  • Persist rules: keep must-follow rules in the project-root CLAUDE.md, which is re-read after compaction.
  • Save context: send big research to a subagent.

What Is in the Context Window?

The context window holds everything Claude can see in your session. Some of it loads before you type anything:

  • The system prompt and environment info.
  • Your CLAUDE.md files (user and project) and auto memory.
  • MCP tool names and skill descriptions.

Then every action adds more: each file Claude reads, path-scoped rules that load next to matching files, hook output after edits, command output such as test runs, and Claude’s own replies.

The docs walk through an example session. Before the user types, about 7,850 tokens are already loaded. After a short bug fix with a few file reads and a test run, the session uses 22,225 tokens. A subagent that did research used another 9,890 tokens in its own window, which never touched the main session.

Source Example tokens
System prompt 4,200
Project CLAUDE.md 1,800
Reading one source file 1,100-2,400
npm test output 1,200
Skill descriptions 450
Subagent summary returned 420

These are illustrative numbers. Large CLAUDE.md files, many MCP servers and long logs push them much higher. Our CLAUDE.md guide shows how to keep that file lean.

Check Your Usage With /context

  1. Type /context in any session.
  2. Read the grid. It shows current usage as a colored grid, broken down by category.
  3. Look at the suggestions. It flags context-heavy tools, memory bloat and capacity warnings, and lists which CLAUDE.md and auto memory files loaded.
  4. Use /context all for the full per-item breakdown.
  5. Fix what is big. Run /memory to open and trim memory files, or disable MCP servers you are not using.

If the conversation is already over the limit, /context shows how far over you are and which command frees space. You can also add context usage to your status line; see our Claude Code status line guide.

Use /compact

/compact replaces the conversation history with a structured summary, then reloads your startup content. You keep working in the same session with far fewer tokens.

/compact
/compact focus on the auth bug fix and the failing test names

Adding focus instructions is the best habit. The summary then keeps what you choose instead of what an automatic pass guesses is important. Run it before you start a long new subtask, not after the window is already full.

In the docs example, /compact took the session from 22,225 tokens to 17,095: the startup content, a 1,725-token summary, the four recently read files and the last skill body.

Compact only part of the conversation

Run /rewind, select a message, then choose Summarize from here or Summarize up to here. This is useful when the early part of a session still matters but a long detour does not. Our checkpoints and rewind guide covers the menu.

Use /clear Between Tasks

/clear starts a new conversation with empty context. Use it when you switch to unrelated work, because old conversation crowds out the files you need next and costs tokens on every message.

/clear
/clear release-prep

Nothing is lost. Claude Code saves the previous conversation, and you can reopen it with /resume. Passing a name, as in /clear release-prep, labels the conversation you are leaving so it is easy to find. Aliases /reset and /new do the same thing.

/compact vs /clear vs /rewind

Command What it does Use when
/compact Summarizes history, keeps the session going Same task, context getting full
/clear Empty context, new conversation Switching to unrelated work
/rewind Go back, or summarize part of the history A detour you want to drop or condense
/context Shows what is using space Before deciding which of the above
/autocompact Sets when automatic compaction runs You want it earlier or later

How Auto-Compaction Works

As you approach the auto-compact window, Claude Code compacts automatically, the same way /compact does, so a long conversation does not end your session.

When it runs depends on the model:

  • Current 1M-context models (Fable, Sonnet 5 and later, Haiku 5.5, Opus 4.7 and later) use auto, which is 400K. Compaction runs at about 367K tokens.
  • Sonnet 4.6 and Opus 4.6 without extended context compact at the 200K boundary.
  • With CLAUDE_CODE_DISABLE_1M_CONTEXT=1, 1M models compact at 200K.
  • Unknown model IDs, such as a gateway alias, compact at the window Claude Code assumes for them.

Why 400K on a 1M model? Anthropic tunes auto per model for cost and performance. Compacting sooner keeps later requests smaller, so long sessions use fewer tokens.

You may see a notice that says the session “now autocompacts near 400k tokens instead of 1m”. Some sessions, such as ones that send more than about 180K tokens of system prompt and tools each turn, get a larger window automatically.

A session left idle can also compact on its own. The idleCompaction setting controls this.

Change the Auto-Compact Window

  1. Check the current window: run /autocompact with no value.
  2. Change it for this model: /autocompact 500k or /autocompact 1M. It is saved in your user settings for that model.
  3. Go back to the tuned default: /autocompact auto.
  4. For every model: add "autoCompactWindow": 200000 to ~/.claude/settings.json.
  5. For one launch: claude --autocompact 500k.
  6. In scripts or cloud environments: CLAUDE_CODE_AUTO_COMPACT_WINDOW=200000, which beats all the other methods.

Values must be 100K or more. The command accepts 200000, 500k, 1M or a bare number from 100 to 1000 meaning thousands. Be careful with the environment variable: CLAUDE_CODE_AUTO_COMPACT_WINDOW=200 means 200 tokens (raised to the 100K minimum), while /autocompact 200 means 200,000.

Using an LLM gateway that rejects requests over 200K? Set CLAUDE_CODE_AUTO_COMPACT_WINDOW=200000 so every model compacts at that boundary.

What Survives Compaction

Item After compaction
System prompt and output style Still apply
Project-root CLAUDE.md and unscoped rules Re-read from disk
Auto memory Re-read from disk
Skill descriptions Rebuilt and re-injected
Plan written in plan mode Re-read from disk
Rules with paths: and nested CLAUDE.md Reload on demand when matching files are touched
Files Claude read or edited Up to five re-read, most recently modified first; files over 5,000 tokens come back as a path only
Invoked skill bodies Re-injected, capped at 5,000 tokens each and 25,000 total
Background commands and subagents Keep running
Context added by hooks Summarized with the conversation

Two practical lessons follow. If a rule must survive compaction, remove its paths: frontmatter or move it into the project-root CLAUDE.md. And put the most important instructions near the top of a long SKILL.md, because truncation keeps the start.

A SessionStart hook that matches the compact source can also re-add context after every compaction; see our hooks guide.

8 Ways to Keep Context Small

  1. Clear between tasks instead of running one endless session.
  2. Compact with focus before a new subtask.
  3. Delegate big reads to a subagent; only its summary comes back.
  4. Keep CLAUDE.md short and move detail into path-scoped rules or skills.
  5. Disable unused MCP servers, and keep MCP tool search on.
  6. Point Claude at files instead of pasting huge logs; write long output to a file.
  7. Ask for targeted test output, such as one failing test, not the whole suite.
  8. Watch /context on long sessions and act before the window fills.

Smaller context also means lower cost. See Claude Code pricing for how usage counts against plan limits.

Troubleshooting

“Prompt is too long” or context limit error

Auto-compaction is probably off (DISABLE_AUTO_COMPACT=1 or "autoCompactEnabled": false), or the window is held at 200K. Run /compact, then remove that variable or setting to turn auto-compaction back on.

Claude forgot an instruction after compaction

Instructions given only in chat are summarized. Put lasting rules in the project-root CLAUDE.md.

Compaction happens at 367K on a 1M model

That is the auto default. Run /autocompact 1M if you want the full window.

The session compacts too early behind a gateway

Claude Code may not know your gateway’s model ID. Correct the window as described in the model configuration docs, or set the auto-compact window yourself.

FAQ

What does /compact do in Claude Code?

It replaces the conversation history with a summary so the session can continue with fewer tokens.

What is the difference between /clear and /compact?

/clear starts an empty conversation; /compact keeps the same conversation in summarized form.

How big is the Claude Code context window?

Current models such as Opus 5.5, Sonnet 5.5, Haiku 5.5 and Fable run with 1 million tokens, but compact near 400K by default.

How do I see how much context I am using?

Run /context.

Can I turn off auto-compact?

Yes. Set DISABLE_AUTO_COMPACT=1 or "autoCompactEnabled": false; manual /compact still works. Without auto-compaction, a session stops with a context-limit error when the window is full.

Does /clear delete my conversation?

No. It is saved and can be reopened with /resume; see our guide to resuming sessions.

Sources

Free weekly email

Get new AI guides every week

One short weekly email with our newest local AI, ComfyUI and AI tool guides. No spam, no pop-ups, just the good stuff.

Free. Unsubscribe anytime in one click. We only use your email to send this newsletter. See our privacy policy.

Woman in a brick-walled loft holding a tablet with a CONTEXT WINDOW card, hook never run out of context