Context editing, compaction and memory
Three mechanisms, three different jobs. Expect a "which one" question.
4 min read · Lesson 4 of 9 in this domain
Three mechanisms manage long-running context and they are routinely confused, so anchor them by what they physically do. Context editing prunes: stale tool results are removed and not replaced. Compaction summarises: earlier turns are condensed into a summary block so the conversation can continue past the window. Memory persists: files written to a memory directory outlive the session entirely. The first two operate within one session; only memory crosses sessions. A scenario asking about state surviving a restart has exactly one answer.
- Context editing — prunes. Clears stale tool results and thinking blocks. The content is removed, not summarised.
- Compaction — summarises. When a conversation approaches the window limit, earlier context is condensed server-side.
- Memory — persists. State survives across separate sessions via files in a memory directory.
- Critical compaction implementation detail: append the full
response.contentback to your message history. The compaction blocks must be preserved — extracting only the text silently loses the compaction state. - Editing and compaction operate within a session; memory is across sessions. Many long-running agents use all three.
- None of these is
max_tokens, which is only a per-response output cap.
| Need | Mechanism |
|---|---|
| Remove stale tool results | Context editing (prunes) |
| Conversation will exceed the window | Compaction (summarises) |
| State must survive across sessions | Memory (persists) |
| Cap one response length | max_tokens |
Compaction and context editing are offered interchangeably. One summarises, one deletes.
Stale tool results are cluttering a long session. Which mechanism removes them?
Context editing prunes; compaction summarises.
State must survive across separate sessions. Which mechanism?
The first two operate within one session only.
Practise this domain with 15%%-weighted questions in the study app.
Open in study appSource: Claude Docs — Context editing · Independent study aid, not affiliated with or endorsed by Anthropic.