Module 1 · How agents remember · Lesson 2
The context window as working memory
How compaction, context editing and Claude Code's compaction rules decide what an agent still knows late in a long session, why every summary is a lossy write, and how to pin the facts that must survive.
By the end of this lesson you can
- Explain what threshold compaction, on-demand compaction and context editing each remove, keep and rewrite on the Claude API
- Predict what survives compaction in Claude Code, and move instructions that must persist out of the conversation
- Compute how the chance of a detail surviving falls with repeated compaction, and state the assumption behind the calculation
- Write a compaction instruction for a long-running agent that preserves the categories of fact later steps need
- Pin critical case state outside the summarised history so it is re-injected on every call