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
When the Anthropic streaming API sends SSE data: lines containing unescaped control characters (C0 range U+0000–U+001F), the @anthropic-ai/sdk streaming parser throws:
Bad control character in string literal in JSON at position N (line 1 column N+1)
This error is surfaced verbatim to the user as a message in the chat, with no retry or graceful recovery. The response is lost and marked stopReason: "error".
Steps to Reproduce
Use claude-opus-4-6 (streaming) in a coding-heavy session
Request code generation or file editing that may include control characters
Intermittently, a response will fail with the above error
Observed Behavior
User sees raw JSON parse error as a chat message
Response is lost (stopReason: "error")
Session recovers on the next user message (no persistent corruption)
Position in error varies (122, 131, 134, 156, etc.)
Expected Behavior
Either:
Retry the request automatically (the error is transient — next attempt usually succeeds)
Sanitize control characters from SSE data before JSON.parse() (defense-in-depth, since the upstream SDK should also fix this)
At minimum, show a user-friendly error like "Response interrupted, please try again" instead of the raw JSON parse error
Description
When the Anthropic streaming API sends SSE
data:lines containing unescaped control characters (C0 range U+0000–U+001F), the@anthropic-ai/sdkstreaming parser throws:This error is surfaced verbatim to the user as a message in the chat, with no retry or graceful recovery. The response is lost and marked
stopReason: "error".Steps to Reproduce
claude-opus-4-6(streaming) in a coding-heavy sessionObserved Behavior
stopReason: "error")Expected Behavior
Either:
JSON.parse()(defense-in-depth, since the upstream SDK should also fix this)Environment
Related