claude -p returns empty result field despite model generating response
Description
When using claude -p (print mode), the result field in the output is always empty, even though the model successfully generates a response. This makes --output-format=text return blank output, breaking programmatic/scripted usage.
Version
- Claude Code v2.1.83 (latest as of 2025-03-25)
- macOS Darwin 25.3.0
Steps to Reproduce
# Returns empty string
claude -p "Reply with exactly: hello" --output-format=text < /dev/null
# JSON output shows result is empty despite successful completion
claude -p "Reply with exactly: hello" --output-format=json < /dev/null
# => {"type":"result","subtype":"success","is_error":false,"result":"","stop_reason":"end_turn",...,"output_tokens":5}
Expected Behavior
result field should contain the assistant's response text. --output-format=text should print the response.
Actual Behavior
resultfield is""(empty string)output_tokensshows tokens were generated (e.g., 5 or 13)stop_reasonis"end_turn"(normal completion)subtypeis"success"
Evidence from Streaming
Using --verbose --output-format=stream-json, the assistant message IS visible in the stream:
{"type":"assistant","message":{"content":[{"type":"text","text":"\n\nHello! How can I help you today?"}],...}}
But the final result event still has "result":"".
Impact
This breaks any workflow that relies on capturing claude -p output programmatically, such as:
- CI/CD pipelines using Claude for code review
- Scripts that pipe Claude output to other tools
- Multi-agent setups where one CLI invokes another
Workaround
Parse the streaming JSON output (--verbose --output-format=stream-json) and extract the assistant message text manually.
This issue has 5 comments on GitHub. Read the full discussion on GitHub ↗