claude -p returns empty stdout despite generating output tokens

Resolved 💬 4 comments Opened Mar 25, 2026 by digin1 Closed Mar 31, 2026

Description

claude -p (print mode) returns empty stdout despite the model generating tokens. The --output-format json output confirms output_tokens > 0 but result is an empty string.

Environment

  • Claude Code version: 2.1.83
  • OS: Ubuntu Linux (6.8.0-106-generic)
  • Auth: OAuth (claude.ai), Max subscription
  • Installation: curl installer

Reproduction

# Simple test — returns nothing
echo "say hello" | claude -p --model haiku --max-turns 1

# JSON output confirms tokens generated but result is empty
claude -p "2+2" --output-format json
# Output: {"result":"","output_tokens":5,"stop_reason":"end_turn",...}

# Direct argument — also empty
claude -p "say hello" 2>&1
# (no output)

Observed behavior

  • Exit code: 0 (success)
  • stdout: empty
  • stderr: empty
  • --output-format json shows "result": "" with "output_tokens": 5
  • Model is charged tokens (cache_creation_input_tokens: 5205, cache_read_input_tokens: 14417)
  • Happens with and without --model haiku
  • Happens with piped stdin and direct argument
  • Happens both inside and outside an active Claude Code session
  • --bare flag results in "Not logged in" (strips OAuth auth)

Expected behavior

stdout should contain the model's response text.

Impact

This breaks any scripted use of claude -p for programmatic LLM calls in hooks/automation. We use claude -p --model haiku --max-turns 1 in Claude Code hooks for lightweight LLM tasks (query expansion, keyword extraction). All of these silently fail and fall back to non-LLM paths.

Auth verification

claude auth status
# loggedIn: true, authMethod: "claude.ai", subscriptionType: "max"

Possibly related issues

  • #28407 (Bash tool output suppressed when child process spawns claude -p)
  • #7263 (Claude CLI returns empty output with large stdin input)
  • #19663 (Bash tool returns no output — set -o onecmd)

View original on GitHub ↗

This issue has 4 comments on GitHub. Read the full discussion on GitHub ↗