Blog · August 5, 2026 · 6 min read

Claude Code Context Management: Treat the Context Window Like a Budget

Most advice about Claude Code is about prompting: brief it well, plan first, be specific. All true. But after enough hours in the terminal, a different constraint starts dominating everything else, and almost nobody budgets for it deliberately: the context window.

Here's the opinion this whole piece hangs on: context is a budget, and most people spend it like it's free. Sessions rarely fail loudly. They degrade. Claude starts forgetting a decision from twenty minutes ago, re-reads files it already read, drifts from the conventions you agreed on. That's not the model getting dumber mid-session — it's a budget quietly running out, and everything you loaded "just in case" is what spent it.

You're spending tokens before you type anything

Claude Code's context window is 200,000 tokens by default (newer models can go higher), which sounds like more than anyone could need. But a surprising slice of it is gone before your first prompt. At session start, Claude loads the system prompt, your CLAUDE.md files at every level — user, project, and any nested ones — its own auto-memory notes, the tool definitions for every MCP server you've connected, and the descriptions of every skill you've installed.

None of these are individually large. Together they add up, and they're charged on every single session whether the task needs them or not. Run /context in a fresh session sometime and look at the breakdown before you've typed a word. That's your fixed overhead — your rent. Everything you actually do — reading files, running commands, iterating on a fix — comes out of what's left.

The practical consequence: every MCP server you connect "in case it's useful" and every paragraph you leave in CLAUDE.md because deleting feels risky is a recurring charge against every future session. Treat it that way.

The CLAUDE.md failure mode: it only ever grows

A briefing file is one of the first things worth setting up in Claude Code, and it stays the highest-leverage file in the repo. But CLAUDE.md files have a failure mode nobody warns you about: they grow monotonically. Every incident adds a rule. Every new teammate adds a section. Nothing ever gets removed, because nobody is sure which line is load-bearing.

The result is a file that reads like a wiki and performs like a tax. Worse, a bloated briefing doesn't just cost tokens — it dilutes itself. Twenty crisp rules get followed; two hundred paragraphs of mixed instruction, history, and trivia get skimmed. The file meant to make every session smarter is now making every session heavier and vaguer at the same time.

The fix is editorial, not technical. Treat CLAUDE.md like an API, not a wiki: small, stable, and versioned with intent. Keep only what applies to most sessions — build commands, hard constraints, the two or three conventions Claude genuinely gets wrong without help. Everything situational goes in separate docs that Claude can pull in on demand (imports with the @path syntax work well for this), so detail is available when a task needs it and costs nothing when it doesn't. And prune it on a schedule. A quarterly deletion pass does more for session quality than any prompt trick.

Auto memory: useful, but audit it

Newer Claude Code versions also keep notes of their own — an auto-memory file per project where Claude records things it figured out: build quirks, corrections you made, patterns that worked. This is genuinely useful, and it compounds nicely with a lean CLAUDE.md: you write the constitution, Claude keeps the field notes.

But it's still budget. Only the top of the memory file is loaded at startup — roughly the first couple hundred lines — so a memory file full of stale observations crowds out the notes that still matter. It deserves the same treatment as your briefing file: open it occasionally (the /memory command gets you there), delete what's obsolete, and promote anything universally true into CLAUDE.md proper.

Compaction is a tax, not a feature

When a session approaches the limit, Claude Code compacts — summarizing older conversation to free space. It's a good safety net. It is a terrible thing to rely on. A summary is lossy by definition: the exact error message from an hour ago, the reason you rejected an approach, the precise wording of a decision — some of that survives compaction and some doesn't, and you don't get to choose which.

So here's the second opinionated claim: if auto-compact fires regularly in your sessions, your sessions are scoped too big. The answer usually isn't a bigger window — it's smaller units of work. Finish a task, have Claude write down anything worth keeping, then /clear and start the next task fresh. A clean 200k window with a two-line handoff note beats a twice-compacted marathon session every time. For genuinely large jobs, subagents are the structural version of the same idea — exploration and research burn a subagent's context, and only the conclusion comes back to your main session.

The honest objection to task-sized sessions is that they create more idle moments — more times when Claude finishes a scoped chunk and waits for you to review, clear, and kick off the next one. If you're watching the terminal, that's friction. The fix is to stop watching: run sessions in parallel or go do something else, and let a notification tell you the moment one needs you.

What a lean setup actually looks like

If you want the checklist version of the argument:

  • Run /context once a week. You can't budget what you don't measure. If fixed overhead looks fat, find out which server or file is responsible.
  • Cap CLAUDE.md ruthlessly. Universal rules only; push situational detail into on-demand docs. Delete something every time you add something.
  • Disconnect idle MCP servers. Their tool definitions load every session. Connect the ones this project actually uses, not the ones you might use someday.
  • Prune auto memory monthly. Stale notes crowd out live ones at the top of the file.
  • Prefer /clear over compaction. End tasks deliberately with a short handoff note instead of letting summaries decide what survives.
  • Delegate research to subagents. Let exploration burn disposable context, not your main session's.

Budget, don't hoard

The instinct behind every bloated setup is the same: more context must mean a smarter agent. It's exactly backwards. The best Claude Code sessions are the ones where nearly all of the window is spent on the task in front of it — not on rules for situations that won't come up, tools that won't be called, and summaries of conversations that should have ended an hour ago. Spend deliberately, prune on a schedule, scope tasks to fit the window — and let AI Done Now handle the one part of a short-session workflow that used to be annoying: knowing the moment each session is done.

Keep reading