When To Start New Sessions & Making Sense Of Compaction

In the last lecture, you learned about the context window and that it has a limited size.

But what happens if you run out of space (i.e., the conversation gets too long - which can easily happen since code files evaluated or code generated by Claude Code also take up valuable tokens)?

In this case, Claude Code will compact the conversation: It will generate a summary of the conversation, including some instructions (for itself) on how to proceed once the compaction process is over. So it won't stop working or anything like that - BUT some details from the conversation will get lost.

You can also trigger compaction manually via the /compact command (e.g., if you know that you're about to ask for a task that will require lots of free space in the context window).

Since compaction WILL lead to loss of information, it's typically a good idea to keep sessions concise and focused. When working on a new feature, you want to use a new session (by starting a new Claude Code instance in a new terminal window, or via the /clear command).

The same is true when getting stuck: If Claude Code can't fix a certain bug or just won't implement a feature the way you want it to, it's often better to try again in a new session, with a cleared context window.