Skip to content
Claudekit.ai

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

Manage the Claude Code context window: what loads at startup, when to use /context, /compact and /clear, how compaction works, and habits that keep it lean.

By Claudekit Team Published 11 min read

Long Claude Code sessions get worse in a predictable way: the model forgets a constraint from an hour ago, re-reads files it already saw, and usage climbs. The cause is almost always the context window, the fixed amount of text Claude can hold at once. Managing it well is the single biggest lever on both quality and cost.

This guide explains what fills the window, how compaction works, and which commands and habits keep it lean. Behaviour is checked against the official context window and costs docs as of October 2026.

What’s in the context window

Before you type anything, Claude Code loads:

  • The system prompt (plus any output style or --append-system-prompt text).
  • Your CLAUDE.md files (or AGENTS.md) and auto memory.
  • MCP tool names and server instructions. Full tool definitions are deferred by default through tool search and load only when Claude needs a tool.
  • Skill descriptions, so Claude knows which skills exist. The full skill body loads only when invoked.

As you work, every file read, command output, tool result and reply adds to it. Path-scoped rules load alongside matching files. Claude Code sends the full conversation with every request, which is why a one-line question in a session open all day still draws usage for the whole history.

/context: see what’s using space

/context

/context shows current usage as a coloured grid, broken down by category, with optimisation suggestions for context-heavy tools, memory bloat and capacity warnings. It also lists which CLAUDE.md and memory files loaded. In fullscreen mode the per-item breakdown is collapsed; /context all expands it.

Make it a habit to run it when a session feels sluggish, and once after setting up a new project, to see your baseline before any work starts. If you want a constant readout, a custom status line can display context usage continuously.

/compact: summarise and keep going

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

/compact replaces the conversation history with a structured summary, freeing space while keeping the thread. The optional instructions tell the summary what to keep. Without them, it decides for itself.

You can also put standing instructions in your project CLAUDE.md:

# Compact instructions

When you are using compact, please focus on test output and code changes

What survives compaction

ContentAfter compaction
System prompt and output styleStill apply
Project-root CLAUDE.md and unscoped rulesRe-injected from disk
Auto memoryRe-injected from disk
Plan written in plan modeRe-injected from disk
Path-scoped rules, nested CLAUDE.mdReload on demand when a matching file is touched
Files Claude read or editedUp to five re-read, most recently modified first
Invoked skill bodiesRe-injected, capped at 5,000 tokens per skill and 25,000 in total; oldest dropped first
Instructions you only typed in chatSummarised with everything else

Two practical lessons follow. First, anything that must persist belongs in CLAUDE.md, not in a chat message. Second, put the most important instructions at the top of a SKILL.md, because truncation keeps the start of the file.

If something keeps getting lost, a SessionStart hook with the compact matcher can re-inject it every time.

Partial compaction with /rewind

/rewind (or double-tap Esc) opens the checkpoint menu. Pick a message and choose Summarize from here or Summarize up to here to compress only part of the conversation, for example a long debugging detour you no longer need verbatim.

Auto-compaction

You don’t have to compact manually. Claude Code compacts automatically as you approach the limit, so a full window doesn’t end the session. The trigger point depends on your model and configuration.

To compact earlier, set the auto-compact window:

/autocompact 500k

/autocompact auto returns to the default for your model. Running it with no argument shows the current value. Compacting earlier trades some history for a session that stays responsive and cheaper per message.

/clear: start fresh

/clear auth-refactor

/clear starts a new conversation with empty context while keeping project memory. The optional name labels the old conversation in the /resume picker, so you can come back to it. Aliases: /reset and /new.

The official advice is blunt: use /clear when switching to unrelated work, because stale context costs tokens on every message and crowds out the files you need next. Unlike /compact, which has to read the conversation it summarises, /clear costs nothing.

/clear or /compact?

SituationUse
Moving to an unrelated task/clear
Same task, window getting full/compact with focus instructions
One noisy detour in an otherwise useful thread/rewind then Summarize
Need a quick answer without polluting history/btw

/btw deserves a mention: it asks a side question answered from the current context, and neither the question nor the answer enters the conversation history.

Subagents: keep big reads out of your window

Subagents run in their own context window. When Claude delegates research, a test run or log processing to a subagent, the verbose output stays there and only a summary comes back. Built-in agents include Explore (read-only codebase search) and Plan (research used in plan mode).

