Claude Agent Stuck in Infinite Tool Call Loop
Your agent keeps calling the same tool with the same or nearly-same inputs, burning tokens without progress. Common when tool returns errors Claude misinterprets, when Claude hallucinates a tool, or when tool feedback is ambiguous. Prevent with iteration caps and duplicate-call detection.
Fingerprint every tool call as (name, hash(input)). If the same fingerprint appears 3+ times, inject a system message telling Claude the loop is detected. Also enforce a max iteration cap (10-20 turns typical), timeout the whole run, and log each fingerprint for post-mortem debugging.
The Symptoms You're Seeing
Turn 1: tool_use search_docs("payment refund")
Turn 2: tool_use search_docs("payment refund") ← same call
Turn 3: tool_use search_docs("payment refund") ← same call
Turn 4: tool_use search_docs("payment refund") ← infinite
Or: input drift while going nowhere
Turn 1: tool_use calc(x + y)
Turn 2: tool_use calc(x + y + 0)
Turn 3: tool_use calc(x + y + 0.0)
Turn 4: tool_use calc((x + y))
Symptoms:
- Token spend spikes without task completion
- Agent runs hit iteration cap
- User complaints: "it just keeps searching"
- Same tool_use_id patterns in logs
- Cost anomaly alerts firing
What Actually Causes Loops
Fixes That Work (Tested Nov 2026)
1Fingerprint-Based Loop Detection
2Hard Iteration Cap + Timeout
Typical caps: 10 for simple lookup, 20 for research, 50 for complex multi-tool workflows. Above 50, question whether Claude is really progressing or just churning. Log final iteration count; adjust caps based on real workload data.
3Improve Tool Feedback Quality
Preventing Loops Going Forward
- Fingerprint tool calls. Detect repeats in a sliding window.
- Cap iterations, wall time, and token budget. Three independent bounds.
- Design tool results to be actionable. Never return empty strings; explain what to try next.
- Log every fingerprint for post-mortem. Identify loop-prone tools.
- Add a "give up" tool. Let Claude call
report_stuck(reason)gracefully. - Monitor cost per agent run. Alert on outliers > 3× baseline.
Researcher · AI Error Hub
Frequently Asked Questions
Yes, and give it explicit permission. Add a report_stuck or give_up_gracefully tool. Tell Claude in the system prompt: "If you've tried and can't make progress, call report_stuck with your reasoning." Better than silent looping.
Thinking often HELPS avoid loops by letting Claude reflect on prior attempts. But if broken feedback confuses reasoning, thinking amplifies the loop. Monitor loop rates with/without thinking enabled.
Anthropic won't stop your agent from looping — it's your responsibility. Anthropic charges for tokens generated regardless. You must implement client-side limits. Consider budget alerts in the console.
Cache reduces cost per turn but doesn't stop looping. It's independent of loop detection. Some teams see loops WORSE with cache because per-request cost is lower, so cost signals fire later.
Task-dependent. Simple lookup: $0.01-0.05. Research task: $0.10-1.00. Multi-hour analysis: $1-10. Set alerts at 3× your P95 baseline. Runs over the alert threshold get inspected for loops.
Related Errors
Build Robust Agents That Don't Loop
Weekly deep dives on agent architecture, loop detection, and cost controls. 12,000+ developers subscribe.
Subscribe Free →