Skip to content
Nilay Kabariya

Entry No.031·Agents·Updated ·4 min read

Fix: Codex CLI error "stdin is not a terminal"

Codex CLI stops with stdin is not a terminal in scripts, pipes and CI. The command that works, and the 2 errors that come next, tested on 0.167.0.

What changed on Nov 8, 2026: Re-ran on Codex CLI 0.167.0 and added the two errors that come next in CI: the git-repository check and the misleading WebSocket error.

by Nilay#codex#openai#cliAGENTS

The error, verbatim

Jump to the fix ↓
Error: stdin is not a terminal
✓ Reproduced on Windows 11 Pro; Ubuntu on GitHub Actions (November 2)

The fix that worked

Use the non-interactive command:

codex exec "say hi"
Not it? Every cause, tested ↓

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

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 exec

If 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:

Terminal on GitHub Actions with codex-cli 0.167.0: codex exec outside a git repository stops with Not inside a trusted directory and --skip-git-repo-check was not specified; with the flag, or inside a git repository, it reads the prompt and then fails to connect to the Responses WebSocket, the same as with no key at all.
codex exec in a folder that isn't a git repository, then with the flag, then inside a repository, then with no key. Timestamps cut from the log lines. Full log.

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

Useful? Pass it on:Post on XFollow @EmotionalMatter

Related entries

  1. No.114

    Codex: Error loading config.toml, each message and its fix

    Codex CLI 0.171.0 won't start on a bad config.toml. Common mistakes tested on Linux and Windows, from Windows paths to profiles: each message and fix.

    > Error loading config.toml:

    AGENTS6 min
  2. No.111

    Codex MCP startup incomplete: what each failure prints

    Codex 0.171.0 hides MCP startup errors behind a warnings count. Tested: a crash, a missing key, a bad command, an npx 404, a slow server, and the fix for each.

    > ⚠ 2 warnings · f2 to view

    AGENTS4 min
  3. No.098

    huggingface-cli: command not found (removed in 1.0, not 2.0)

    huggingface-cli stopped working in huggingface_hub 1.0.0, returned as a do-nothing stub in 1.10.1 and is gone in 2.0. All versions tested, plus the hf commands.

    > huggingface-cli: command not found

    AI5 min

tip: paste the exact error text