Context Editing’s clear_tool_uses_20250919: A Full Parameter Table and When Each Default Kicks In

Two people carrying a paper shredder for disposal aboard a Navy ship

Context editing’s clear_tool_uses_20250919 strategy clears old tool results out of a Claude conversation once it crosses a token threshold you set, so a long agentic loop doesn’t keep paying to re-send tool output Claude no longer needs. It runs server-side, before your prompt reaches the model, and your own client keeps the full, unedited history the whole time. The table below lists every parameter the strategy accepts, straight from Anthropic’s documentation, because the defaults matter more than most teams assume before they’ve actually hit the threshold in production.

What gets cleared, and what’s left alone

By default, clear_tool_uses_20250919 only clears tool results — the data a tool returned. The original tool call (the parameters Claude sent) stays visible unless you explicitly set clear_tool_inputs to true. The oldest tool results go first, and each cleared result is swapped for placeholder text that tells Claude it was removed, not silently deleted from what Claude can see happened.

ParameterDefaultShapeWhat it controls
trigger100,000 input tokens{"type": "input_tokens", "value": N} or {"type": "tool_uses", "value": N}When clearing starts. You can trigger off a token count or a count of tool uses instead.
keep3 tool uses{"type": "tool_uses", "value": N}How many of the most recent tool use/result pairs stay untouched after a clear.
clear_at_leastNone{"type": "input_tokens", "value": N}A minimum number of tokens to free on each clear. If the API can’t clear at least that much, the strategy doesn’t run at all that turn.
exclude_toolsNonearray of tool namesTools whose uses and results are never cleared, no matter how old. Useful for a tool whose output Claude needs for the entire session.
clear_tool_inputsfalsebooleanWhen true, also clears the original tool call parameters, not just the result.

The minimal call uses every default at once: context_management={"edits": [{"type": "clear_tool_uses_20250919"}]}. That alone starts clearing once a conversation passes 100,000 input tokens, keeps the 3 most recent tool pairs, and leaves tool call parameters visible. Here’s the fuller version with every parameter set explicitly, requiring the context-management-2025-06-27 beta header:

response = client.beta.messages.create(
    model="claude-opus-5-5",
    max_tokens=4096,
    messages=[{"role": "user", "content": "Create a simple command line calculator app using Python"}],
    tools=[
        {"type": "text_editor_20250728", "name": "str_replace_based_edit_tool", "max_characters": 10000},
        {"type": "web_search_20250305", "name": "web_search", "max_uses": 3},
    ],
    betas=["context-management-2025-06-27"],
    context_management={
        "edits": [{
            "type": "clear_tool_uses_20250919",
            "trigger": {"type": "input_tokens", "value": 30000},
            "keep": {"type": "tool_uses", "value": 3},
            "clear_at_least": {"type": "input_tokens", "value": 5000},
            "exclude_tools": ["web_search"],
        }]
    },
)

Lowering trigger to 30,000 tokens here means clearing starts much earlier than the 100,000-token default — worth doing deliberately if your context window budget is tight, but not something to copy without checking it against your own model’s limits first.

What the response actually tells you

Every response that triggers a clear includes a context_management.applied_edits field reporting exactly what happened:

"context_management": {
  "applied_edits": [
    {"type": "clear_tool_uses_20250919", "cleared_tool_uses": 8, "cleared_input_tokens": 50000}
  ]
}

That’s the number to log if you’re debugging why a long-running agent’s behavior shifted mid-session — a sudden “I don’t have that information anymore” from Claude usually traces back to a clear you didn’t notice happened. The token-counting endpoint (client.beta.messages.count_tokens) also accepts context_management and returns both the post-editing input_tokens and the pre-editing context_management.original_input_tokens, which is the fastest way to check your trigger threshold against a real transcript before shipping it.

The prompt caching trade-off nobody puts in the first paragraph

Clearing invalidates cached prompt prefixes. Every clear is effectively a cache-write event, which costs more than a cache hit. Anthropic’s own guidance is to make each clear worthwhile by clearing enough tokens to justify that cache write, and to use clear_at_least to guarantee a minimum amount gets freed rather than triggering a cache invalidation for a token or two. If you’re already tuning prompt caching breakpoints for cost, context editing is the other half of that same budget — tune them together, not separately.

Combining it with the memory tool

