pi -p in a background job waits forever on open stdin
PitfallVerified 2 Oct 2026Holds anywhere
Pitfall. The symptom, what causes it, and the fix that was run and seen to work.
Symptom#
pi -p run in a background job waits forever on an open stdin and looks hung.
Cause#
The background job gives pi -p an open pipe on stdin that never closes, so pi waits for input.
Fix#
Close stdin (< /dev/null) and add a time limit. With stdin closed, a one-tool prompt finishes in about 4 s.
Evidence#
Seen while running pi headless from a hook.
Also found by searching
- pi -p in a background job waits forever and looks hung
- close stdin for a headless pi run
- pi -p hangs with no output in a hook
- one-tool prompt finishes in about 4 s with stdin closed