Agent tool consistently fails with 'Failed to parse JSON' after empty stream response
Bug Description
Every call to the Agent tool (subagent) fails consistently with Failed to parse JSON. Regular API calls in the same conversation work fine. The issue is 100% reproducible — the Agent tool has never succeeded in this environment.
Environment
- Claude Code version: 2.1.63
- OS: Linux 6.8.0-88-generic (Ubuntu)
- Shell: bash
- Auth method: OAuth
Error Chain (from ~/.claude/debug/latest)
Every Agent tool invocation produces the exact same chain:
[ERROR] Stream completed without receiving message_start event - triggering non-streaming fallback
[ERROR] Error streaming, falling back to non-streaming mode: Stream ended without receiving any events
[ERROR] API error (attempt 1/11): Failed to parse JSON
[ERROR] Error in API request: Failed to parse JSON
[ERROR] SyntaxError: SyntaxError: Failed to parse JSON
at <parse> (:0)
at json (unknown)
at <anonymous> (/$bunfs/root/claude:272:650)
at hU$ (/$bunfs/root/claude:272:692)
at processTicksAndRejections (native:7:39)
Key Observations
- Streaming returns empty — The SSE stream closes immediately with no events (
message_startis never received) - Non-streaming fallback also fails — The fallback response cannot be parsed as JSON (likely empty body or HTML error page from a 4xx response)
attempt 1/11but no retry — The error is classified as non-retryable, suggesting the API returns a 4xx HTTP status- Only Agent tool is affected — All regular (non-subagent) API calls in the same session succeed normally
- Happens from the very first Agent call — Not related to context window growth; the first failure occurred at ~29,000 tokens (threshold: 167,000)
Suspected Cause
The Agent tool packages the full conversation context (including images) into the subagent request. This may produce a payload that triggers a 4xx rejection (e.g. 413 Request Too Large or a similar error), but the error response body is not valid JSON, causing Bun's json() parser to throw.
Workaround
Avoid using the Agent tool entirely. Use Bash, Grep, Glob, and Read tools directly instead — these work correctly.
Steps to Reproduce
- Start a conversation with Claude Code 2.1.63 on Linux
- Upload one or more images in the conversation
- Invoke the Agent tool (e.g.
subagent_type: "Explore") to explore the codebase - Observe the error
Additional Log Context
autocompact: tokens=29406 threshold=167000 effectiveWindow=180000
[DEBUG] [API:request] Creating client, ANTHROPIC_CUSTOM_HEADERS present: false, has Authorization header: false
[ERROR] Stream completed without receiving message_start event - triggering non-streaming fallback
[ERROR] Error in API request: Failed to parse JSONThis issue has 2 comments on GitHub. Read the full discussion on GitHub ↗