Skip to content

Blogclaude-code

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.

3hship3 min read

Share

A frosted glass jar holds a short stack of clay discs, the top disc glowing soft violet, with one empty disc resting beside it.
Contents

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 flags

The 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.

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

Sign in to write a response

Keep reading