claude --print hangs on Sonnet 4-6 at default/high effort with large prompts
claude --print hangs on Sonnet 4-6 at default/high effort with large prompts
Version: Claude Code CLI 2.1.142 (also cc_version=2.1.142.433)
OS: macOS Darwin 25.3.0
Auth: API key via ANTHROPIC_BASE_URL proxy (proxy itself confirmed healthy)
Summary
When invoked with --print --model sonnet on a sufficiently large prompt (~30 KB+, ~10 K input tokens), the CLI's stream consumer hangs indefinitely after receiving the first chunk from the API. The model finishes generating (confirmed by raw HTTP calls returning a full response in ~80-170 s), but the CLI emits nothing to stdout and never exits on its own. Reducing thinking budget via --effort low makes the same call succeed; --model haiku on the identical prompt always works.
Reproducer
A ~36 KB user prompt is sufficient. Any large stage-1 clustering JSON works; the content isn't load-bearing.
export ANTHROPIC_BASE_URL=...
export ANTHROPIC_API_KEY=...
# Hangs indefinitely (kill required):
claude --print --model sonnet --output-format stream-json --verbose < large_prompt.txt
# Same prompt, succeeds in ~80s:
claude --print --model sonnet --effort low --output-format stream-json --verbose < large_prompt.txt
# Same prompt + Haiku, succeeds in ~90s:
claude --print --model haiku --output-format stream-json --verbose < large_prompt.txt
Effort flag is the load-bearing variable: --effort high (explicit) reproduces the same hang as the default.
Debug observations
With --debug --debug-file ./d.log:
[API REQUEST] /v1/messages source=sdk
[auto-mode] verifyAutoModeGateAccess: ... model=claude-sonnet-4-6 modelSupported=true ... canEnterAuto=true
Stream started - received first chunk
<<< 2-minute silence — no further debug output, no stdout >>>
<<< after manual SIGKILL: shutdown sequence runs cleanly, including BigQuery 401 errors >>>
The CLI's API client opens both proxy and direct-to-Anthropic connections (api.anthropic.com, 160.79.104.10). Same connection pattern is present during successful Haiku runs, so those connections themselves are not the issue.
Ruled out by experiment
- Proxy / network / model availability — raw
curlto/v1/messageswithclaude-sonnet-4-6+ same large prompt +thinking: {budget_tokens: 16000}streams cleanly and completes in ~170 s. - API key validity — same key works for Haiku via CLI and Sonnet via curl.
- Prompt cache headers —
curlwithcache_control: ephemeralon the same prompt succeeds (73 s). - Session / hooks / tools —
--barereproduces the hang. - Inherited env vars (
ANTHROPIC_DEFAULT_SONNET_MODEL=claude-sonnet-4-6etc.) —env -i(preserving only the proxy vars) reproduces the hang. - Fixture content — two different 32 KB fixtures both hang Sonnet, both work Haiku.
- Output format — both
--output-format jsonand--output-format stream-json --verbosehang.
Probable area
The CLI's stream-to-stdout consumer is the only remaining suspect. The API call succeeds (Stream started - received first chunk is logged), but the CLI's parser/formatter for stream-json output emits nothing further. The bug appears specifically when Sonnet's thinking response under default/high effort has both (a) substantial thinking_delta volume and (b) a signature_delta event for the encrypted thinking block. Haiku's thinking response — also signed — handles fine; suggests the difference is volume or rate, not the signature event per se.
Workarounds
--effort low— reduces thinking budget; call succeeds.- Bypass the CLI entirely and POST
/v1/messagesdirectly viacurlor any HTTP client. The proxy path works; this is what I shipped.
Impact
Blocks claude --print automation pipelines that use Sonnet for any non-trivial input. Silent failure mode (no error, no stdout, no debug output past "Stream started") makes the cause non-obvious — most operators will mis-attribute to the proxy / model / network before isolating the CLI.
Environment details
claude --version→2.1.142cc_version=2.1.142.433(from attribution header in debug log)- Auth: API key via proxy (
ANTHROPIC_BASE_URL), not OAuth. - Plugins enabled:
warp@claude-code-warp(also reproduces with--barewhich skips plugins).
This issue has 2 comments on GitHub. Read the full discussion on GitHub ↗