claude -p hangs when called from background scripts on Windows (Git Bash)

Resolved 💬 3 comments Opened Feb 26, 2026 by thaishileme-ux Closed Mar 1, 2026

Environment

  • OS: Windows 11 + Git Bash
  • Claude Code version: 2.1.50

Problem

When running claude -p (non-interactive mode) from a background script or observer agent, it either:

  1. Hangs indefinitely (no response)
  2. Fails with: "Error: Input must be provided either through stdin or as a prompt argument when using --print"

Reproduction Steps

  1. Create a background bash script that calls claude -p --model haiku --max-turns 1 "prompt"
  2. Run it from within a Claude Code session (as an observer agent)
  3. The command either hangs or fails

Workarounds Attempted

  • env -u CLAUDECODE claude -p "prompt" - hangs
  • bash -c "export CLAUDECODE=''; claude -p ..." - hangs
  • Using stdin pipe: echo "prompt" | claude -p - hangs
  • Using temp file redirect: claude -p < prompt.txt - hangs
  • All combinations with --dangerously-skip-permissions - same result

Expected Behavior

Claude Code should respond to prompts in non-interactive mode when called from background scripts.

Related

  • Possibly related to #4930 (but that issue is about --system-prompt flag, not general -p usage)

View original on GitHub ↗

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