little cups of claude

tips and techniques for Claude and Claude Code

#14: Managing the Context Window 🪟

Today we'll look at how to keep an eye on (and make room in) the context window in Claude Code.

The context window holds everything Claude knows about our session: our instructions, the files it has read, its own replies, and some content that never shows up in the terminal. When it fills up, older details get summarized away, so it pays to know what's in there and how to steer it.

Let's take a look.

What Loads Before We Type

Before we've typed anything, a few things are already in context:

  • our CLAUDE.md files (or AGENTS.md)
  • auto memory
  • MCP tool names
  • skill descriptions

As we work, every file Claude reads adds more, and path-scoped rules load alongside the files they match. This is why a big pile of always-on skills or MCP servers costs us a bit on every single message.

Seeing What's In There

The /context command shows our live usage as a colored grid, broken down by category, with suggestions for things like heavy tools or memory bloat:

/context

It also lists which CLAUDE.md and auto memory files loaded. In fullscreen mode the per-item breakdown is collapsed, and passing all expands it:

/context all

To open and edit those memory files, there's /memory.

Compacting With A Focus

/compact replaces the conversation with a summary to free up space. Claude Code does this automatically as we approach the limit, but running it ourselves lets us say what matters:

/compact focus on the auth bug fix and the failing login tests

The summary keeps what we chose instead of what the automatic pass guesses is important. It's a good move right before starting a long new task.

For finer control, /rewind lets us pick a message and choose Summarize from here or Summarize up to here, compacting just part of the conversation.

What Survives Compaction

Not everything comes back the same way after a compaction:

  • The project-root CLAUDE.md, unscoped rules, and auto memory are re-injected from disk.
  • Up to five recently modified files Claude read or edited are re-read.
  • Invoked skill bodies come back, capped at 5,000 tokens per skill.
  • Rules with paths: frontmatter and nested CLAUDE.md files are summarized away, and reload only when Claude touches a matching file again.

That last one is the gotcha. If a rule has to stick around no matter what, we drop its paths: frontmatter or move it into the project-root CLAUDE.md. And since skill truncation keeps the start of the file, the most important instructions belong near the top of SKILL.md.

Clearing Between Tasks

When we switch to unrelated work, /clear starts a new conversation with empty context. Passing a name labels the old conversation so it's easy to find again:

/clear hal-login-refactor

That conversation is still there in the /resume picker. For a quick question that shouldn't add to the history at all, there's /btw:

/btw what's the difference between 401 and 403 again?

Large research jobs are another place to save room. Sending them to a subagent keeps all those file reads in its own context window, and only the summary comes back to ours. Neat!

Tuning Auto-Compaction

We can change how full the context window gets before the automatic pass runs with /autocompact:

/autocompact 500k

Claude Code saves the value to our user settings. Passing auto goes back to the window tuned for our model, and running it with no argument shows the current value.

More info about the context window can be found at the Claude Code docs.

Share

Share on Threads

Similar Cups