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
- Choose between context editing, compaction and memory for a long-running agent
- Wire up compaction without losing its block, and read its cost from usage.iterations
- Explain why trimming history yourself breaks the newest models, and what replaces it
Context Management: Clear, Compact, Persist
Three API features with three jobs: clearing finished material, summarising a conversation that will not fit, and keeping what must outlive it. On the newest models they are also the only safe way to shrink history.
Long agent runs fill the window with material that has done its job. Context editing clears it, compaction summarises it, memory writes it somewhere that outlives the session. The first two run on the server, so your history stays append-only, which the newest models now require.