# Claude Code context window: a practical guide

URL: https://agentvera.dev/en/blog/claude-code-context-window/ · Published: 2026-10-23

Manage the Claude Code context window: what fills it, how /context, /compact and /clear work, CLAUDE.md size, subagents, MCP cost and signs of context rot.

**In short:**

- Claude Code’s context holds the system prompt, tool names, CLAUDE.md, every message, file read and command output, and model performance degrades as it fills.
- Run /context to see what is using it, /compact with a focus to summarize a long session on the same task, and /clear when switching to unrelated work.
- Keep CLAUDE.md under about 200 lines, move task-specific instructions into skills, and send heavy research to subagents so only a summary returns.

The Claude Code context window is everything the model sees on a given turn: the system prompt, tool names, your CLAUDE.md, every message, every file Claude read and every command output in the session. To manage it, check what is in it with `/context`, compact long sessions with `/compact` (or let auto-compact do it), start unrelated work with `/clear`, keep CLAUDE.md short, and send heavy investigation to subagents so only their summary comes back. The rest of this guide shows how each of these works and when to reach for it.

## What fills the context window

A [context window](/en/glossary/context-window/ "Context window") is measured in [tokens](/en/glossary/token/ "Token"), and in Claude Code it fills from two directions: what loads before you type anything, and what the session piles up as it works.

### Loaded at startup

According to Claude Code’s documentation, these are in the context before your first prompt:

- The system prompt and the built-in tools.
- CLAUDE.md files (project, user and any parent folders) and auto memory. AGENTS.md can load in place of CLAUDE.md.
- MCP tool names and server instructions. Full tool definitions are deferred by default and load when a tool is used.
- Skill descriptions. The body of a skill only loads when it is invoked.

We measured this baseline in [our token usage post](/en/blog/claude-code-token-usage/ "Cut Claude Code token usage by 61%"): about 34.4k tokens on the first request with a standard setup, down to about 13.3k with a lean one. That baseline is re-sent on every turn.

### Added during the session

This is where most of the growth comes from:

| Source | Why it grows fast |
| --- | --- |
| File reads | A large file read in full can cost thousands of tokens, and re-reads cost the same again |
| Command output | Test runs, builds and logs are often long and mostly noise |
| Your messages and Claude’s replies | Every turn stays in the history |
| Tool results from MCP servers | A search or query result lands in context in full |
| Failed attempts | Wrong approaches and your corrections stay until you clear or compact |

A single debugging session or codebase exploration can produce tens of thousands of tokens. That matters because, as the Claude Code docs put it, LLM performance degrades as context fills: Claude may start forgetting earlier instructions or making more mistakes.

## How big is the window?

It depends on the model. Claude Code’s model configuration docs list a 1M-token context window for recent models (Fable models, Sonnet 5 and later, Haiku 5.5, Opus 4.7 and later run with it by default). Opus 4.6 and Sonnet 4.6 reach 1M only through their `[1m]` variant; otherwise they work at a 200K boundary.

A bigger window gives you room, not immunity. A session with 600k tokens of old exploration in it is still slower, costlier per turn and noisier than one that carries only what the current task needs.

## Read the meter: /context

Before changing anything, look. `/context` shows a live breakdown of what is using the window, grouped by category, with suggestions. It also lists which CLAUDE.md and memory files were loaded, which is the quickest way to find a forgotten instruction file in a parent folder.

```text
/context
```

A few related commands help here:

- `/memory` opens the loaded memory files so you can edit them.
- `/mcp` lists connected servers and lets you disable the ones you are not using.
- `/usage` shows token use for the session, including a prompt cache line.

You can also put context usage in a custom status line so you see it without asking.

## Compact: /compact and auto-compact

`/compact` replaces the conversation so far with a summary and keeps going in the same session. Claude Code also does this on its own as you approach the limit; that is auto-compact.

### Steer the summary

A plain `/compact` lets Claude decide what to keep. You get better results when you tell it:

```text
/compact Focus on the API changes and the list of files we modified
```

You can make this permanent with a `# Compact instructions` section in CLAUDE.md, for example: “When compacting, always preserve the full list of modified files and any test commands.”

To compact only part of the conversation, press `Esc` twice or run `/rewind`, pick a message and choose **Summarize from here** or **Summarize up to here**.

