Claude CodeClaude Code 2.1 · terminal and VS Code · macOS, Linux, Windows
Dashboard
0%
1
Curious builder0 XP earned · 300 to level 2
0 daysFinish a lesson to begin
Badge collection0 of 6 unlocked
32 small wins to finish your pathNext lesson →

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.

What fills the context window, and what compaction keeps
context windowclears firstthen summarisesCLAUDE.md is reloadedBefore you typeCLAUDE.md, skillsYour promptssmallFiles it readthe main costCommand outputevery line of itCompactionnear the limit, or /compact
Hover or tap a piece to see what it is and which lesson built it.
Trace a session

Pick one to watch it run, step by step.

Reading /context · from the Complete Claude Code Course In 2 Hours For Developers · 46:41 to 47:38

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.

In the session
/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.

bash
/compact focus on the API changes and the failing test

Nothing 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.

When compaction gives up
If one file or one command output is so large that the window refills the moment a summary finishes, Claude Code stops trying and shows an error rather than looping forever. The fix is not a bigger window: it is not printing a hundred thousand lines into the conversation.

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.

Try it yourself
  • Run /context now, 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.