claude -p returns empty stdout despite generating output tokens
Status Fixed / completed
Reported on v2.1.83
Maintainer reply None cached
Workaround ✓ Mentioned in thread ↓
Activity 4 comments · opened Mar 25, 2026 · 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 jsonshows"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
--bareflag 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)
4 Comments
Found 3 possible duplicate issues:
This issue will be automatically closed as a duplicate in 3 days.
🤖 Generated with Claude Code
Detailed Regression Analysis
Version Bisection
All binaries cached at
~/.local/share/claude/versions/. No v2.1.82 exists — the jump is 2.1.81 → 2.1.83 directly.Command:
<binary> -p "Reply with just: hello" --model haiku --tools "" --output-format json < /dev/null| Version |
resultfield |output_tokens| Status ||---------|---------------|-----------------|--------|
| 2.1.78 |
'hello'| varies | works || 2.1.79 |
'hello'| varies | works || 2.1.80 |
'hello'| varies | works || 2.1.81 |
'hello'| 356 | works || 2.1.83 |
''| 372 | broken |Reproducible across haiku, sonnet, and opus. With/without
--tools "". From any directory.Stream-JSON Evidence
Using
--output-format stream-json --verbose, both versions produce 11 events with identical event types. The text IS generated in 2.1.83 — it just isn't captured in theresultfield.Assistant text event (identical in both versions):
Result event (divergent):
Structural Differences in 2.1.83
| Aspect | 2.1.81 | 2.1.83 |
|--------|--------|--------|
| Plugins loaded | 8 | 1 |
| cache_creation_input_tokens | 12,519 | 0 |
| cache_read_input_tokens | 4,851 | 17,963 |
| output_tokens | 356 | 153 |
| New native tools | — | LSP tool added |
Real-World Impact
A FastAPI server calling
claude -pviasubprocess.run()for NLP extraction silently fell back to a degraded keyword parser, producing incorrect results for 100% of new inputs until the empty output was diagnosed and the CLI was pinned to 2.1.81.Known Duplicates
Workaround
Related to #38651 — Stop hooks cause empty
-poutput. If you have anyStophooks configured, that is likely the root cause.Immediate fix: Remove or disable Stop hooks:
Workaround: If you need Stop hooks but also use
-pmode, wrap them with a headless detector:Or set
CC_HEADLESS=1in your wrapper:This lets Stop hooks run in interactive mode but skip in
-pmode, avoiding the empty output regression.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.