Context window and compaction
The context window is the fixed span of text Claude Code can hold in one session, and compaction is how it summarises older material once that span fills.
Last updated: 29 Sep, 2026 · Claude Code
Everything Claude knows in a session lives in that window, and what happens when it fills is the difference between a session that stays sharp and one that starts forgetting your instructions.
The window holds more than your conversation. It holds the system instructions, your CLAUDE.md, the notes it has saved for itself between sessions, which the memory lesson covers, the descriptions of every skill available, and then, growing all session, the files it read and the output of every command it ran.
Pick one to watch it run, step by step.
The video runs /context part way through a session. The grid names the model and its window, then shows what fills it: the system prompt, the system tools (about 15.5k tokens of a 1M window in that session), memory files, skills, the free space, and an autocompact buffer. It leaves the question of what happens when the window fills for later, and the rest of this lesson answers it.
/context shows what is using space right now. Run it once in a long session and the number that surprises you is the thing to fix. In VS Code the prompt box shows how full the window is all the time.What happens at the end
Claude Code compacts on its own as you approach the limit. It clears older tool output first, since that is bulky and rarely needed twice, and if that is not enough it summarises the conversation. Your requests and the important code survive. Detailed instructions from early on may not.
That last sentence is the practical one, and it has a fix that costs nothing: rules you need followed all session do not belong in the conversation at all. They belong in CLAUDE.md, which is reloaded rather than summarised. The CLAUDE.md lesson is that file.
Compacting manually
/compact summarises now rather than waiting, and it takes instructions.
/compact focus on the API changes and the failing testNothing is printed. The conversation is replaced by a summary written to that focus, and a marker appears in its place showing where the compressed messages were.
You can set the same steer permanently by adding a section headed Compact Instructions to your CLAUDE.md, and you can move the threshold itself with /autocompact.
Two other things keep the window small, and both have their own lessons. Skills load their full text only when used, so twenty skills cost you twenty descriptions rather than twenty documents. Subagents work in their own window entirely and hand back a summary, which is the subagents lesson.
Related
- Previous: Rewind and checkpoints
- Next: Interrupt and steer
- Reference: Claude Code docs
- Run
/contextnow, then read one large file and run it again. - Compact with a focus, then ask about something outside that focus and see what survived.
You understood something today that you didn't yesterday.