{"slug": "what-context-editing-actually-clears-and-what-it-costs", "title": "What Context Editing Actually Clears, and What It Costs", "summary": "Anthropic shipped context editing as a beta feature in the Claude API, letting developers have the server delete the oldest tool call and result pairs from a prompt once it crosses a default threshold of 100,000 input tokens, replacing each with a short placeholder while keeping the three most recent pairs intact. The feature is enabled with the beta header context-management-2025-06-27 and a context_management request object, which exposes four parameters — trigger, keep, exclude_tools and clear_at_least — plus a separate clear_thinking_20251015 strategy for extended thinking blocks that takes a turn count or the string \"all\". Anthropic's announcement cites three figures from an internal evaluation of complex, multi-step agentic search tasks, though the source text truncates before stating them.", "body_md": "Let an agent run free with a web search tool for a hundred turns and something predictable happens: the context window fills with old search results long before the task is finished. Anthropic built a fix for exactly that failure mode into the Claude API, and it ships today as a beta feature called context editing [1].\n\n**In this article:**\n\nA single tool call doesn’t cost much context on its own. The problem is that nothing about a tool call shrinks once it lands in the transcript. The call stays, the result stays, and on turn eighty you’re still paying to re-read a page you scraped on turn twelve. For an agent doing research, coding, or anything with a long tool-use loop, that accumulation is usually the actual ceiling, not the model’s reasoning ability. It’s a more mechanical version of the drift and bloat problem covered in [Context engineering: drift, bloat, and the lost-in-the-middle problem](https://medium.com/towards-artificial-intelligence/context-engineering-drift-bloat-and-lost-attention-210b692fad4c): the window has room, technically, but most of what’s in it is dead weight from three tasks ago.\n\nAnthropic’s answer isn’t a bigger window. It’s a server-side setting that watches the prompt as it grows and deletes specific pieces of it on your behalf, before the request ever reaches the model [1]. You turn it on with a beta header, context-management-2025-06-27, and a context_management object in the request body. The model never finds out anything was removed unless you tell it; your client keeps the full, unedited history and doesn't need to track what got cleared on the server's end.\n\nThe main strategy is named for what it does: it clears tool uses, specifically the oldest ones, once the prompt crosses a size threshold. By default that threshold is 100,000 input tokens, and once it’s crossed, the API starts removing the earliest tool call and result pairs, replacing each one with a short placeholder that tells Claude the content was cleared [1]. The three most recent tool use and result pairs stay untouched by default, so the agent never loses the thing it just did, only the things it did a while ago.\n\nFour parameters give you control over that behavior. trigger sets the threshold and can be measured in input tokens or raw tool-use count instead of the 100k default. keep sets how many recent pairs survive a clearing pass, three by default. exclude_tools lets you name tools whose calls are never touched, useful for something like a memory write you never want silently deleted. And clear_at_least sets a minimum number of tokens that must actually be freed for the clearing to happen at all, which matters more than it sounds like, because clearing isn't free. More on that below.\n\nTool results aren’t the only thing that piles up. Extended thinking blocks from earlier turns do too, and Anthropic gives them a dedicated strategy, clear_thinking_20251015, rather than folding them into the tool-use cleaner [1]. The logic is that thinking and tool results decay differently: a model might genuinely benefit from seeing its own earlier reasoning on a long task, where a stale tool result from turn twelve rarely helps anyone.\n\nThe only setting is keep, and it takes either a turn count or the string \"all\". Set a turn count and the API keeps thinking blocks from that many of the most recent assistant turns, counting the turn currently in progress. Set \"all\" and nothing gets cleared, which is also what several newer model families default to even without this strategy turned on at all, according to the current docs [1]. If you're mixing older and newer models in the same codebase, that default difference is worth checking before you assume your thinking blocks are being handled one particular way.\n\nAnthropic’s own announcement gives three figures, and it’s worth being precise about what each one actually measured. On an internal evaluation set it describes as complex, multi-step agentic search tasks, context editing alone produced a 29% improvement over an unedited baseline. Pairing context editing with the memory tool, so Claude can write important findings to a file before old tool results get cleared, pushed that improvement to 39% on the same evaluation [2]. In a separate hundred-turn web search test, context editing cut total token consumption by 84% and let the agent finish workflows that would otherwise have failed outright from running out of context [2].\n\nThose numbers are real, but they’re Anthropic’s own internal benchmark, and the announcement doesn’t publish the baseline task set, the model used, or a methodology write-up alongside them [2]. That’s not a reason to dismiss the figures. It’s a reason not to treat an 84% reduction as something you’ll see on your own workload without measuring it yourself first. The mechanism is sound and well documented; the specific percentage is a vendor claim about one internal test, not a guarantee.\n\nHere’s the part that’s easy to miss if you only read the feature description and not the caching section: every time the tool-use clearer actually removes content, it invalidates whatever prompt cache prefix existed up to that point [1]. You pay a fresh cache write on the next request, the same way you would after any other edit to earlier turns. That’s exactly the mechanism covered in [Prompt caching and token budgeting: what’s documented vs. exam-tested](https://medium.com/gitconnected/prompt-caching-whats-documented-not-exam-tested-b5bc330002e2), and it’s why clear_at_least exists: it's a way to tell the API not to bother clearing unless the clear is big enough to be worth breaking the cache over.\n\nClearing thinking blocks works the opposite way. Keeping them preserves your cache and keeps the cost benefit of cache hits; clearing them invalidates the cache from that point forward, same as the tool-use strategy [1]. So the actual decision isn’t “turn context editing on or off.” It’s where you set trigger and keep relative to how much you rely on cache hits to keep your [per-turn costs](https://medium.com/towards-artificial-intelligence/why-your-agent-loop-costs-more-than-its-model-price-tag-81a48b691df5) down versus how much headroom your agent actually needs to finish a long task without truncation errors.\n\nFor a short-lived agent that rarely crosses a few thousand tokens of tool output, none of this matters much, and raising max_tokens or just picking a model with a larger window is simpler. For something that runs long, tool-heavy loops, research agents, coding agents working across a big repo, customer support agents with deep tool access, context editing is solving a problem that a bigger context window alone doesn't fix: the model still has to read everything in that window on every turn, and most of what accumulates in a long tool-use session isn't worth re-reading. Pair it with the memory tool, as covered in [The Three Layers of Memory in the Claude Agent SDK](https://medium.com/gitconnected/the-three-layers-of-memory-in-the-claude-agent-sdk-d1c5437a9451), and Claude gets a chance to write down what matters before the clearer takes the rest away.\n\nIf you enjoyed the article and wish to show your support, make sure to:\n\n[What Context Editing Actually Clears, and What It Costs](https://pub.towardsai.net/what-context-editing-actually-clears-and-what-it-costs-53f580a7e62e) was originally published in [Towards AI](https://pub.towardsai.net) on Medium, where people are continuing the conversation by highlighting and responding to this story.", "url": "https://wpnews.pro/news/what-context-editing-actually-clears-and-what-it-costs", "canonical_source": "https://pub.towardsai.net/what-context-editing-actually-clears-and-what-it-costs-53f580a7e62e?source=rss----98111c9905da---4", "published_at": "2026-11-17 15:01:02+00:00", "updated_at": "2026-11-17 20:08:19.302320+00:00", "lang": "en", "topics": ["artificial-intelligence", "ai-agents", "large-language-models", "ai-tools", "developer-tools"], "entities": ["Anthropic", "Claude API", "context editing", "context-management-2025-06-27", "clear_thinking_20251015"], "also_reported_by": [], "alternates": {"html": "https://wpnews.pro/news/what-context-editing-actually-clears-and-what-it-costs", "markdown": "https://wpnews.pro/news/what-context-editing-actually-clears-and-what-it-costs.md", "text": "https://wpnews.pro/news/what-context-editing-actually-clears-and-what-it-costs.txt", "jsonld": "https://wpnews.pro/news/what-context-editing-actually-clears-and-what-it-costs.jsonld"}}