[BUG] `--print` mode returns empty output when API proxy returns content types in separate assistant messages
claude -p returns empty output when using an OpenRouter-compatible API proxy as ANTHROPIC_BASE_URL. The proxy returns thinking/text/redacted_thinking as separate assistant messages instead of a single combined message.
Everything else works — interactive mode, streaming, --output-format stream-json all return correct responses. Only the final result extraction in --print text mode is affected.
Cause
The result extraction picks the last assistant message:
messages.findLast(m => m.type === "assistant" || m.type === "user")
When a proxy splits content into separate messages, the last one is redacted_thinking (no text) → empty result.
Fix
Find the last assistant message that has a text block:
messages.findLast(m =>
(m.type === "assistant" && m.message?.content?.some(b => b.type === "text"))
|| m.type === "user"
)
I've tested this on both the latest Bun SEA binary and the npm-installed version (v2.1.86). Patched the minified cli.js and confirmed it works — no regressions.
Patch script: https://gist.github.com/PawiX25/181b0839b77c1463a8884b57085472b1
This issue has 4 comments on GitHub. Read the full discussion on GitHub ↗