### Set when auto-compact runs

By default Claude Code compacts when the conversation reaches the model’s context limit; models running with a native 1M window compact a little earlier, at about 967K tokens. If you would rather compact sooner, set your own window:

```text
/autocompact 500k
/autocompact auto
```

The first saves a 500k window for the current model; the second returns to the default. The same setting exists as `autoCompactWindow` in `settings.json` and as the `CLAUDE_CODE_AUTO_COMPACT_WINDOW` environment variable for scripts. Values from 100K to 1M are accepted.

### What survives compaction

The docs list what is put back after a compact: the system prompt, the project-root CLAUDE.md, unscoped rules, auto memory and the current plan-mode plan. Recently modified files are re-read, and nested CLAUDE.md files and path-scoped rules reload when Claude works in those folders again. What does not survive verbatim is the conversation itself, so an instruction you only ever typed in chat can lose detail. If it matters, put it in CLAUDE.md.

One cost to keep in mind: `/compact` reads the whole conversation to summarize it, so the compact itself is a large request.

## Start over: /clear

`/clear` empties the conversation and costs nothing. Use it when you move to unrelated work. Claude Code’s best practices name two failure patterns it fixes:

- **The kitchen sink session.** You start one task, ask something unrelated, then go back. The context is full of irrelevant material.
- **Correcting over and over.** After two failed corrections on the same issue, the context is polluted with failed approaches. Clear and write a better first prompt that includes what you learned.

If you might want the session back, name it first with `/rename`, then `/clear`; `/resume` brings it back later. For a quick question that does not need to stay in history, `/btw` answers without adding to the conversation.

| Situation | Reach for | Why |
| --- | --- | --- |
| Same task, long history | `/compact <focus>` | Keeps the thread, drops the bulk |
| Only the early part is stale | `/rewind` → Summarize up to here | Keeps recent turns in full |
| Switching to unrelated work | `/clear` | Free, and nothing irrelevant carries over |
| Two corrections didn’t work | `/clear` + better prompt | Failed attempts mislead the next ones |
| One-off question | `/btw` | Never enters the history |

## Keep CLAUDE.md small

CLAUDE.md loads in every session, so every line is paid for on every turn. Claude Code’s docs suggest keeping it under about 200 lines and asking, for each line, whether removing it would cause mistakes. If not, cut it. A bloated file has a second cost beyond tokens: important rules get lost in the noise and Claude ignores them.

What to do with the rest:

- Move workflow-specific instructions (how to release, how to write a migration) into skills. Only their short descriptions load at startup; the body loads when the skill is used.
- Link to detailed docs instead of pasting them.
- Delete anything Claude already does right without being told, or turn it into a hook if it must always happen.

We go deeper on structure in [the CLAUDE.md and AGENTS.md guide](/en/blog/claude-md-agents-md/ "CLAUDE.md best practices").

## Use subagents to keep the main context clean

Research is the classic context killer: to answer “how does our auth handle token refresh?”, Claude may read twenty files. A [subagent](/en/glossary/subagent/ "Subagent") runs in its own context window, does that reading there, and returns only a summary to your main session.

```text
Use subagents to investigate how our authentication system handles token
refresh, and whether we have any existing OAuth utilities I should reuse.
```

Good candidates for a subagent:

- Codebase exploration before a change.
- Reading long logs or test output to find the one failure that matters.
- A review of the diff in a fresh context, which also avoids bias toward code the main session just wrote.

Subagents are not free. They spend their own tokens, and Claude Code’s docs note that agent teams use roughly 7 times as many tokens as a single session. The win is quality and focus in the main thread, not always a smaller bill.

## What MCP servers cost

The [Model Context Protocol](/en/blog/what-is-mcp-server/ "What is an MCP server?") used to be one of the biggest startup costs, because every tool definition of every server loaded up front. Claude Code now defers tool definitions by default (tool search), so until a tool is used, only its name and the server’s instructions are in context.

That changes the advice, but does not remove it:

- Disable servers you are not using in this project with `/mcp`.
- Prefer CLI tools such as `gh`, `aws`, `gcloud` or `sentry-cli` when they exist. The docs call them the most context-efficient way to reach external services.
- Watch tool results, not just definitions. A database query or a page snapshot returned by an MCP tool lands in context in full.

