Streaming SSE Event Parse Error — Fix (2026)

The Error

AnthropicError: Could not parse server-sent event: unexpected field 'X-Cache-Status' in event stream at position 847

This error occurs when a network intermediary (CDN, reverse proxy, or corporate firewall) injects HTTP headers into the SSE chunked transfer stream, corrupting the event format that the Anthropic SDK expects.

The Fix

  1. Bypass any local proxy for Anthropic API calls:
export NO_PROXY="api.anthropic.com,$NO_PROXY"
  1. If behind a corporate proxy, set the direct endpoint:
export HTTPS_PROXY=""
claude "test streaming"
  1. If using nginx as a reverse proxy, disable response buffering:
proxy_buffering off;
proxy_cache off;
proxy_set_header Connection '';
proxy_http_version 1.1;
chunked_transfer_encoding on;
  1. Restart Claude Code and test:
claude "count from 1 to 5 slowly"

Why This Happens

The Anthropic streaming API uses Server-Sent Events (SSE) over HTTP/1.1 chunked transfer encoding. Each chunk must follow the event: / data: format strictly. When a proxy or CDN buffers and re-chunks the response, it can inject its own headers or merge chunks, breaking the SSE parser in the SDK.

If That Doesn’t Work

  • Disable HTTP/2 multiplexing which some proxies force:
export ANTHROPIC_DISABLE_HTTP2=1
  • Test with curl to confirm the raw stream is clean:
curl -N https://api.anthropic.com/v1/messages \
  -H "x-api-key: $ANTHROPIC_API_KEY" \
  -H "anthropic-version: 2023-06-01" \
  -H "content-type: application/json" \
  -d '{"model":"claude-sonnet-4-20250514","max_tokens":50,"stream":true,"messages":[{"role":"user","content":"hi"}]}'
  • Upgrade the SDK to the latest version which has improved chunked parsing:
pip install --upgrade anthropic

Prevention

Add this to your CLAUDE.md:

# Streaming Configuration
- Do not route Anthropic API traffic through caching proxies or CDNs.
- Set NO_PROXY=api.anthropic.com in CI/CD environments.
- Always use proxy_buffering off when reverse-proxying SSE streams.

See Also

This fix also applies if you see these related error messages:

  • ECONNREFUSED: connection refused through proxy
  • Error: unable to verify the first certificate
  • SELF_SIGNED_CERT_IN_CHAIN
  • ECONNRESET: connection reset by peer
  • ECONNREFUSED: connection refused

Frequently Asked Questions

How do I configure Claude Code to use a corporate proxy?

Set the HTTPS_PROXY environment variable: export HTTPS_PROXY=http://proxy.corp.com:8080. Claude Code respects standard proxy environment variables. Add this to your shell profile for persistence.

Why does my proxy cause SSL errors?

Corporate proxies often perform TLS inspection by re-signing certificates with an internal CA. Node.js does not trust these CAs by default. Set NODE_EXTRA_CA_CERTS=/path/to/corporate-ca.pem to add your proxy’s CA certificate to the trust chain.

Can I bypass the proxy for Anthropic endpoints only?

Yes. Set NO_PROXY=api.anthropic.com to route Anthropic API traffic directly while keeping the proxy for other traffic. This avoids TLS inspection issues specific to the API connection.

Why does Claude Code lose connection during long operations?

Long-running operations can exceed keep-alive timeouts on intermediate proxies and load balancers. If a proxy closes an idle connection after 60 seconds and Claude Code’s request takes 90 seconds, the connection is severed before the response arrives.

Find the right skill → Browse 155+ skills in our Skill Finder.

Configure MCP → Build your server config with our MCP Config Generator.

Try it: Paste your error into our Error Diagnostic for an instant fix.

Step-by-Step Debugging Process

When you encounter pipe-related errors in Claude Code, follow this systematic debugging approach:

Step 1: Identify the failing command. Check the error output for the command that triggered the failure. The stack trace shows which process wrote to the closed pipe.

Step 2: Check command output size. Run the command alone (without piping) and check output size with wc -l. If the output exceeds 10,000 lines, it needs buffering or file redirection.

Step 3: Replace pipes with file intermediaries. Instead of command1 | command2, use command1 > /tmp/intermediate.txt && command2 < /tmp/intermediate.txt. This eliminates pipe buffer pressure entirely.

Step 4: Set appropriate timeouts. Long-running commands need matching timeout values. Check CLAUDE_CODE_BASH_TIMEOUT and ensure it exceeds the expected command duration by at least 50%.

Step 5: Verify the fix under load. Run the full workflow three times consecutively to confirm the error does not recur under typical conditions.

Common Scenarios That Trigger This Error

Large repository searches. Running grep -r or find across a repository with 50,000+ files produces output faster than the pipe consumer can process it. Use --max-count or -maxdepth to limit output volume.

Build output during CI. Build tools like webpack, tsc, and esbuild produce verbose output during compilation. If Claude Code’s process supervisor terminates the build mid-output, the pipe breaks. Redirect build output to a log file.

Streaming API responses. When Claude Code processes long streaming responses and the connection is interrupted (timeout, network drop), the write side of the stream receives EPIPE. Implement proper stream error handlers with .on('error', handler).

Parallel tool execution. Claude Code may run multiple bash commands simultaneously. If system pipe buffer capacity (typically 64KB on macOS, 65KB on Linux) is exhausted across all concurrent pipes, writes block and eventually fail.