Context Management
Context editing, compaction and memory as Claude API features: what each does to the conversation, and why the compaction block must be appended back verbatim.
Last updated
After this section you can
- Tell context editing, compaction and memory apart by what each one does to the conversation
- Wire up compaction without silently dropping its state by extracting only the response text
- Reason about what a context rewrite costs you in cache reads, and set thresholds from real runs
Context Management as an API Feature
Three mechanisms with three different jobs: clearing, summarising, and persisting. Picking the wrong one is how a long-running agent either forgets what it was doing or pays to re-read what it already knew.
A long agent run fills its window with material that has already done its job — tool outputs read once, thinking from twenty turns ago. Context editing deletes that material. Compaction replaces it with a summary. Memory writes it somewhere that outlives the session. They are not alternatives; most long-horizon agents use all three, at different timescales.