Skip to content

Definition

A beta API capability that automatically clears the oldest tool results from the context window during long agent runs, replacing each with placeholder text so Claude knows content was removed — the API-level form of "tool result clearing."

Key points

  • Beta header: anthropic-beta: context-management-2025-06-27.
  • Strategy type: clear_tool_uses_20250919, passed via context_management={"edits":[{"type":"clear_tool_uses_20250919", ...}]}.
  • Available on all supported Claude models.
  • Behavior: clears the oldest tool results in chronological order and replaces each cleared result with placeholder text. Only tool results cleared by default; tool calls preserved unless clear_tool_inputs: true.
  • Config parameters (defaults):
    • trigger — default 100,000 input tokens; when clearing activates. {"type":"input_tokens","value":N} or {"type":"tool_uses","value":N}.
    • keep — default 3 tool uses to preserve. {"type":"tool_uses","value":N}.
    • clear_at_least — default None; min tokens to clear; if the API can't clear this amount the strategy won't apply.
    • exclude_tools — default None; tool names never cleared, e.g. ["web_search"].
    • clear_tool_inputs — default false; true clears both results AND tool call parameters.
  • Response: context_management.applied_edits[] with {"type":"clear_tool_uses_20250919","cleared_tool_uses":N,"cleared_input_tokens":N} (in the final message_delta when streaming).
  • count_tokens supports it: returns input_tokens (after clearing) + context_management.original_input_tokens (before).

Why it matters for the exam

  • The concrete API mechanism for keeping long tool-heavy agent runs under the window. Expect exact params — remember trigger 100k default and keep last 3 default.

Common gotchas

  • Clearing invalidates cached prompt prefixes — set clear_at_least so each clear removes enough tokens to justify the cache write cost.
  • By default only tool results are cleared; tool inputs stay unless you set clear_tool_inputs: true.
  • Pairs with the Memory Tool: as context nears the threshold, Claude gets an automatic warning to write important info to memory before results are cleared.

See also

Sources