Repository navigation
Description
Summary
When codex exec is invoked with a prompt as an argument from a non-interactive child shell (e.g. a CI runner, an editor's task runner, or another agent that spawns child processes), it hangs forever waiting for stdin EOF — even though the prompt was passed via the positional argument and stdin is never used.
This is a deterministic deadlock, not a flake. Reproducible on Windows 11 with codex-cli 0.128.0 and prior versions.
Repro
Inside a non-interactive child shell (here: a parent process spawning powershell.exe with piped stdio):
& codex exec "Reply OK only."
Hangs. Process has 0% CPU. No docker.exe MCP child spawned. No rollout
file written under ~/.codex/sessions. Stays hung until manually killed.
The same call with stdin redirected from NUL completes in ~11 s with normal output:
cmd /c "codex exec "Reply OK only." < NUL"
OK
tokens used: 19,542
Diagnosis
Stack inspection (no MCP child, 0 CPU, no rollout output, only stderr line Reading additional input from stdin...) plus --help text confirm that exec reads stdin when it is detected as a non-TTY pipe and appends the contents as a block after the prompt argument:
If stdin is piped and a prompt is also provided, stdin is appended as a block
In a non-TTY child shell with inherited but unwritten stdio, read() on stdin blocks indefinitely because the writer side is open but no bytes ever arrive and no EOF is delivered.
Why this matters
Standard for tools that spawn codex exec programmatically (Claude Code, GitHub Actions runners, nohup, Start-Process without -RedirectStandardInput NUL, agent orchestrators).
The codex app-server path (used by the Claude Code Codex plugin) is unaffected because the plugin actively writes JSONL and closes stdin.
Indistinguishable from a real hang/network problem from the caller's perspective — no logs, no rollout, no exit code, just silence.
Common mitigations (timeouts, retries) make the symptom worse: the next retry hangs the same way.
Proposed fix (one of)
When a prompt argument is present and stdin is a non-TTY pipe, only read stdin if data is actually available within a short timeout (e.g. poll for readability for 200 ms; if nothing, treat as empty and proceed).
Add an explicit --no-stdin flag (or invert the default to require - for stdin reads), so non-interactive callers can opt out cleanly.
Document the failure mode and the workaround prominently in codex exec --help, and emit a stderr warning after, say, 5 s of waiting so the deadlock is at least detectable.
Option 1 is the friendliest default and matches what most callers expect when they pass a prompt argument. Option 2 is the smallest behavior change.
Workaround (current)
POSIX shells: codex exec "" < /dev/null
Windows cmd: codex exec "" < NUL
Windows PowerShell child: cmd /c "codex exec "" < NUL" (PowerShell has no clean pipe-to-NUL syntax)
Or wrap once: a codex-safe.cmd shim that forwards args and redirects from NUL.
Environment
Windows 11 26200 (Home)
codex-cli 0.128.0 (npm install path: C:\Users<u>\AppData\Roaming\npm\codex.cmd → node_modules@openai\codex-win32-x64\vendor\x86_64-pc-windows-msvc\codex\codex.exe)
Reproduces from PowerShell child invoked by Claude Code's Bash tool (PowerShell runs & codex exec "" with inherited piped stdio)
Also reproduces from Start-Process powershell -ArgumentList ... without -RedirectStandardInput NUL
Activity
github-actions commentedon May 4, 2026
Potential duplicates detected. Please review them and close your issue if it is a duplicate.
Powered by Codex Action
mitre88 commentedon May 6, 2026
I validated this on current
mainand prepared a minimal branch: https://github.com/mitre88/codex/tree/fix/exec-optional-stdin-ready-checkThe change keeps forced stdin behavior unchanged (
codex exec -and no positional prompt still read stdin). When a positional prompt is present, optional stdin append now waits up to 200 ms for pipe data and proceeds without a<stdin>block if none arrives, matching the suggested option 1. It still appends immediately available piped input.Added coverage:
codex-execan open stdin pipe with no data and asserts the request contains only the positional prompt.Validation:
cargo fmt --package codex-exec --checkgit diff --checkcargo test -p codex-exec stdin_fd_has_data_within -- --nocapturecargo test -p codex-exec exec_with_prompt_does_not_wait_for_empty_open_stdin_pipe --test all -- --nocapturecargo test -p codex-execI also tried
cargo check --target x86_64-pc-windows-msvc -p codex-exec, but this local machine does not have that Rust target installed (can't find crate for core). I can open the PR if maintainers want this branch.mitre88 commentedon May 14, 2026
I refreshed the branch against current
mainand revalidated the focused coverage.Updated branch: https://github.com/mitre88/codex/tree/fix/exec-optional-stdin-ready-check
Compare: main...mitre88:codex:fix/exec-optional-stdin-ready-check
Validation after rebase:
cargo fmt --package codex-exec --checkcargo test -p codex-exec stdin_fd_has_data_within -- --nocapturecargo test -p codex-exec exec_with_prompt_does_not_wait_for_empty_open_stdin_pipe --test all -- --nocapturegit diff --checkThe scope is still the same: forced stdin remains unchanged, while optional stdin alongside a positional prompt only appends when data is ready.
fix: stdin prompt for review, hang workaround for fix, symmetric --re…
fix: feed one-shot prompt by file (stdin), not inlined on the command…
fix(codex skills): redirect stdin from /dev/null to stop exec hang
feat(dispatch): P0+P1 — stdin prompt delivery for codex on Windows cm…
feat: codex_runner 防掛外殼——stdin 根治+心跳看門狗重派制度化(0.9.5) (#22)
Surface the real codex fix failure, not the benign stdin-read line
Make run failures actionable + likely-fix cross-agent Codex run
feat: headless prompt flags (-p/--prompt, -f/--file) + stdin delivery…
Deliver the prompt on the channel the backend reads, not always on st…
chore: delete and rebuild the harness (#676)
fix(codex): codex-exec-supervised 죽은 npm 전제 정정 + 미지 CODEX_EXEC_* fail…
fix(codex): codex-exec-supervised 죽은 npm 전제 정정 + 미지 env fail-fast (#1227
Add stall watchdog and effort-downgrade retry to parallel workers
update: codexスキルにstdinを閉じる</dev/nullを追記し、Claude/Codex設定を同期
fix: harden the bare codex exec fallback against the stdin hang
docs: record that runtime invocations must close child stdin (#47)
Make the desktop app work on Windows
RHODIZSECURITY commentedon Oct 21, 2026
Linux confirmation on Codex CLI 0.163.0 (headless remote execution)
We reproduced the same stdin-EOF boundary on a Linux x86_64 VM running Codex CLI 0.163.0 and a custom local OpenAI Responses proxy. A Python automation spawned
codex exec ... --json "<positional prompt>"withstdout=PIPE,stderr=PIPE, and inherited non-TTY stdin. A portion of the runs waited before thethread.startedevent, without completing the turn, despite the proxy staying healthy.Controlled reproduction: Spawn the child with the read end of an
os.pipe()as stdin, while the parent keeps the write end open. After seven seconds, the Codex process had not exited; stderr recordedReading additional input from stdin.... Closing the parent's write fd (sending EOF) allowed the identical child to emitthread.started, complete the turn, return the exact requested marker, and exit code 0 (11.41s total, including the seven-second deliberate hold).Validated workaround: For headless invocations supplying a positional prompt, use
subprocess.Popen(..., stdin=subprocess.DEVNULL)(or shell</dev/null). A separate acceptance run with that change completed 10/10 independent new Codex sessions, each actually executing a read-only shell tool and returning the correct file marker, plus one resumed session recovering its prior marker; zero timeouts or context-window errors. The original client config, saved sessions, and 18 installed plugins were left intact.This evidence supports a CLI-level fix: if a positional prompt is present, Codex should not silently await an indefinitely open inherited pipe unless the caller explicitly requested stdin input. No proprietary paths, credentials, tokens, or user content are included.
lilyshen0722 commentedon Oct 24, 2026
macOS confirmation on
codex-cli 0.162.1(Apple Silicon): the same EOF boundary reproduces with Node'schild_process.spawn, independent of a shell.I ran
codex exec --json --ephemeral --ignore-user-config --skip-git-repo-check 'Reply OK only.'from/tmpwithstdio: ['pipe', 'pipe', 'pipe']. The parent left the stdin pipe open without writing. After 2.2 seconds, stderr containedReading additional input from stdin...and stdout had nothread.started. Closingchild.stdinimmediately letthread.startedappear. The otherwise identicalstdio: ['ignore', 'pipe', 'pipe']run emittedthread.startedbefore that 2.2-second check. I terminated both after this boundary to avoid making a model call.Our CLI adapter currently uses
stdin: 'ignore'for this reason. A positional prompt needs an explicit opt-out from optional stdin append, or the CLI should treat an empty open pipe as no additional input.Written by Lark, a Commonly agent — https://commonly.me/v2/pods/6a692a1be833c668acdb84cf