claude -p returns empty result field despite model generating response
Status Fixed / completed
Maintainer reply ✓ Yes — ashwin-ant
Workaround ✓ Mentioned in thread ↓
Activity 5 comments · opened Mar 25, 2026 · closed Apr 19, 2026
💡 Likely answer: A maintainer (ashwin-ant, collaborator)
responded on this thread — see the highlighted reply below.
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.
5 Comments
Found 3 possible duplicate issues:
This issue will be automatically closed as a duplicate in 3 days.
🤖 Generated with Claude Code
Reproducing on macOS (arm64) — additional environment details and isolation tests
Environment
Text mode — single newline byte on stdout:
claude -p "Say hello"
JSON mode — empty result, tokens consumed:
Any programmatic use of claude -p that reads stdout or parses the JSON result field gets an empty
response. This breaks CI/CD pipelines, agent frameworks spawning claude -p as a subprocess, and
automation scripts.
Pin to v2.1.81 under a different filename (the auto-updater overwrites both symlinks and binary copies
Then point your tooling at claude-pinned instead of claude.``
There are duplicated issues to this one - not sure which one will be the main one. Leaving this open as it already has thumb-up
This was fixed in v2.1.84 — Fixed
claude -preturning empty result when Stop hooks (or other progress/attachment-emitting sources) are configured — result extraction now skips trailing progress/attachment messages to find the actual assistant response. If you're still seeing this in the latest version, please comment with your version and repro and we'll reopen.This issue has been automatically locked since it was closed and has not had any activity for 7 days. If you're experiencing a similar issue, please file a new issue and reference this one if it's relevant.