You can ask for this explicitly:

Use a subagent to run the test suite and report only the failing tests with their error messages

This is the most effective habit for long sessions. Note the trade-off: the subagent’s requests still count toward your usage, so for simple jobs give custom subagents a smaller model. Our subagents guide shows how.

Shrink what loads every session

Everything that loads at startup costs tokens on every request. Audit these:

CLAUDE.md

Anthropic recommends keeping each CLAUDE.md under 200 lines. Imports with @path don’t help here, because imported files load with the file that imports them. What helps:

  • Move instructions for one part of the codebase into .claude/rules/ with paths frontmatter.
  • Move multi-step procedures (PR review, migrations, releases) into skills.
  • Run /doctor to get proposed trims.

The CLAUDE.md guide has templates that stay short.

Skills: progressive disclosure

Skills are designed for this. Only the description sits in context; the body loads when the skill is invoked, and supporting files in the skill folder load only when Claude decides it needs them. The combined description and when_to_use text is truncated at 1,536 characters in the skill listing, so put the key use case first.

A large library still adds up, because every auto-invocable description loads each session. /skill-doctor shows what each skill costs in context and how often it’s used, and /skills lets you hide ones you don’t need. Setting disable-model-invocation: true on a skill keeps its description out of context entirely; you can still run it by name. See best Claude Code skills for a lean starting set.

MCP servers

Tool definitions are deferred by default, so only names and server instructions load up front. Still:

  • Disable servers you aren’t using with /mcp.
  • Prefer CLI tools like gh where they exist; the docs note they’re more context-efficient than MCP servers.
  • Large tool outputs count too. Claude Code warns when an MCP tool result exceeds 10,000 tokens and caps output at 25,000 tokens by default (MAX_MCP_OUTPUT_TOKENS changes the cap).

Need a bigger window instead?

Per the docs, Fable models, Sonnet 5 and later, Haiku 5.5, Opus 4.6 and later, and Sonnet 4.6 support a 1 million token context window, selected with a [1m] model variant where your plan allows it. Compaction works the same way at the larger size. A bigger window delays the problem; it doesn’t replace the habits above, and a huge conversation still costs more per message.

A context routine that works

  1. Start each new task with /clear.
  2. Use plan mode for anything non-trivial, so Claude explores once and you approve a direction before it spends tokens on the wrong path.
  3. Delegate searches and test runs to subagents.
  4. Check /context when the session feels slow.
  5. /compact with explicit focus before switching sub-tasks in the same thread.

These habits are part of a broader set; see our Claude Code best practices. 6. Write anything you’d hate to lose into CLAUDE.md.

The same habits lower your bill: see Claude Code pricing for how context size translates into usage. For running Claude without an interactive session at all, see headless mode.

Context management in your Claude kit

Context is the budget every other part of a Claude kit spends from. A good kit keeps always-on context small (short CLAUDE.md, few auto-invoked skills, only the MCP servers you use) and pushes everything else into on-demand skills and subagents.

Frequently asked questions

How big is the Claude Code context window?

It depends on the model. Per Anthropic's docs, Fable models, Sonnet 5 and later, Haiku 5.5, Opus 4.6 and later, and Sonnet 4.6 support a 1 million token context window, with availability depending on your plan. Run /context to see your session's actual usage.

What happens when the context window fills up?

Claude Code compacts automatically as you approach the limit, summarizing older conversation history so the session can continue. You can compact earlier with /compact, set the threshold with /autocompact, or start fresh with /clear.

Does /compact delete my CLAUDE.md instructions?

No. The project-root CLAUDE.md, unscoped rules and auto memory are re-injected from disk after compaction. Path-scoped rules and nested CLAUDE.md files reload on demand. Instructions you only typed in chat are summarized with everything else.

Should I use /clear or /compact?

Use /clear when you switch to unrelated work; it starts an empty conversation and costs nothing. Use /compact when you want to keep going on the same task but free space; it summarizes the conversation, which is itself a large request.

Do subagents use my context window?

No. Each subagent runs in its own context window, so its file reads and tool output stay there. Only its summary returns to your main conversation. Its requests still count toward your usage.

Get the weekly Claude digest

New skills, MCP servers, prompts and Claude updates — one short email a week. No spam, unsubscribe anytime.

The newsletter is launching soon. Follow the RSS feed in the meantime.