Context editing on its own is lossy: once a tool result is cleared, it’s gone for good. Pair it with the memory tool (memory_20250818) and Claude gets an automatic warning as the clearing threshold approaches, giving it a chance to write the parts of a result worth keeping to a memory file before context editing removes it from the conversation — then retrieve that file later if the information matters again. Neither tool substitutes for the other: context editing manages what the model currently sees, memory manages what survives past that.

Rules and limits worth checking before you rely on this

  • The feature is in beta and requires the context-management-2025-06-27 beta header on every request that uses it — omit it and context_management is simply unavailable.
  • If you combine clear_tool_uses_20250919 with the separate clear_thinking_20251015 strategy, clear_thinking_20251015 must be listed first in the edits array, not the other way around.
  • It’s available across the Claude API, Claude on AWS Bedrock (including InvokeModel), Claude Models on Google Cloud, and Microsoft Foundry.
  • Edits are zero-data-retention eligible, but the feature itself is not currently HIPAA eligible — check that distinction separately before using it on a regulated workload.

Most teams reach for context editing after a long agent run throws a context-length error they didn’t see coming — the kind of failure covered from the error-handling side in our field guide to Claude API error codes. Reading the parameter table above before that happens is cheaper than debugging it after a client has already noticed Claude forgetting something it was told only a few tool calls earlier in the same run.

Compaction handles most cases; this is for the rest

Anthropic’s own documentation frames context editing as the second line of defense, not the first. For most use cases, the platform’s server-side compaction is meant to be the primary strategy for keeping a long conversation inside its context window — it runs automatically and needs no configuration from you. Context editing is positioned as the tool for scenarios that need finer-grained, more deliberate control over exactly what gets cleared and when: an agent that calls a handful of expensive tools repeatedly, where you specifically want to protect certain tool results (via exclude_tools) while aggressively discarding others, is the case compaction alone doesn’t give you a lever for. If you haven’t hit a context-length problem yet, start with compaction and reach for clear_tool_uses_20250919 only once you know which tool results you actually need to keep.

Protecting the memory tool’s own calls from being cleared

If you’re running the memory tool alongside context editing, there’s a subtle failure mode worth guarding against directly: letting clear_tool_uses_20250919 clear the memory tool’s own tool results. If Claude’s view call on a memory file gets cleared like any other tool result, Claude loses track of what it already wrote to disk and may re-create or duplicate a file it already has. Excluding the memory tool from clearing avoids that:

context_management={
    "edits": [{
        "type": "clear_tool_uses_20250919",
        "trigger": {"type": "input_tokens", "value": 50000},
        "keep": {"type": "tool_uses", "value": 5},
        "exclude_tools": ["memory"],
    }]
}

With memory in exclude_tools, every other tool’s old results still get cleared on schedule, but Claude’s own record of what it has already saved, renamed, or deleted stays intact for the whole conversation. That one line is cheap insurance against an agent that re-reads its own notes incorrectly because the read itself got erased from view.

A short FAQ

Does my application need to track which tool results were cleared? No. Context editing runs entirely server-side against the prompt Anthropic receives. Your own client keeps sending the full, unedited history on every request; the API applies the configured edits before the prompt reaches the model and reports what it did in applied_edits. You never have to reconstruct or resend a “cleared” version yourself.

Can I turn this on for one request and off for the next in the same conversation? Yes — context_management is a per-request parameter, not a setting tied to a conversation or session, so you can change trigger, keep, or drop the beta header entirely on any given call.

Logging cleared tokens like you’d log a cost metric

Because applied_edits arrives on every response where a clear happened, it’s cheap to log cleared_tool_uses and cleared_input_tokens alongside whatever you already track for token usage and cost per request. Summed across a session, that number tells you two different things depending on which way it points: a session that clears constantly is one where your trigger is probably set lower than the conversation actually needs, paying cache-invalidation costs for little benefit; a session that never triggers a clear at all but still errors out on context length means your threshold is too high relative to the model’s real window, and you found out the expensive way instead of from a log line. Treat the field as an early-warning signal, not just a debugging footnote you only check after something breaks.

None of this requires guessing. Run a handful of representative sessions through count_tokens with the context_management block you’re considering, compare original_input_tokens against the post-editing count, and you’ll know whether a given trigger and keep pair actually matches how your agent behaves before a single production conversation depends on it.

Photo: U.S. Navy photo by Mass Communication Specialist 3rd Class Timothy A. Hazel, public domain, via Wikimedia Commons.

Leave a Comment

Your email address will not be published. Required fields are marked *

Scroll to Top