Claude Code "Stream idle timeout - no chunks received" fix
Claude Code Stream idle timeout - no chunks received: a watchdog closed a stalled stream. Confirm in the debug log, raise CLAUDE_STREAM_IDLE_TIMEOUT_MS.
API Error: Stream idle timeout - no chunks receivedNo response events arrived on a streaming response for a while, so Claude Code's streaming idle watchdog closed the connection. The typical case in the official docs is a route through a gateway or proxy where only keep-alive pings flow while Claude thinks for a long time; the fix is to raise CLAUDE_STREAM_IDLE_TIMEOUT_MS.
When not even the response headers arrive, that is a different error (No response from API); see No response from API timeout. This post covers a response that stalls after it started.
[1] Tell whether this line ended the turn or something else did. When a stream stalls, Claude Code usually re-sends the request without streaming (the non-streaming fallback), and the phrase then appears only in the debug log, not on screen. The case the official docs describe for a turn ending with API Error: Stream idle timeout - no chunks received on screen is CLAUDE_CODE_DISABLE_NONSTREAMING_FALLBACK=1 turning that re-send off. The fix is the same either way.
[2] Confirm the cause in the debug log. Re-run the same task with a debug file, then search it.
$ claude --debug-file ./claude-debug.txt$ grep -n "Stream idle timeout" ./claude-debug.txtThe line the docs tell you to look for:
Error streaming, falling back to non-streaming mode: Stream idle timeout - no chunks receivedThe non-streaming re-sends that follow carry no pings, so they can hit the front proxy's timeout (240 seconds, for example) and produce a run of 504 errors. The proxy log splits into two shapes (per the Claude apps gateway deployment docs).
| Gateway upstream | What the proxy log shows |
|---|---|
An upstream other than provider: anthropic | One request open for about 12.5 minutes, then a run of 504s |
provider: anthropic as the model's only upstream | One request open for about 20 minutes, then 502s from the gateway (or 504s from your proxy if its timeout is shorter than the gateway's wait) |
[3] Get a sense of which timer fired. Claude Code runs four independent timers (defaults and scope per the official docs).
| Timer | Aborts when | Runs on · default |
|---|---|---|
| First-byte deadline | No response headers after the request | 180 s on the direct API, 300 s on Claude Platform on AWS (+1 s per 32KB of request). Does not run when ANTHROPIC_BASE_URL or similar routes through a gateway. On Bedrock only with CLAUDE_ENABLE_BYTE_WATCHDOG_BEDROCK=1 (300 s) |
| Event-level watchdog | No response events parse | Every provider · 300 s |
| Byte-level watchdog | No bytes at all, pings included | 180 s on the direct API; 300 s on Claude Platform on AWS, gateways and ANTHROPIC_BASE_URL. On Bedrock only with that variable set (300 s) |
| Body idle timeout | No bytes for 5 minutes, counting the wait for headers | Connections other than the direct API, Claude Platform on AWS and Bedrock with that variable set · 5 min. API_FORCE_IDLE_TIMEOUT=0 turns it off, 1 turns it on for every provider |
On Bedrock, setting CLAUDE_ENABLE_BYTE_WATCHDOG_BEDROCK=1 makes the byte-level watchdog replace the body idle timeout rather than run alongside it.
While only pings arrive, the byte-level watchdog keeps resetting but the event-level watchdog is extended only for a limited time. On a Claude apps gateway that pings every 15 seconds, a stream therefore ends after about 12.5 minutes at the default (the documented value for an upstream other than provider: anthropic; about 20 minutes with provider: anthropic as the only upstream).
[4] Raise CLAUDE_STREAM_IDLE_TIMEOUT_MS. It is the timeout in milliseconds for both the event-level and byte-level watchdogs; if you don't know your longest thinking pause, the docs suggest starting at 1800000 (30 minutes).
{"env": { "CLAUDE_STREAM_IDLE_TIMEOUT_MS": "1800000"}}| Value | Pings-only time a stream survives — upstream other than provider: anthropic | provider: anthropic as only upstream |
|---|---|---|
300000 (default) | About 12.5 minutes | About 20 minutes |
900000 | About 22.5 minutes | About 30 minutes |
1800000 | About 37.5 minutes | About 45 minutes |
Pick the value that covers your longest thinking pause (both columns come from the Claude apps gateway deployment docs).
Values below 300000 are silently raised to 300000, and the byte-level watchdog caps the value at 30 minutes. To change only the byte-level watchdog, use CLAUDE_BYTE_STREAM_IDLE_TIMEOUT_MS (10 seconds to 30 minutes, v2.1.210 or later).
[5] If your organization runs a Claude apps gateway, deliver the value through a gateway policy instead of personal settings. The docs' example is an env entry under a policy in managed.policies of gateway.yaml, and they suggest trying it on one group first.
[6] Check the proxy too. A proxy idle timeout longer than the gateway's keep-alive interval is enough (the docs note the ALB default of 60 seconds works), and raising only the proxy timeout does not fix this. The non-streaming re-send still fails once a reply takes longer than Claude Code's own wait, 300 seconds by default. If a session shows Streaming response ended before any complete data was received. Retrying without streaming., the proxy is consuming or rewriting the streaming body; configure it to pass streaming bodies and their headers through unmodified.