## Signs of context rot

“Context rot” is the informal name for a session that has quietly got worse because its context is too full or too noisy. Typical signs:

- Claude forgets a rule you stated earlier in the conversation, or one from CLAUDE.md.
- It re-reads files it already read, or asks about things it already knows.
- It repeats an approach you already rejected.
- Answers get vaguer and edits touch the wrong place.
- Each turn feels slower and the token counter climbs faster.

When you see two or more of these, run `/context`. If the conversation is the bulk, compact with a focus; if the session has wandered across tasks, clear. Also note that after an idle break the prompt cache expires, so the next message reprocesses the whole context at full price. A long-idle, large session is a good moment to compact or clear before you continue.

## Habits that keep sessions healthy

- **One task per session.** Name it, finish it, clear.
- **Point, don’t browse.** Reference files with `@path` and name functions instead of asking Claude to “look around”.
- **Scope investigations.** “Find where rate limits are enforced in `src/api`” beats “investigate rate limiting”. Or hand it to a subagent.
- **Trim command output.** Run single tests rather than the whole suite, and filter logs before Claude reads them.
- **Compact with a focus, early.** A compact you steer, before the window is nearly full, usually keeps the right details better than an automatic one at the limit.
- **Review CLAUDE.md like code.** Prune it when Claude starts ignoring rules.

## Where AgentVera fits

AgentVera runs Claude Code, Codex and other CLI agents side by side in one desktop app. It does not replace the habits above, but it takes some of the bookkeeping off you when you run several agents at once. All of this is on the [token savings page](/en/features/token-savings/ "Token savings"):

- **Live context size in the pane** for each agent, measured from the CLI’s own history, so it works beyond Claude Code and Codex.
- **Auto-compact on by default** at a 150k-token threshold, using each CLI’s own command (`/compact`, `/compress`, `/summarize`, `/smol`). Change it under Settings → Token savings.
- **Context profiles** (Standard, Balanced, Lean) that shrink the startup baseline per agent.
- **A read guard**, plus [smart tools](/en/features/smart-tools/ "Smart tools") for Claude Code, that refuse a re-read of an unchanged file and hand the agent an outline of a big file first.
- **A [project map](/en/features/project-map/ "Project map")** so agents find the relevant files without reading them one by one.
- **The [MCP manager](/en/features/mcp-manager/ "MCP manager")**, whose connection test shows an approximate token cost per tool.

It is still worth learning `/context`, `/compact` and `/clear` yourself. They work the same with or without AgentVera.

## Frequently asked questions

**How do I see what is in my Claude Code context window?** Run /context. It shows a live breakdown by category, such as system prompt, tools, MCP, memory files and messages, together with suggestions, and lists which CLAUDE.md and memory files were loaded.

**What is the difference between /compact and /clear?** /compact replaces the conversation with a summary and keeps working in the same session. /clear starts with an empty conversation. Use /compact when you are still on the same task and /clear when you switch to unrelated work.

**When does auto-compact run?** By default Claude Code compacts as the conversation approaches the model’s context limit. You can set your own window with /autocompact, for example /autocompact 500k, and return to the default with /autocompact auto.

**How long should CLAUDE.md be?** Claude Code’s docs suggest keeping it under about 200 lines. It loads in every session, so move instructions that only matter for some tasks into skills, which load on demand.

**Do MCP servers fill the context window?** Less than they used to. Tool definitions are deferred by default, so only tool names and server instructions load until a tool is actually used. Unused servers still add some weight, so disable the ones you do not need with /mcp.

---

**About AgentVera.** AgentVera is a desktop app for macOS, Windows and Linux, built by Solviera Teknoloji. It runs 18 AI coding agents (Claude Code, Codex, Gemini CLI, Copilot, Cursor, Antigravity, opencode, Hermes, Qwen Code, Kimi Code, Kiro, Amp, Droid, Goose, Vibe, Crush, Aider, Cline) side by side, per project, in real terminals with the user's own CLI installs and logins. The free plan has unlimited agents. Download: https://agentvera.dev/en/download/ · Pricing: https://agentvera.dev/en/pricing/
