Codex Background Stdin Close Pattern
Class of task
Use this skill when launching non-interactive Codex CLI execution from Hermes, especially for long-running implementation lanes or quota-burn batches in isolated worktrees.
Trigger conditions
codex exec ... prints Reading additional input from stdin... and appears to hang.
< /dev/null, an empty pipe, or PTY launch does not make Codex proceed.
- The task is a background Codex implementation/review lane that should continue while Hermes does other work.
- Multiple Codex lanes are running and duplicate/stale launches must be avoided.
Reliable Hermes launch pattern
Put the prompt in a file when it is long:
cat > /tmp/codex-issue-NNN.md <<'EOF'
...self-contained prompt...
EOF
Launch Codex as a Hermes-tracked background process, without shell stdin redirection:
terminal(
command='codex exec -c model_reasoning_effort="high" --dangerously-bypass-approvals-and-sandbox --cd /path/to/worktree "$(cat /tmp/codex-issue-NNN.md)"',
background=True,
notify_on_complete=True,
)
Immediately close stdin for the returned session:
process(action='close', session_id='proc_...')
Monitor with:
process(action='poll', session_id='proc_...')
process(action='log', session_id='proc_...', limit=200)
If the run remains stuck at the stdin message, kill the Hermes process session and relaunch once with the same pattern. Do not launch duplicates before checking OS-level ps, worktree git state, and logs.
Scope and safety rules
- Use isolated worktrees/clones for each issue lane.
- Verify the issue is
status:plan-approved before implementation; otherwise do planning/review only.
- Use
--dangerously-bypass-approvals-and-sandbox only when the user has authorized autonomous execution and the worktree scope is isolated. Record the sandbox failure reason, such as bwrap: loopback: Failed RTM_NEWADDR.
- Do not force-push.
- Require final output or handoff to include issue number, branch, commit SHA(s), validation commands/results, push status, issue URL, and blockers.
- On remote/overflow machines, CLI presence and auth files are not enough. Before assigning a Codex burn lane, run a tiny real
codex exec smoke through the same login shell/launch path. A worker may have codex --version and ~/.codex/ present but still fail with 401 Unauthorized / Failed to refresh token: refresh token was already used.
- If a remote worker falls back to Codex and produces a branch for an issue that another Codex lane also touched, do not push blindly. First compare commit/file scope against the already-pushed branch and choose one canonical branch/PR; treat the other as a salvage/reference artifact.
Why this exists
In workspace-hub on 2026-04-27, Codex CLI 0.125 repeatedly hung at Reading additional input from stdin... with < /dev/null, printf "" |, and PTY launches. Starting the run as a Hermes background process and explicitly closing stdin with process close allowed it to proceed.
1---2name: codex-background-stdin-close3description: Launch Codex CLI background runs in Hermes when Codex hangs at `Reading additional input from stdin...`; use explicit process stdin close and isolated worktrees.4---56# Codex Background Stdin Close Pattern78## Class of task910Use this skill when launching non-interactive Codex CLI execution from Hermes, especially for long-running implementation lanes or quota-burn batches in isolated worktrees.1112## Trigger conditions1314- `codex exec ...` prints `Reading additional input from stdin...` and appears to hang.15- `< /dev/null`, an empty pipe, or PTY launch does not make Codex proceed.16- The task is a background Codex implementation/review lane that should continue while Hermes does other work.17- Multiple Codex lanes are running and duplicate/stale launches must be avoided.1819## Reliable Hermes launch pattern20211. Put the prompt in a file when it is long:22 ```bash23 cat > /tmp/codex-issue-NNN.md <<'EOF'24 ...self-contained prompt...25 EOF26 ```27282. Launch Codex as a Hermes-tracked background process, without shell stdin redirection:29 ```python30 terminal(31 command='codex exec -c model_reasoning_effort="high" --dangerously-bypass-approvals-and-sandbox --cd /path/to/worktree "$(cat /tmp/codex-issue-NNN.md)"',32 background=True,33 notify_on_complete=True,34 )35 ```36373. Immediately close stdin for the returned session:38 ```python39 process(action='close', session_id='proc_...')40 ```41424. Monitor with:43 ```python44 process(action='poll', session_id='proc_...')45 process(action='log', session_id='proc_...', limit=200)46 ```47485. If the run remains stuck at the stdin message, kill the Hermes process session and relaunch once with the same pattern. Do not launch duplicates before checking OS-level `ps`, worktree git state, and logs.4950## Scope and safety rules5152- Use isolated worktrees/clones for each issue lane.53- Verify the issue is `status:plan-approved` before implementation; otherwise do planning/review only.54- Use `--dangerously-bypass-approvals-and-sandbox` only when the user has authorized autonomous execution and the worktree scope is isolated. Record the sandbox failure reason, such as `bwrap: loopback: Failed RTM_NEWADDR`.55- Do not force-push.56- Require final output or handoff to include issue number, branch, commit SHA(s), validation commands/results, push status, issue URL, and blockers.57- On remote/overflow machines, CLI presence and auth files are not enough. Before assigning a Codex burn lane, run a tiny real `codex exec` smoke through the same login shell/launch path. A worker may have `codex --version` and `~/.codex/` present but still fail with `401 Unauthorized` / `Failed to refresh token: refresh token was already used`.58- If a remote worker falls back to Codex and produces a branch for an issue that another Codex lane also touched, do **not** push blindly. First compare commit/file scope against the already-pushed branch and choose one canonical branch/PR; treat the other as a salvage/reference artifact.5960## Why this exists6162In workspace-hub on 2026-04-27, Codex CLI 0.125 repeatedly hung at `Reading additional input from stdin...` with `< /dev/null`, `printf "" |`, and PTY launches. Starting the run as a Hermes background process and explicitly closing stdin with `process close` allowed it to proceed.