Byte-level stream idle timeout detection #
API streaming responses are now monitored at the byte level for idle connections, catching stalled streams that the existing chunk-level timeout might miss.
- A new
StreamIdleTimeoutErrorclass andTransformStreamwrapper monitor the raw byte stream from the API. If no bytes arrive within the timeout window, the stream is aborted and retried. - The timeout is controlled by the existing
CLAUDE_STREAM_IDLE_TIMEOUT_MSenvironment variable (default: 90 seconds, minimum: 15 seconds). - This is layered on top of the pre-existing chunk-level idle timeout, providing defense-in-depth: the byte-level check catches low-level TCP stalls, while the chunk-level check handles higher-level protocol issues.
- Error reporting is now more granular — when a stream times out after receiving partial data, the error message distinguishes "Stream idle timeout - partial response received" from "Stream idle timeout - no chunks received", which should improve diagnostics.
- Only applies to first-party and Anthropic AWS streaming connections (SSE
text/event-streamresponses).
# Override the default 90s idle timeout (minimum 15s)
CLAUDE_STREAM_IDLE_TIMEOUT_MS=60000 claude
New StreamIdleTimeoutError class (search for "stream idle: no bytes for") and TransformStream wrapper in fetch middleware (search for "Streaming idle timeout (byte-level)")