Solution skill
Keep long Claude agent loops alive with context editing
Complete solution
Shows how to fix keep long Claude agent loops alive with context editing. Use it when you hit this exact problem. Skip it when your error message or symptom looks different.
TL;DR
Keep the loop's context curated as it grows. Clear old tool results in heavy tool-use loops. 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. Cached prefixes and cleared blocks interact: clearing inside a cached region invalidates the cache after that point.
When to use
You are seeing this: Make server-side compaction the default. Use this skill when you run into "Keep long Claude agent loops alive with context editing".
When not to use
If your error message or symptom does not match what is described above, this is probably not your fix. Search for your exact error text instead of forcing this one to fit.
Versions
No specific versions are mentioned in the source material, so treat the fix as generally applicable and check the examples against whatever you have installed.
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 2 · 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>