claude -p returns empty result field despite model generating response

Status Fixed / completed
Maintainer reply ✓ Yes — ashwin-ant
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

  • result field is "" (empty string)
  • output_tokens shows tokens were generated (e.g., 5 or 13)
  • stop_reason is "end_turn" (normal completion)
  • subtype is "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.

View original on GitHub ↗

5 Comments

github-actions[bot] · 5 months ago

Found 3 possible duplicate issues:

  1. https://github.com/anthropics/claude-code/issues/38769
  2. https://github.com/anthropics/claude-code/issues/38725
  3. https://github.com/anthropics/claude-code/issues/38760

This issue will be automatically closed as a duplicate in 3 days.

  • If your issue is a duplicate, please close it and 👍 the existing issue instead
  • To prevent auto-closure, add a comment or 👎 this comment

🤖 Generated with Claude Code

tyjmcn · 5 months ago

Reproducing on macOS (arm64) — additional environment details and isolation tests

Environment

  • Claude Code: 2.1.83
  • macOS 15 (Darwin 25.2.0), Apple Silicon, Mac Mini
  • Auth: claude.ai OAuth (Max subscription)
  • Last working version: 2.1.81
  • Settings: effortLevel: "high", 9 plugins, 13 MCP servers, 3 hooks
Reproduction

Text mode — single newline byte on stdout:
claude -p "Say hello"

JSON mode — empty result, tokens consumed:

  claude -p "Say hello" --output-format json
  Returns: {"result": "", "output_tokens": 13, ...}
Stream-JSON — text IS generated, visible in assistant events:
  claude -p "Say hello" --output-format stream-json --verbose
  Assistant event: {"type":"assistant","message":{"content":[{"type":"text","text":"\n\nHello! How can I
   help you?"}]}}
  Final result event: {"result": ""}
Isolation tests (all empty on 2.1.83, all work on 2.1.81)
  • Different models (Opus 4.6, Sonnet 4.6, Haiku 4.5) → Empty result
  • Different effort levels (--effort low, --effort high) → Empty result
  • Different directories (/tmp, ~/, project dirs) → Empty result
  • No MCP (--strict-mcp-config --mcp-config '{"mcpServers":{}}') → Empty result
  • No slash commands (--disable-slash-commands) → Empty result
  • Explicit stdin (echo "" | claude -p "Say hello") → Empty result
  • Same tests on v2.1.81 → All work correctly
Key observations
  • output_tokens is always > 0 (model generates tokens)
  • Content blocks are type: "text" (not thinking blocks — extended thinking is not the cause)
  • stop_reason: "end_turn" — model completes normally
  • is_error: false, subtype: "success" — CLI reports success
  • Text exists in the streaming pipeline and is lost during final result assembly
Confirms this is not caused by:
  • Extended thinking
  • MCP servers or plugins
  • Hooks (one hook shows Permission denied on session start, but disabling all hooks doesn't fix it)
  • Model choice or effort level
Impact

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.

Workaround

Pin to v2.1.81 under a different filename (the auto-updater overwrites both symlinks and binary copies

   at ~/.local/bin/claude):
  cp ~/.local/share/claude/versions/2.1.81 ~/.local/bin/claude-pinned

Then point your tooling at claude-pinned instead of claude.``

tpavelek · 5 months ago

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

ashwin-ant collaborator · 4 months ago

This was fixed in v2.1.84 — Fixed claude -p returning 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.

github-actions[bot] · 4 months ago

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.