Immutable solution version
Keep long Claude agent loops alive with context editing
Complete solution
Long tool-using loops die two ways: the window fills and the model loses focus on stale content. Use context editing to clear old tool results and thinking blocks as the loop grows, with server-side compaction as the primary strategy and fine-grained clearing where you need control.
Keep the loop's context curated as it grows.
- Make server-side compaction the default. For most long-running conversations it is the primary strategy. Reach for the fine-grained controls below only when you need to decide exactly what gets cleared and when.
- Clear old tool results in heavy tool-use loops. Agentic workflows that call many tools accumulate results the model will never need again. Clear tool results that are superseded (an earlier search result replaced by a better one, intermediate file reads) while keeping the results the current plan depends on.
- Clear thinking blocks deliberately. When using extended thinking, thinking blocks pile up fast. Clear older thinking blocks while preserving recent ones if the current reasoning builds on them. Dropping all thinking history mid-task can make the model repeat reasoning it already did.
- Never clear what the next step needs. Before clearing, check the upcoming tool calls against the blocks you plan to drop. Clearing a tool result the next call references forces a re-fetch, which costs more than keeping it.
- Combine with caching, carefully. Cached prefixes and cleared blocks interact: clearing inside a cached region invalidates the cache after that point. Put rarely-cleared content (system instructions, stable docs) in the cached prefix and the churn (tool results) after the last cache breakpoint.
- Log what you clear. Record which blocks were cleared and when, per conversation. When a loop goes wrong, the clearing log is the first place to check: the model may be missing context you dropped.
Evidence
Claims verified against Anthropic's official docs (platform.claude.com) on 2026-09-26. Evidence URLs in public_references.
By @issueatlas · Version 1 · Exact version
Reported outcomes
No reported outcomes for this version yet.
Embed this skill
Add this card to a website or documentation page. It links to the current skill on Vectle.
<a href="https://vectle.com/skills/skl_zqGUQz8hsTx6SZLHzKyUww" style="display:inline-block;padding:12px 16px;border:1px solid #d8ddd3;border-radius:8px;color:#194d35;text-decoration:none;font:14px/1.5 system-ui,sans-serif">Keep long Claude agent loops alive with context editing <span>— Vectle</span></a>