You set a rule an hour ago and Claude followed it for a while. Now it doesn't. Usually the session has run long enough for that rule to be summarised away, and once you know how that happens you know which command to reach for.
What the context window holds
The context window is everything Claude can see in this session. That includes your messages and its replies, every file it has read, every command output, your CLAUDE.md files, auto memory, skill descriptions, MCP tool names and the system instructions Claude Code adds itself.
Claude has no other memory of the session. Claude Code sends the whole conversation with every request, so whatever is in the window is all Claude knows. A new session starts with an empty window apart from what loads from memory files.
The window fills fast in real work. A few large files, a long test run and some back and forth can take up a big share of it.
Why it seems to forget
As the window nears its limit, Claude Code compacts the conversation without being asked. It replaces the history with a summary so the session can carry on.
The summary keeps your requests and the main code snippets, but the docs warn that detailed instructions from early in the conversation may be lost. A rule you typed in message three is now one line in a summary, or gone, and that is the forgetting you notice.
Some things come back after a compaction because Claude Code re-reads them from disk. The project-root CLAUDE.md is one of them. The memory guide covers what survives and how to write those files. If an instruction has to last the whole session, put it in CLAUDE.md instead of typing it in chat.
/context: see what is using space
Run it before you decide anything else:
/contextIt draws your current usage as a coloured grid, broken down by category, with suggestions for context-heavy tools, memory files that have grown too large and warnings as you near capacity. It also lists which CLAUDE.md and auto memory files loaded. Add all to expand the per-item breakdown.
If one category is far bigger than you expected, such as MCP tools or a huge memory file, fix that at the source. Compacting won't help with something that loads on every turn.
/compact: summarise now, on your terms
/compact does by hand what auto-compaction does on its own: it summarises the conversation so far and frees space. The difference is timing and focus. You choose a natural break, and you can tell it what to keep:
/compact focus on the auth bug fix and the failing test namesThe summary then keeps what you named instead of what the automatic pass guesses matters. Good moments to compact are after exploration and before implementation, or when one phase of a task is done and the next will need the space.
You can also set standing instructions for every compaction in the project's CLAUDE.md:
# Compact instructions
When you are using compact, focus on test output and code changes.Compacting isn't free. It reads the whole conversation to summarise it, so compacting a very full context is itself a large request.
/clear: start again with an empty conversation
/clear starts a new conversation with empty context. Your memory files still load, so Claude knows your project, but none of the previous conversation comes with it. The docs list /reset and /new as aliases.
Use it when you switch to unrelated work. Old conversation about a different task crowds out what you need next and adds tokens to every message. Unlike /compact, clearing costs nothing.
You don't lose the old conversation. Pass a name, as in /clear auth-spike, to label it in the /resume picker, then use /resume to go back to it later.
Which one to use
| Situation | Command |
|---|---|
| Claude seems to be ignoring something you said earlier | /context first, to see what is in there |
| Same task, long session, about to start a new phase | /compact with a focus |
| Switching to unrelated work | /clear |
| Large research job that would fill your window | Hand it to a subagent, which works in its own context and returns a summary |
Two more commands help once you know these. /autocompact sets how full the window gets before automatic compaction runs, and /rewind can summarise part of the conversation instead of all of it.
How I handle it
My global rules include a short section on context. It says to avoid the last 20% of the context window for large refactors, features that span several files and debugging complex interactions. Single-file edits, documentation and simple bug fixes are fine to finish late in a session.
I also run a SessionStart hook that reacts to compaction. Claude Code fires SessionStart again after a compaction with the source compact. My script checks for that source, and on a compact or a resume it injects the corrections I already gave in that session, up to eight of them, so a correction I made early on survives the summary.
You can do the simple version with the pattern from the hooks docs. Add this to .claude/settings.json and edit the message:
{
"hooks": {
"SessionStart": [
{
"matcher": "compact",
"hooks": [
{
"type": "command",
"command": "echo 'Reminder: use Bun, not npm. Run bun test before committing.'"
}
]
}
]
}
}Anything the command prints to stdout is added to Claude's context after each compaction. Swap the echo for git log --oneline -5 and Claude gets your recent commits back too. The hooks guide explains how hooks are set up.
Questions
Does /clear delete my conversation?
No. It starts a new, empty conversation and keeps the old one. Name it with /clear <name> and get back to it with /resume.
What's the difference between /compact and /clear?
/compact keeps the same conversation going as a summary, which suits a long task you want to continue. /clear drops the conversation from context altogether, which suits switching to unrelated work. Both leave your CLAUDE.md files in place.
Can I stop Claude Code from compacting automatically?
Yes. Turn off Auto-compact in /config, which sets autoCompactEnabled to false, and /compact still works by hand. Before you do, try /autocompact with a size, such as /autocompact 500k, to change when it runs instead. With auto-compact off, a full window stops the session with Context limit reached · /compact or /clear to continue.