You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
API stream hangs mid-response on complex generation tasks (all models: Opus, Sonnet, Haiku) #19883
Claude Code sessions using Opus 4.5 repeatedly hang mid-stream when attempting complex generation tasks (e.g., writing comprehensive review documents). The API connection remains established but no tokens are received after the initial few.
Environment
Claude Code version: 2.1.14
Model: claude-opus-4-5-20251101
OS: Linux (Debian)
Extended thinking: enabled (high)
Reproduction Steps
Start a session with Opus 4.5 and extended thinking enabled
Build up context (~60-80K tokens) through normal work
Ask the agent to write a comprehensive document (e.g., "write the comprehensive cross-phase consistency review")
Agent responds with thinking like "Let me write the comprehensive review document now"
Stream starts, receives 1-3 output tokens, then hangs indefinitely
Observed Behavior
From session 9b3cc295-c95a-4ca5-b79c-c969ff31b696:
{
"content": [{"type":"text","text":"Now I have all the information I need. Let me write the comprehensive cross-phase consistency review."}],
"stop_reason": null,
"output_tokens": 1
}
TCP connections remain ESTABLISHED to Anthropic servers
Debug logs show "Stream started - received first chunk" then nothing
Process stays in Running state but produces no output
No error messages or retry attempts
Happens repeatedly (261 user interruptions logged due to this pattern)
Debug Log Pattern
[DEBUG] Stream started - received first chunk
[DEBUG] Stream started - received first chunk
Then silence. No further log entries despite process remaining active.
Attempted Fixes
Set MAX_THINKING_TOKENS=63999 (no effect - this is not a token limit issue since stream DOES start)
The request initiates and streams partial text before hanging
Impact
Occurring daily for 3+ days
Affects almost every session involving complex generation tasks
Forces users to interrupt and retry repeatedly
Makes Opus 4.5 unusable for document generation tasks
Request
Please investigate why the API stream stalls mid-response when using Opus 4.5 with extended thinking on larger contexts.
Reacted by joelgrus-tektonic, adrnnapor, marko, plugin24-is-devang, Vít Koštejn and viky
changed the title [-]Opus 4.5 API stream hangs mid-response on complex generation tasks[/-][+]API stream hangs mid-response on complex generation tasks (Opus 4.5 and Sonnet 4.5)[/+]on Jan 21, 2026
[ERROR] Error in non-streaming fallback: Request was aborted.
[ERROR] Error: Error: Request was aborted.
at D (/$bunfs/root/claude:1028:26168)
at A4H (/$bunfs/root/claude:1028:26102)
Retry Escalation
The session shows exponential backoff retries, all failing:
For comparison, healthy connections to the same API endpoint in the same session show 0 retransmissions.
Network Path is Clean
Traceroute shows 8 hops with normal latency (~22ms), 0% packet loss on ping:
1 172.17.12.1 7ms
...
8 160.79.104.10 22ms
Process State
sample shows main thread blocked in kevent64 (78% of samples) - correctly waiting for network events that aren't arriving due to the degraded TCP state.
Theory
The high retransmission count suggests the TCP connection entered a degraded state mid-stream where packets are being lost or corrupted. The kernel keeps retrying, but the connection is effectively stalled. This would explain why:
Stream starts successfully (first chunk arrives)
Then hangs (subsequent data doesn't arrive/ack properly)
No error is raised (TCP stack thinks connection is still valid)
Eventually times out after TCP keepalive exhaustion
Possible Causes
Middlebox (firewall/proxy) interfering with long-lived HTTPS connections
API server-side issue with response streaming
TLS session corruption mid-stream
Connection idle timeout from network equipment
Reproduction Note
Multiple Claude Code sessions on same machine showed similar degradation pattern today (PID 82918: 25k retx, PID 34314: 10k retx). Fresh connections work fine.
Diagnostics collected while leaving the hung process running for analysis
This issue has been automatically locked since it was closed and has not had any activity for 7 days. If you're experiencing a similar issue, please file a new issue and reference this one if it's relevant.
Activity
github-actions commentedon Jan 21, 2026
Found 3 possible duplicate issues:
This issue will be automatically closed as a duplicate in 3 days.
🤖 Generated with Claude Code
josh-argyle commentedon Jan 21, 2026
Update: Also affects Sonnet 4.5
After switching from Opus 4.5 to Sonnet 4.5 in the same session, the identical problem occurs:
Debug log shows model switch:
Sonnet 4.5 exhibits the same behavior:
stop_reason: nullAdditionally seeing API errors with empty error objects:
{ "type": "system", "subtype": "api_error", "error": {}, "retryAttempt": 4, "maxRetries": 10 }The retries also fail with the same pattern.
Conclusion: This is not model-specific. Both Opus 4.5 and Sonnet 4.5 hang mid-stream on this session. The issue may be related to:
Updating title to reflect this affects multiple models.
[-]Opus 4.5 API stream hangs mid-response on complex generation tasks[/-][+]API stream hangs mid-response on complex generation tasks (Opus 4.5 and Sonnet 4.5)[/+]josh-argyle commentedon Jan 21, 2026
Update 2: Also affects Haiku
The issue also reproduces with Haiku (claude-haiku-4-5-20251001). Same behavior:
This affects all three model families:
Not model-specific - appears to be an API-level or session-level issue.
[-]API stream hangs mid-response on complex generation tasks (Opus 4.5 and Sonnet 4.5)[/-][+]API stream hangs mid-response on complex generation tasks (all models: Opus, Sonnet, Haiku)[/+]josh-argyle commentedon Jan 21, 2026
Additional Debug Information
Error Pattern
The actual error captured in debug logs:
Retry Escalation
The session shows exponential backoff retries, all failing:
Critical Issue: Empty Error Objects
All API errors are logged with
"error": {}- the actual error details are not being captured:{ "type": "system", "subtype": "api_error", "error": {}, "retryAttempt": 6, "maxRetries": 10 }This makes debugging nearly impossible. The error object should contain the actual API response/error code.
Summary
error: {})josh-argyle commentedon Jan 21, 2026
Update: Occurs with Extended Thinking OFF
The issue also reproduces with extended thinking disabled. This rules out the
MAX_THINKING_TOKENSoff-by-one bug as the cause.Confirmed NOT related to:
The stream abortion happens regardless of thinking mode configuration.
spm1001 commentedon Feb 1, 2026
Additional Diagnostic Data (macOS)
Reproducing the "stream hang at 0 tokens" issue on macOS with Claude Code 2.1.17.
Environment
Symptoms
Same as OP: "Julienning" spinner with
↓ 0 tokensfor 10+ minutes. User must ESC to interrupt.Key Finding: TCP Connection Degradation
Unlike issues where the stream simply stops, this case shows severe TCP-level packet loss on an established connection:
For comparison, healthy connections to the same API endpoint in the same session show 0 retransmissions.
Network Path is Clean
Traceroute shows 8 hops with normal latency (~22ms), 0% packet loss on ping:
Process State
sampleshows main thread blocked inkevent64(78% of samples) - correctly waiting for network events that aren't arriving due to the degraded TCP state.Theory
The high retransmission count suggests the TCP connection entered a degraded state mid-stream where packets are being lost or corrupted. The kernel keeps retrying, but the connection is effectively stalled. This would explain why:
Possible Causes
Reproduction Note
Multiple Claude Code sessions on same machine showed similar degradation pattern today (PID 82918: 25k retx, PID 34314: 10k retx). Fresh connections work fine.
Diagnostics collected while leaving the hung process running for analysis
github-actions commentedon Mar 2, 2026
Closing for now — inactive for too long. Please open a new issue if this is still relevant.
github-actions commentedon Mar 10, 2026
This issue has been automatically locked since it was closed and has not had any activity for 7 days. If you're experiencing a similar issue, please file a new issue and reference this one if it's relevant.