Claude Code context window keeps filling up: why it compacts, and what to do
Claude Code compacts when the conversation gets close to the size of the context window: it replaces the history with a summary so the session can go on. If that keeps happening, something is filling the window faster than it should. Part of the window is taken before you type anything, by your CLAUDE.md, auto memory and tool lists. The rest fills with file reads and command output. Shrink what loads at the start, keep long output out, and clear between tasks.
Updated 2026-11-16
What fills the window#
Anthropic’s context window page lists what is in context before you type: CLAUDE.md, auto memory, the names of your MCP tools, and the descriptions of your skills. That part is the same size on every turn of every session.
Then the session adds to it. Each file read goes into context and stays. So does the output of every command, every search result and every answer. Path-scoped rules load next to the files they match. A long test log or a large file can take more room than an hour of conversation.
A warning that the context is nearly full is not a usage limit. It is about the size of this one conversation. If you were stopped by a plan limit, see Claude Code usage limit reached.
What survives compaction, and what does not#
Compaction summarizes the conversation and then puts some things back. This is why an instruction can seem to vanish halfway through a session.
| What | After compaction |
|---|---|
| CLAUDE.md at the project root, and rules with no path scope | Read again from disk and put back |
| Auto memory | Read again from disk and put back |
| Files Claude read or edited | Up to five are read again, most recently changed first |
| A CLAUDE.md in a subfolder, and path-scoped rules | Gone until Claude touches a matching file again |
| Instructions you gave only in the conversation | Summarized with everything else |
| Text a hook added earlier | Summarized with everything else |
So an instruction that must hold for the whole session belongs in the root CLAUDE.md, not in a message. And a compaction is not free: /compact has to read the conversation it summarizes, so compacting a large session is itself a large request.
Six ways to compact less often#
1. Look at what is using the room#
Run /context. It shows the window by category with suggestions, including which CLAUDE.md and auto memory files loaded. Fix the biggest line first.
2. Shrink what loads before you type#
Everything in your CLAUDE.md is in the window from the first turn to the last, and it comes back after every compaction. Anthropic suggests keeping each file under 200 lines. CLAUDE.md too long covers how to split it.
3. Clear between tasks#
Run /clear when you switch to unrelated work. Old conversation crowds out the files you need next. Use /rename first if you want to come back with /resume.
4. Compact on your terms#
Before a long new task, run /compact with what to keep, for example /compact focus on the auth bug fix. The summary then keeps what you chose, not what the automatic pass guessed. /rewind can summarize only part of the conversation.
5. Send large reads to a subagent#
A subagent works in its own context window. The files it reads stay there, and only a summary comes back to your session. Use it for research, log reading and documentation lookups.
6. Trim long output before it lands#
Ask for the failing tests, not the whole run. A hook can do this for you: Anthropic’s cost docs show one that keeps only the last lines of a test command’s output.
Shrinking the startup part automatically#
Step 2 pays on every turn and after every compaction. MinniMemoryMCP does it for you: it sorts your CLAUDE.md or AGENTS.md, MEMORY.md and the files they import into a small part that loads on every turn and files Claude opens only when a task needs them. Every line is kept, and undo puts the originals back.
$ npm i -g minnimemory
$ minnimemory installWith MinniMemoryMCP 1.6.0 on our test memory, the agent went looking in its memory 17 times instead of 89 over the same 87 answers, and the run used 47.2% fewer tokens. The method is on the Evidence page. For the token side of the same problem, see How to reduce Claude Code token usage.