## Definition **Context editing** is a family of API-level techniques for managing a long agentic run's [[Context Window]] by selectively removing material that is no longer load-bearing. The two principal moves are *tool-result clearing* and *thinking-block clearing*. ## Tool-result clearing Agent runs accumulate bulky tool outputs: a 40 KB file dump, a directory listing, a verbose API response. Most of these matter only at the moment they return — the agent reads them, acts, and moves on. Tool-result clearing drops the old, fat outputs while keeping the *fact that the tool was called* and its conclusion. You shed the payload, not the history. ## Thinking-block clearing Extended reasoning produces spent thinking blocks ([[Extended Thinking]]). Once a reasoning step has been consumed to produce an action, the raw chain rarely needs to persist for the rest of the run. Thinking-block clearing removes that exhaust, reclaiming window for live work. ## Finer-grained than compaction [[Context Compaction]] summarizes a whole stretch of history into a compressed note — lossy, automatic, coarse. Context editing is surgical: *you* (or a policy) decide which specific blocks are safe to forget, and the rest is untouched. | | Context editing | Context compaction | |---|---|---| | Granularity | Per-block | Per-region | | Lossiness | Removes; nothing rewritten | Summarizes; rewrites | | Control | Explicit, targeted | Heuristic, sweeping | | Best for | Bulky tool noise | Long conversational drift | ## You choose what's safe to forget The discipline is judgment about durability. Some outputs are ephemeral (a grep result you already acted on); some are foundational (the spec, the user's goal, an error you must not repeat). Context editing rewards knowing the difference. Clearing the wrong block is how an agent "forgets" why it started a task mid-run. ## Interaction with caching Editing the window invalidates [[Prompt Caching]] from the edit point forward, since the cache keys on an exact prefix. The economics still favour editing on long runs — a smaller window per turn beats a perfectly cached but bloated one — but structure your edits so the stable prefix (system prompt, spec) survives untouched. ## Related - [[Context Window]] - [[Context Compaction]] - [[Context vs Memory]] - [[Prompt Caching]] - [[Extended Thinking]]