CLI -p flag returns empty stdout when using stdin pipe (v2.1.83 regression)

Resolved 💬 9 comments Opened Mar 25, 2026 by failedprompt Closed Apr 19, 2026

Bug Description

claude -p with input via stdin pipe returns empty stdout in v2.1.83. This worked correctly in the previous version (installed before 2026-03-25).

Reproduction

import subprocess

result = subprocess.run(
    ["/Users/admin/.local/bin/claude", "-p"],
    input="Say hello",
    capture_output=True, text=True, timeout=30
)
print(f"RC: {result.returncode}")      # 0
print(f"STDOUT: [{result.stdout}]")    # empty
print(f"STDERR: [{result.stderr}]")    # empty

Shell equivalent:

echo "Say hello" | claude -p
# No output

claude -p "Say hello" < /dev/null
# No output

claude -p --output-format json "Say hello" < /dev/null
# Returns: {"result": "", ...} with output_tokens: 27

Note: running claude -p "Say hello" interactively (no pipe, with TTY) works fine and produces output.

Key Observations

  • returncode is 0 (success)
  • JSON output format shows output_tokens: 27 but result: "" — tokens are generated but not captured in the result field
  • Adding --output-format text doesn't help
  • Adding < /dev/null to avoid stdin warning doesn't help
  • --bare flag requires API key and doesn't use OAuth auth
  • This is a regression — the same code worked with the CLI version installed before 2026-03-25

Impact

This breaks any subprocess.run() integration that relies on capturing CLI output via stdout, e.g. using Claude CLI as a backend for prompt research in a Flask app.

Environment

  • Claude Code: v2.1.83
  • OS: macOS Darwin 25.3.0
  • Updated: 2026-03-25 07:46
  • Previous version (working): unknown exact version, updated automatically

View original on GitHub ↗

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