all guides

Context, explained by monkey

(the cheat sheet)

comment: COMPACT

The longer you chat with Claude, the fuller its context gets and the worse it works. Here's every command that helps, when Claude compacts by itself, and what survives a compact.

Claude's context window is everything it can hold in mind at once: your messages, the files it read, what its commands printed, your CLAUDE.md. It fills up fast, and the fuller it gets, the worse Claude works. It can start forgetting earlier instructions or making more mistakes. These commands keep it clean.

The cheat sheet

cheat sheet
/context                    see what's using space
/compact                    squash the chat into a summary
/compact focus on <topic>   ...and choose what it keeps
/clear                      new, empty chat (or /reset, /new)
/autocompact 500k           auto-compact sooner
/autocompact auto           back to the default
Esc Esc                     summarize just part of the chat
/btw <question>             side question, not added to the chat

/context: see what's eating the space

Type /context and you get a coloured grid of what's using space: your memory files, MCP tools, skills and so on. Check it when Claude starts slipping, or before a big task.

/compact: squash the chat

/compact replaces the conversation so far with a summary, so you keep going in the same chat with room to spare. On its own, the summary keeps what the automatic pass guesses is important. Add a focus and it keeps what you choose:

cheat sheet
/compact focus on the login changes

A good time to do it is right before you start a long new task. A focus that names what to keep and what to drop works well:

say this to Claude:
/compact focus on the login changes: keep the files we changed, the decisions we made and what's left to do. Drop the attempts that didn't work.

/clear: start fresh

/clear starts a new conversation with empty context. It also answers to /reset and /new. Your CLAUDE.md and auto memory load again, but the chat itself is gone.

  • Switching to unrelated work? Clear between tasks. The old conversation crowds out the files you need next and costs tokens on every message.
  • Corrected Claude more than twice on the same thing? The context is cluttered with failed attempts. Run /clear and start again with a more specific prompt that includes what you learned.

A fresh-start prompt that carries the lessons over:

say this to Claude:
We're starting over on [the task]. What we learned last time: [what went wrong, and what you now know]. Read [the files that matter] first, then tell me your plan before you change anything.

Compact just part of the chat

Press Esc twice with the message box empty, or type /rewind, and pick a message. Then choose Summarize from here or Summarize up to here. Only that part of the chat gets squashed.

When Claude compacts by itself

You don't have to do it all by hand. As the window gets close to full, Claude Code clears old tool output first, then summarizes the conversation if it still needs room. Your requests and key code snippets are kept, but detailed instructions from early in the chat can get lost. When it kicks in depends on your model:

  • Models with a native 1M window (Sonnet 5 and later, Opus 4.7 and later, Haiku 5.5 and the Fable models): at about 967K tokens.
  • Opus 4.6 and Sonnet 4.6 without the bigger window: at 200K tokens.

Want it to compact sooner? /autocompact 500k sets your own point, and /autocompact auto puts it back.

What survives a compact

  • Your project-root CLAUDE.md. It's read again from disk.
  • Auto memory.
  • Your plan from plan mode.
  • Up to 5 files Claude used recently.
  • Skills you've used, trimmed to their first 5,000 tokens.

Everything else gets summarized, and a rule you only typed in the chat can get lost. If you'll still need it next week, put it in CLAUDE.md, or just say "add this to CLAUDE.md".

Two ways to keep the chat small to begin with

  • /btw <question> asks a side question. It sees your whole context, but the question and answer aren't added to the conversation.
  • Hand big reads to a subagent. The files fill its context instead of yours, and only a summary comes back.

Good to know

  • Idle compaction: step away for about 54 minutes and a big conversation (200K tokens or more) can compact itself before its cache runs out. You'll see "Compacted while idle, before the prompt cache expired". To turn it off, set "idleCompaction": false in your settings.json.
  • Running /compact on an old session you've just resumed costs the most, because nothing is cached any more.
  • /clear also closes the Chrome tab group Claude opened.
Context windowthe official docs: compacting with a focus, clearing between tasks, and what survives a compactBest practiceswhy a full context makes Claude worse, and when to start fresh

Monkey believe in you. Now go build.

follow @nocodemonkey

More guides