# Claude Code context window keeps filling up: why it compacts, and what to do

> Source: https://minniai.com/learn/claude-code-context-window-full (canonical HTML page)

[Guides](https://minniai.com/learn)


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](https://code.claude.com/docs/en/context-window) 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](https://minniai.com/learn/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](https://minniai.com/learn/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](https://minniai.com/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.

install it for Claude Code

```
$ npm i -g minnimemory
$ minnimemory install
```

With 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](https://minniai.com/evidence). For the token side of the same problem, see [How to reduce Claude Code token usage](https://minniai.com/learn/reduce-claude-code-token-usage).

Try MinniMemoryMCP

Free, runs on your computer, and every change can be undone. Two commands install it for Claude Code; the [docs](https://minniai.com/minnimemorymcp/docs) cover Codex and the rest.

install it for Claude Code

```
$ npm i -g minnimemory
$ minnimemory install
```

## More guides

- [How to reduce Claude Code token usage](https://minniai.com/learn/reduce-claude-code-token-usage) Where the tokens go each turn, and eight ways to spend fewer.

Updated 2026-11-16 · Minni AI

- [Claude Code usage limit reached: what to do, and how to hit it less](https://minniai.com/learn/claude-code-usage-limit-reached) What each limit message means, what to do now, and how to send less every turn.

Updated 2026-11-16 · Minni AI

- [CLAUDE.md too long: what Claude Code does with it, and how to split it](https://minniai.com/learn/claude-md-too-long) What a long CLAUDE.md costs, the real size limits, and four ways to cut it.

Updated 2026-11-16 · Minni AI

- [How to reduce Codex token usage](https://minniai.com/learn/reduce-codex-token-usage) Where Codex spends tokens, and seven ways to spend fewer.

Updated 2026-11-16 · Minni AI

- [Codex usage limits: why they drain and how to use fewer tokens](https://minniai.com/learn/codex-usage-limits) How the windows work, how to check what is left, and what uses the allowance up.

Updated 2026-11-11 · Minni AI

- [AGENTS.md too large: what Codex cuts off and how to split it](https://minniai.com/learn/agents-md-too-large) The 32 KiB cap, how to see which files load, and five ways back under it.

Updated 2026-11-11 · Minni AI

- [How to lower a Claude Code or Codex API bill](https://minniai.com/learn/lower-claude-code-codex-api-bill) What a coding agent bills on an API key, and the levers that move it.

Updated 2026-11-16 · Minni AI

- [Why Claude Code sessions get expensive](https://minniai.com/learn/why-claude-code-sessions-get-expensive) Every turn re-sends the whole session. What makes that grow.

Updated 2026-11-05 · Minni AI

- [Claude Code memory: CLAUDE.md vs MinniMemoryMCP](https://minniai.com/learn/claude-code-memory-claude-md-vs-minnimemorymcp) What belongs in CLAUDE.md, and splitting the rest out by hand or with a tool.

Updated 2026-11-16 · Minni AI

- [MinniMemoryMCP vs Mem0, Zep, supermemory and Letta](https://minniai.com/learn/minnimemorymcp-vs-mem0-zep-supermemory-letta) Four tools add memory to an agent. MinniMemoryMCP cuts what the agent already loads. When each fits.

Updated 2026-11-16 · Minni AI

- [How Claude Code remembers across sessions](https://minniai.com/learn/claude-code-memory-across-sessions) What carries over between sessions, what does not, and how to keep it small.

Updated 2026-11-16 · Minni AI

- [Where Claude Code keeps its memory](https://minniai.com/learn/claude-code-memory-directory) Every memory path on your machine, what each file is for, and which ones load every turn.

Updated 2026-11-07 · Minni AI

- [How to run a coding agent on free, open models](https://minniai.com/learn/run-a-coding-agent-on-free-open-models) What a free key gets you, what a local model can do, and where the tokens go.

Updated 2026-10-25 · Minni AI

- [Get a free NVIDIA API key for a coding agent](https://minniai.com/learn/free-nvidia-api-key-for-a-coding-agent) Where the key comes from, where to keep it, and how to run a coding agent on it.

Updated 2026-11-07 · Minni AI

- [What a Windows PC optimization agent should and should not touch](https://minniai.com/learn/what-a-pc-optimization-agent-should-touch) The settings worth changing, the ones that are placebo, and the ones that break things.

Updated 2026-10-25 · Minni AI

---

Index for agents: https://minniai.com/llms.txt. Doing a task: https://minniai.com/agents.md
