claude-code - 💡(How to fix) Fix Infinite retry loop when API times out during thinking phase [1 participants]

Official PRs (…)
ON THIS PAGE

Recommended Tools

×6

Utilities matched from this issue’s tags and category — try them while you read without losing context.

GitHub issue graph ai analysis

Paste a GitHub issue URL. We fetch that issue, discover linked issues from bodies/comments/timeline, collect linked pull requests, and produce a structured English report.

The report is written in English Markdown for sharing and archival.

Helpful · Quick feedback

Loading…
GitHub stats
anthropics/claude-code#48286Fetched 2026-04-16 07:04:05
View on GitHub
Comments
0
Participants
1
Timeline
4
Reactions
0
Author
Participants
Timeline (top)
labeled ×4

Claude Code enters an infinite retry loop when the API connection drops during the thinking/reasoning phase. The same user prompt is re-executed repeatedly with no retry limit.

Error Message

  • After max retries, show an error message to the user instead of silently looping

Root Cause

Claude Code enters an infinite retry loop when the API connection drops during the thinking/reasoning phase. The same user prompt is re-executed repeatedly with no retry limit.

Code Example

Claude Code v2.1.108
Opus 4.6 · Claude Pro
/Users/...

> [same prompt]

Web Search("AI model companies 2026...")
Found 10 results
Web Search("AI agents autonomous coding...")  
Did 1 search in 10s
Web Search("AI industry direction 2026...")
Did 1 search in 8s

Bloviating… (17s · ↓ 69 tokens · thinking)
────────────────────────────────────────
[repeats with full header again]
RAW_BUFFERClick to expand / collapse

Description

Claude Code enters an infinite retry loop when the API connection drops during the thinking/reasoning phase. The same user prompt is re-executed repeatedly with no retry limit.

Reproduction

  1. Send a prompt that triggers multiple parallel WebSearch calls + extended thinking (e.g., a research question requiring 3+ web searches)
  2. Model: Opus 4.6
  3. The API call completes the tool-use phase (WebSearch results return successfully) but disconnects during the "Bloviating..." (thinking) phase
  4. Claude Code automatically retries the entire API call from scratch
  5. This repeats indefinitely — in my case, 31 times before I manually interrupted with esc

Evidence

Each retry shows a full Claude Code header (version, model, working directory), confirming the client is restarting the API call, not resuming:

Screenshot

Claude Code v2.1.108
Opus 4.6 · Claude Pro
/Users/...

> [same prompt]

● Web Search("AI model companies 2026...")
  └ Found 10 results
● Web Search("AI agents autonomous coding...")  
  └ Did 1 search in 10s
● Web Search("AI industry direction 2026...")
  └ Did 1 search in 8s

✱ Bloviating… (17s · ↓ 69 tokens · thinking)
────────────────────────────────────────
[repeats with full header again]

Expected behavior

  • Retry with exponential backoff, capped at a reasonable max (e.g., 3-5 retries)
  • After max retries, show an error message to the user instead of silently looping
  • Ideally, resume from the last successful checkpoint (tool results already received) rather than replaying the entire turn

Environment

  • Claude Code: v2.1.108
  • Model: Opus 4.6 (claude-opus-4-6)
  • Plan: Claude Max
  • OS: macOS 24.6.0 (Darwin), Apple M4 Pro
  • No custom hooks or loops causing the retry — verified by inspecting all hook scripts and settings

Impact

  • Wastes significant API quota (31× the same 3 web searches + thinking)
  • Blocks the user from working until manually interrupted
  • No indication to the user that retries are happening — looks like duplicate responses in the same conversation

extent analysis

TL;DR

Implementing exponential backoff with a capped retry limit can help prevent the infinite retry loop when the API connection drops during the thinking/reasoning phase.

Guidance

  • Verify that the API connection drop is indeed the cause of the retry loop by checking the API logs for any errors or disconnections during the "Bloviating..." phase.
  • Consider implementing a retry mechanism with exponential backoff (e.g., 3-5 retries) to prevent infinite looping and reduce API quota waste.
  • To improve user experience, display an error message after the maximum number of retries, indicating that the operation failed due to a connection issue.
  • Investigate the possibility of resuming from the last successful checkpoint (tool results already received) instead of replaying the entire turn to minimize redundant work.

Example

No code snippet is provided as the issue does not imply a specific code fix, but rather a design or configuration change to the retry mechanism.

Notes

The solution may require modifications to the Claude Code API or the Opus 4.6 model to implement the suggested retry mechanism and error handling. Additionally, the exact implementation details may depend on the specific requirements and constraints of the system.

Recommendation

Apply a workaround by implementing exponential backoff with a capped retry limit, as this is likely to prevent the infinite retry loop and improve the overall user experience.

Vote matrix · Quick signals

Works
Did the solution work? Tap to confirm.
Easy Fix
Was it a quick fix?
Time Saver
Did it save you time?
Blocking
Was it severely blocking?
Common Issue
Are others likely hitting this too?
Flaky / Intermittent
Is it intermittent?
Verified / Reproducible
Can you reproduce it reliably?
Loading…

FAQ

Expected behavior

  • Retry with exponential backoff, capped at a reasonable max (e.g., 3-5 retries)
  • After max retries, show an error message to the user instead of silently looping
  • Ideally, resume from the last successful checkpoint (tool results already received) rather than replaying the entire turn

Still need to ship something?

×6

Another batch ranked right after the header list — different links, same matching logic.

Back to top recommendations

TRENDING