Skip to content

API stream hangs mid-response on complex generation tasks (all models: Opus, Sonnet, Haiku) #19883

Closed as not planned

Description

@josh-argyle

Description

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

  1. Start a session with Opus 4.5 and extended thinking enabled
  2. Build up context (~60-80K tokens) through normal work
  3. Ask the agent to write a comprehensive document (e.g., "write the comprehensive cross-phase consistency review")
  4. Agent responds with thinking like "Let me write the comprehensive review document now"
  5. 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.

Activity

  1. github-actions commented on Jan 21, 2026

    @github-actions

    Found 3 possible duplicate issues:

    1. API Streaming Stalls Causing 59-138 Second Delays and Timeouts #18028
    2. [BUG] Opus 4.5 hangs 5-6+ minutes on first prompt in new repo when MCP memory check returns empty #15140
    3. [Bug] Anthropic API: Extended Thinking timeout without user feedback causing CLI hang #13294

    This issue will be automatically closed as a duplicate in 3 days.

    • If your issue is a duplicate, please close it and 👍 the existing issue instead
    • To prevent auto-closure, add a comment or 👎 this comment

    🤖 Generated with Claude Code

  2. josh-argyle commented on Jan 21, 2026

    @josh-argyle
    Author

    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:

    prev: "Opus 4.5 · Claude Max"
    next: "Sonnet 4.5 · Claude Max"
    

    Sonnet 4.5 exhibits the same behavior:

    • Stream starts, receives first chunk
    • Gets 3 output tokens
    • stop_reason: null
    • Then hangs indefinitely

    Additionally 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:

    • Session context corruption
    • Extended thinking configuration persisting across model switch
    • API-side issue affecting both models

    Updating title to reflect this affects multiple models.

  3. 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
  4. josh-argyle commented on Jan 21, 2026

    @josh-argyle
    Author

    Update 2: Also affects Haiku

    The issue also reproduces with Haiku (claude-haiku-4-5-20251001). Same behavior:

    • Stream starts
    • Few tokens received
    • Hangs mid-response

    This affects all three model families:

    • Opus 4.5
    • Sonnet 4.5
    • Haiku 4.5

    Not model-specific - appears to be an API-level or session-level issue.

  5. changed the title [-]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)[/+] on Jan 21, 2026
  6. josh-argyle commented on Jan 21, 2026

    @josh-argyle
    Author

    Additional Debug Information

    Error Pattern

    The actual error captured in debug logs:

    [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:

    20:20 - retry 1 (529ms delay)
    20:25 - retry 2 (1037ms)
    20:30 - retry 3 (2039ms)
    20:35 - retry 4 (4557ms)
    20:40 - retry 5 (9294ms)
    20:45 - retry 6 (16559ms)
    

    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

    1. Stream starts, receives 1-3 tokens
    2. "Request was aborted" error in non-streaming fallback
    3. Retries with exponential backoff (up to 10 retries)
    4. Each retry fails with same pattern
    5. Error details not captured (error: {})
    6. Affects all models (Opus, Sonnet, Haiku)
    7. Session becomes permanently stuck in retry loop
  7. josh-argyle commented on Jan 21, 2026

    @josh-argyle
    Author

    Update: Occurs with Extended Thinking OFF

    The issue also reproduces with extended thinking disabled. This rules out the MAX_THINKING_TOKENS off-by-one bug as the cause.

    Confirmed NOT related to:

    • Extended thinking settings
    • MAX_THINKING_TOKENS limit
    • Specific model (affects Opus, Sonnet, Haiku)

    The stream abortion happens regardless of thinking mode configuration.

  8. spm1001 commented on Feb 1, 2026

    @spm1001

    Additional Diagnostic Data (macOS)

    Reproducing the "stream hang at 0 tokens" issue on macOS with Claude Code 2.1.17.

    Environment

    • Claude Code version: 2.1.17
    • Model: claude-opus-4-5-20251101
    • OS: macOS 26.2 (Darwin 25.2.0)
    • Date: 2026-02-01

    Symptoms

    Same as OP: "Julienning" spinner with ↓ 0 tokens for 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:

    tcp4 172.17.12.178:52525<->160.79.104.10:443
    State:          ESTABLISHED
    bytes_in:       ~154KB (partial response)
    bytes_out:      ~1.1MB (request sent)
    re-tx:          25,983  ← CRITICAL: 25k+ retransmissions
    rx_dupe:        1,187
    rx_ooo:         271
    

    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

    1. Middlebox (firewall/proxy) interfering with long-lived HTTPS connections
    2. API server-side issue with response streaming
    3. TLS session corruption mid-stream
    4. 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

  9. github-actions commented on Mar 2, 2026

    @github-actions

    Closing for now — inactive for too long. Please open a new issue if this is still relevant.

  10. github-actions commented on Mar 10, 2026

    @github-actions

    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.

  11. locked as resolved and limited conversation to collaborators on Mar 10, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    area:apiarea:modelbugSomething isn't workinghas reproHas detailed reproduction stepsplatform:linuxIssue specifically occurs on LinuxstaleIssue is inactive

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions