Back to catalog / Agent context
Clear old tool results after processing
Keep recent results while removing re-fetchable payloads from long-running context.
Goal
Reduce repeated context cost from large tool outputs in long tool workflows.
Steps
- Confirm the target result is safely re-fetchable and is not a recent result needed for the current decision. [toolclear]
- Configure
context_management.editswithtype="clear_tool_uses_20250919", aninput_tokenstrigger, recenttool_usesto keep, andclear_at_least. [toolclear] - Inspect
context_management.applied_editsfor cleared calls and tokens freed; let the agent reread a tool if the original content is needed later. [toolclear]
How to verify
Compare token trajectories on a multi-turn synthetic file-read task; confirm tool-use pairing stays intact, recent results remain, and the final synthesis is correct.
Troubleshooting
If clearing does not trigger, check the beta header, model support, and trigger threshold; if an old result is needed, call its source tool again rather than assuming it can be restored.
Permissions
Prerequisites
- Python 3.11+, Anthropic SDK, a Claude API model supporting context management, and an API key.
Permissions
- Clear only re-fetchable test tool results from request context; do not mutate external tool data.
Limitations
Clearing removes old tool_result bodies; the model must call a tool again if needed. It is neither whole-history summarization nor persistent memory.
Pinned upstream source
- Repository
- anthropics/anthropic-cookbook
- File path
- tool_use/context_engineering/context_engineering_tools.ipynb
- Pinned commit
9c1e493ddd2b82df399d2a61b9c806c539e18be6- Source checked
- 2026-10-14 · Reviewed against the pinned upstream source
Repository metrics
These values describe the upstream repository, not popularity or likes for an individual skill or playbook.
- Stars
- Not collected
- Forks
- Not collected
- Observed at
- Not collected
No metrics snapshot is available yet.
License: MIT
Main topic
Take a coding Agent change from context to verification