claude-code - 💡(How to fix) Fix claude --print hangs on Sonnet 4-6 at default/high effort with large prompts

Official PRs (…)
ON THIS PAGE

Recommended Tools

×6

Utilities matched from this issue’s tags and category — try them while you read without losing context.

GitHub issue graph ai analysis

Paste a GitHub issue URL. We fetch that issue, discover linked issues from bodies/comments/timeline, collect linked pull requests, and produce a structured English report.

The report is written in English Markdown for sharing and archival.

Helpful · Quick feedback

Loading…

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.

Error Message

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.

Root Cause

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.

Fix Action

Fix / Workaround

Workarounds

Code Example

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

---

[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 >>>
RAW_BUFFERClick to expand / collapse

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 curl to /v1/messages with claude-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 — curl with cache_control: ephemeral on the same prompt succeeds (73 s).
  • Session / hooks / tools — --bare reproduces the hang.
  • Inherited env vars (ANTHROPIC_DEFAULT_SONNET_MODEL=claude-sonnet-4-6 etc.) — 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 json and --output-format stream-json --verbose hang.

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/messages directly via curl or 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 --version2.1.142
  • cc_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 --bare which skips plugins).

Vote matrix · Quick signals

Works
Did the solution work? Tap to confirm.
Easy Fix
Was it a quick fix?
Time Saver
Did it save you time?
Blocking
Was it severely blocking?
Common Issue
Are others likely hitting this too?
Flaky / Intermittent
Is it intermittent?
Verified / Reproducible
Can you reproduce it reliably?
Loading…

Still need to ship something?

×6

Another batch ranked right after the header list — different links, same matching logic.

Back to top recommendations

TRENDING