Claude Code context window: what fills it, how to free it
The Claude Code context window fills with memory files, history and tool output. /clear starts a new session, and a shorter CLAUDE.md cuts the fixed load.


The Claude Code context window holds your prompts, the conversation so far, tool output and the memory files loaded at launch. Each Claude Code session begins with a fresh context window, and /clear starts a new session when you want an empty one. Trimming CLAUDE.md lowers the fixed load that every session pays.
What fills the window before you type
Claude Code builds the starting context from files, not from your first message. All discovered files are concatenated into context rather than overriding each other, and both are loaded at the start of every conversation, CLAUDE.md and auto memory alike.
| Source | When it loads | Detail |
|---|---|---|
| CLAUDE.md above the working directory | At launch | Concatenated, not overridden |
| CLAUDE.md in a subdirectory | On demand | After Claude reads, writes or edits a file there |
| Files pulled in with @ imports | At launch | Same cost as pasting them in |
| Auto memory | Every session | First 200 lines or 25KB |
| Path-scoped rules | When matching files are in play | Skipped otherwise |
CLAUDE.md in --add-dir folders | Off by default | Needs an environment variable |
Imports are the usual trap. They don’t reduce its context cost, because imported files also load at launch, so splitting a long file organizes it without making it cheaper. The docs ask you to target under 200 lines per CLAUDE.md file, since longer files consume more context and reduce adherence.
How to see what is in it
Two commands show the load, and one number looks like a context meter but is not.
/context # lists the Memory files that loaded/usage # plan breakdown, including behavior flagsThe count beside the spinner is a live, approximate count of the output the current turn has produced so far. Your prompt, the history and the rest of your context do not move it, though that count measures the size of your context when verbose mode adds its own figure.
On a paid plan, /usage flags habits that burn quota. Behavior flags: behaviors such as long context or cache misses, flagged when one accounts for 10% or more of recent usage. The longer story on spend is in what burns your Claude Code quota.
Commands that clear, compact or trim
| Command or event | What it does | Caveat |
|---|---|---|
/clear | Starts a new session, so the window is empty | Before v2.1.211, cost totals kept accumulating across it |
| Compaction | Claude Code rewrites the conversation | The spinner count resets when it happens |
| Clearing old tool results | Drops stale tool output from context | Counts as an expected cache rebuild |
/doctor prompt-audit | Reports stale or conflicting instruction files | Needs v2.1.283 or later |
The cache effect is documented: when Claude Code has itself just rewritten the conversation, by compaction or by clearing old tool results from context, it counts the same kind of miss as an expected rebuild. That line in /usage needs v2.1.251 or later. A rebuild after a clear is normal, so it is not a sign something broke.
Give your build a human voice
Eleven v4 is ElevenLabs' most emotive voice model yet, for text to speech, voice agents and an API.
Hear Eleven v4Sponsored
Make AI video from inside Claude
Higgsfield has an MCP for Claude, plus Seedance 2.5 and Cinema Studio 4.0. New accounts get up to 50% off for their first 3 hours.
Get up to 50% offSponsored
Trim the fixed load
The cheapest tokens are the ones never loaded. Move anything that matters for one folder into a path-scoped rule, since those load only when Claude works with matching files. Leave maintainer notes in HTML comments: block-level HTML comments are stripped before the content reaches context.
<!-- maintainer note: stripped before it reaches context -->- Run npm test before committing- API handlers live in src/api/handlers/Keep instructions concrete, and do not expect them to enforce anything. Claude treats CLAUDE.md files as context, not enforced configuration, so a rule that must always hold belongs in a hook. The setup for that is in Claude Code hooks, and pacing a plan around long sessions is covered in how to pace your Claude subscription.
Verdict
The Claude Code context window fills first with memory files you control, then with history and tool output you steer. Run /context to see the load, /clear between unrelated tasks, and keep each CLAUDE.md short and scoped.
Try it on your own plan: read the Claude Code memory docs
Sources:Claude Code docs: Manage costs effectively, Claude Code docs: How Claude remembers your project.
Responses
Responses
Community guidelines
Write about the post. Be kind and be specific.
Responses are plain text. Spam, abuse and anything unlawful are removed, and the person who posted them may be blocked.
A response may wait for the owner to read it before it appears. Use Report on anything that should not be here.
Give your build a human voice
Eleven v4 is ElevenLabs' most emotive voice model yet, for text to speech, voice agents and an API.
Hear Eleven v4Sponsored
Make AI video from inside Claude
Higgsfield has an MCP for Claude, plus Seedance 2.5 and Cinema Studio 4.0. New accounts get up to 50% off for their first 3 hours.
Get up to 50% offSponsored
Get the next one
New posts by email, when they are ready. Confirm once and you are on the list.
Check your inbox
We sent a link to . Click it and you are on the list. Nothing is sent to an address that has not confirmed itself.
Keep reading


Generative UI agent instructions: 2,326 vs 12,720 tokens
Generative UI needs instructions that teach an agent to build cards. A short block cost 2326 tokens, a full guide 12,720, so keep the short block.


AGENTS.md vs CLAUDE.md: which file each tool reads
AGENTS.md vs CLAUDE.md: Codex reads AGENTS.md, Claude Code reads CLAUDE.md or an AGENTS.md in its place, so one repo file can serve both.


Claude Code subagents: when to split work off
What Claude Code subagents are, how to define one in a Markdown file, and when a separate context window keeps your main conversation clean.

