Claude Code's context window: why it fills up and what to do
Why Claude Code's context window fills up, what loads before you type, and the commands (/context, /compact, /clear) that stop you running out mid-task.
Claude Code's context window holds everything the model can see in a session: your messages, every file it read, every command output, your CLAUDE.md, loaded skills and tool lists. It fills faster than most people expect because file reads and test output are far bigger than your prompts. Claude Code compacts automatically near the limit, so you rarely hit a hard wall, but a bloated context still costs you quality and plan usage.
#What is actually in Claude Code's context window?
Before you type a word, Claude Code has already loaded a base layer: the system prompt, your ~/.claude/CLAUDE.md, the project's CLAUDE.md, the start of auto memory (MEMORY.md), the names of MCP tools and the descriptions of your skills. Then every turn adds to it:
- the files Claude reads (a 2,000-line file is a lot of tokens);
- search results and command output, especially test runs and build logs;
- Claude's own answers and its thinking;
- rules that load when Claude touches matching files;
- output from hooks.
Two things are not in it. A subagent works in its own context window, and only its summary comes back to yours. And a skill's full body loads only when the skill is invoked, which is why long, situational instructions belong in skills rather than in CLAUDE.md.
#How do I see how full it is?
Run /context in a session. It gives a live breakdown by category (system, memory files, MCP, messages, free space) with suggestions, and it tells you which CLAUDE.md and memory files actually loaded. /memory opens those files for editing.
You can also put the usage in your status line (see the status line page in the official docs) so it is always in view. If the breakdown surprises you, the usual culprits are a huge CLAUDE.md, many MCP servers, or one enormous tool result that has been sitting in the conversation for an hour.
#What happens when it gets full?
Claude Code compacts the conversation on its own as you approach the limit: it replaces the history with a structured summary and carries on. What survives is more than you might fear:
| Item | After compaction |
|---|---|
| Project-root CLAUDE.md and auto memory | Re-injected from disk |
| The plan from plan mode | Re-injected from disk |
| Up to five recently read or edited files | Re-read (large ones come back as a path only) |
| Invoked skill bodies | Re-injected, with size caps |
| Background commands and subagents | Keep running |
| Your early instructions, given only in chat | Summarized, and may lose detail |
The last row is the one that bites. A rule you stated in message three of a long session may be paraphrased away. Anything that must always hold goes in CLAUDE.md, not in the conversation. Rules with paths: frontmatter and nested CLAUDE.md files load on demand, so they are summarized away like everything else; if a rule has to persist, put it in the project-root file.
If one file or tool output is so large that the context refills right after every summary, Claude Code stops auto-compacting after a few attempts and shows an error instead of looping. The fix is to stop reading that file whole.
#When should I /compact, /clear or start a new session?
The three commands do different jobs.
/clearstarts a fresh conversation in the same session. Use it between unrelated tasks. Old conversation crowds out the files you need next and is re-read on every message. Run/renamefirst if you want to find the old one again with/resume./compact <focus>summarizes and keeps going. Use it in the middle of one long task, with a focus:/compact keep the failing test names and the auth refactor decisions. A focused summary beats the automatic guess.- A new session is right when the task is done. Sessions are independent; what carries over is CLAUDE.md and auto memory.
Two more controls are worth knowing. /rewind lets you pick a message and choose Summarize from here or Summarize up to here, which compacts only part of the conversation. And /autocompact (also a --autocompact flag) sets how full the window gets before the automatic pass runs, if you want it to compact earlier than the default. The accepted values and defaults depend on your model, so read the model configuration page before changing it.
You can also add a standing instruction to CLAUDE.md so every compaction knows what to keep:
# Compact instructions
When you compact, keep: the list of files changed, failing test output,
and any decision we made about the data model.
#How do I stop filling it up so fast?
Most of the gain comes from a handful of habits:
- Be specific. "Add input validation to
login()inauth.ts" reads one file. "Improve the codebase" reads fifty. - Delegate big reads. Ask a subagent to investigate and report. The file contents stay in its window, and you get a summary. See Claude Code subagents.
- Trim CLAUDE.md. It loads every session. Aim for essentials, and move workflow-specific instructions into skills, which load only when used. See how to write a CLAUDE.md.
- Prune MCP servers. Tool definitions are deferred by default, so idle servers cost little, but disable the ones you do not use. Command-line tools like
ghadd no per-tool listing at all. - Filter noisy output. A hook can cut a test run to its last 100 lines before Claude sees it.
- Plan first. Plan mode explores and proposes before editing, which avoids reading and writing a whole wrong approach.
A bigger window helps but does not remove the problem. Some models run with a one-million-token window, depending on model and plan (check the model configuration page for yours). More room is not free: Claude Code sends the whole conversation with each request, so a long session draws more from your plan on every turn, even for a one-line question. That is the link between context and your limits; Claude Code usage limits covers the other half.
#Why does a long session eat my usage?
Because the history is re-read each turn, at the cheaper cached rate but still re-read. A session left open all day is expensive per message. The first message after a long break also misses the prompt cache and reprocesses everything. /compact itself is a large request, since it reads the conversation it summarizes, while /clear costs nothing. So: clear when the task changes, compact with a focus when it does not, and do not leave a heavy session parked for hours if you will not return to it.
#In Relais
Relais shows how full a session's context is under the composer, turning orange from 70%, with a Compact button for when it is time. Sessions are ordinary Claude Code sessions, so /context, /compact and /clear work the same. See features for the composer, and the FAQ for how Relais relates to your Claude plan.