The error, verbatim
Jump to the fix ↓Error: stdin is not a terminal
Tested on
- Codex CLI
- 0.158.0; re-tested on 0.166.0 and 0.167.0
- Node
- 24.14.0
- OS
- Windows 11 Pro; Ubuntu on GitHub Actions (November 2)
✓ Last re-run on GitHub Actions · see the run · all repros
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.
The next two errors in CI, on 0.167.0
Getting past stdin is not a terminal is usually the first of three stops in a CI job. On November 8, 2026 I ran codex exec on Codex CLI 0.167.0 on a GitHub Actions runner with no terminal, with an empty CODEX_HOME, to see what comes next:

Stop two: the git check. In a folder that isn’t a git repository, codex exec refuses to start:
Not inside a trusted directory and --skip-git-repo-check was not specified.
CI checkouts are git repositories, so a job usually passes this. It bites in scripts that cd into a build folder, a temp folder or a Docker WORKDIR without .git. Add the flag the message names:
codex exec --skip-git-repo-check "say hi"
Inside a freshly git init-ed folder, the same command started without the flag.
Stop three: sign-in, and an unhelpful message. With an invalid key in OPENAI_API_KEY, the first error wasn’t about the key. It was a connection error:
ERROR codex_api::endpoint::responses_websocket: failed to connect to Responses WebSocket stage=Unknown
With no key at all, and not signed in, it printed exactly the same line. Nothing in those first lines tells you the problem is authentication. The same invalid key in CODEX_API_KEY instead gave a clear message right away: unexpected status 401 Unauthorized: Incorrect API key. So if your CI job ends on that WebSocket line, check the key and how you pass it before you look at the network. Setting up the key itself is covered in Missing environment variable: OPENAI_API_KEY in the Codex CLI.
One more small change: with stdin attached but empty, as in most CI steps, 0.167.0 prints Reading additional input from stdin... before every run, even when you pass the prompt as an argument. It’s informational; the run continues.
The runs
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.
November 2, 2026: every command in the table was re-run with Codex CLI 0.166.0 on GitHub Actions ubuntu-latest (no terminal attached), with an empty CODEX_HOME and an invented key. All matched: plain codex, a piped codex and codex "say hi" stopped with Error: stdin is not a terminal, and codex exec started in each form, with the prompt read from the argument, from the pipe (it now prints Reading prompt from stdin... first), as an argument plus a <stdin> block, and with exec -. The script and output are public.
November 8, 2026: the table again on Codex CLI 0.167.0 (all the same), plus the git-check and sign-in cases above, on ubuntu-latest with Node 24.22.2, an empty CODEX_HOME and an invented key (next.sh, run 42500331928).
— N.K., end of entry No.031