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:
- Hangs indefinitely (no response)
- Fails with: "Error: Input must be provided either through stdin or as a prompt argument when using --print"
Reproduction Steps
- Create a background bash script that calls
claude -p --model haiku --max-turns 1 "prompt" - Run it from within a Claude Code session (as an observer agent)
- The command either hangs or fails
Workarounds Attempted
env -u CLAUDECODE claude -p "prompt"- hangsbash -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-promptflag, not general-pusage)
This issue has 3 comments on GitHub. Read the full discussion on GitHub ↗