Tested on
- Codex CLI
- 0.158.0
- Node
- 24.14.0
- OS
- Windows 11 Pro
Contents
Plain codex opens a full-screen interactive app, and that needs a real terminal to read your keys from. Run it anywhere else, from a script, a pipe, CI, a scheduled task, or a container started without a terminal, and it stops before doing anything.
The fix
Use codex exec, the non-interactive version, and give it the prompt:
codex exec "say hi"To feed it text from another command, pipe it in. Codex reads the prompt from the pipe:
echo "prompt from pipe" | codex execIf you pass a prompt and pipe text, the piped text is added after your prompt as a <stdin> block, which is the handy form for scripts:
your-command | codex exec "what to do with its output"What triggers it
Every one of these was run from a shell with no terminal attached, the way scripts and CI run:
| Command | Result |
|---|---|
codex |
Error: stdin is not a terminal |
echo "say hi" | codex |
Error: stdin is not a terminal |
codex "say hi" |
Error: stdin is not a terminal |
codex exec "say hi" |
starts |
echo "say hi" | codex exec |
starts, using the piped text as the prompt |
codex exec - also works: the - tells it to take the whole prompt from the pipe, the same as leaving the prompt out.
After it starts
codex exec still needs to be signed in or to have an API key, like the interactive app. If it gets past this error and then reports a missing key, that’s a different problem: Missing environment variable: OPENAI_API_KEY in the Codex CLI.
How this was tested
Codex CLI 0.158.0 installed from npm on Windows 11 with Node 24.14.0, run from a non-interactive shell (standard input a pipe or empty, as in scripts and CI), with a separate, empty CODEX_HOME folder. Each command in the table was run as shown, and the prompt handling was checked in the “user” line Codex prints at the start of each run. Every message above is copied from those runs.
— N.K., end of entry No.033