Fix it
- Replace
codexwithcodex execanywhere it runs without a person at a terminal:codex exec "summarize the repository structure and list the top 5 risky areas" - Piping something in? Give the instruction as the argument and the piped data becomes extra context:
Or pass the whole prompt on stdin withgit diff | codex exec "review this diff for bugs"-:cat prompt.txt | codex exec - - Continuing an earlier run? Use
codex exec resume --last "next instruction"instead ofcodex resume. - Need it to edit files?
codex execruns in a read-only sandbox by default. Add--sandbox workspace-write.--full-autois no longer supported. - Not in a Git repository?
codex execrequires one to guard against destructive changes;--skip-git-repo-checkoverrides it, only where that is safe.
Why it happens
In Codex's source, the interactive interface checks its streams before it draws anything:
if !stdin().is_terminal() {
return Err(std::io::Error::other("stdin is not a terminal"));
}
if !stdout().is_terminal() {
return Err(std::io::Error::other("stdout is not a terminal"));
}
So any of these triggers it:
- Piping into it:
echo "fix the tests" | codex. - Running it from a CI job, cron, a git hook, or as a subprocess of another program or AI agent, none of which gives it a terminal.
- Redirecting its output:
codex > out.txtgives the matchingstdout is not a terminal.
How to check
In bash or zsh, from the same place Codex runs:
[ -t 0 ] && echo "stdin is a terminal" || echo "stdin is NOT a terminal"
If it prints NOT, the interactive codex can't run there, and codex exec is the right command.
Getting the output back
codex execstreams progress to stderr and prints only the final message to stdout, socodex exec "..." > result.mdworks.--jsonturns stdout into a JSON Lines stream of every event.-o <path>(--output-last-message) writes the final message to a file.--ephemeralskips saving session files.
In CI
codex exec reuses saved CLI sign-in by default. In CI, set the key only for the one command that needs it:
CODEX_API_KEY=<api-key> codex exec --json "triage open bug reports"
OpenAI's docs warn against setting OPENAI_API_KEY or CODEX_API_KEY at job level in workflows that run repository code, and recommend the Codex GitHub Action for GitHub Actions.
After "Start codex now? [y/n] y ==> launching codex"
Many people hit this error right after a prompt like Start codex now? [y/n] y ==> launching codex, printed by an installer, launcher or setup script. That program started Codex for you, from inside its own process. The interactive interface then has no terminal on stdin, so it stops with error: stdin is not a terminal. Nothing is broken in the install.
- Answer n to that prompt (or let it fail; Codex is installed either way).
- Open a normal terminal window yourself: Terminal on macOS, a Linux terminal, or PowerShell / Windows Terminal on Windows.
- Run
codexthere. If you wanted it to run unattended from the script, change the script to callcodex exec "..."instead.
It happens in a normal terminal on Windows
Issue #15886 reported codex resume --last failing with this error in an interactive Windows PowerShell on v0.116.0. It was closed as stale: the maintainers had no reproduction beyond the older Windows launcher and resume path, and asked for the current install method, terminal and exact command if it still happens. Update first (codex update), then report it with those details.
Running Claude Code, Codex or Cursor on real repos, or shipping an AI agent? A Quick Review ($149 / ₹13,900, 1 working day) checks one repo, config or setup for leaked keys, risky agent permissions and MCP servers. Request a Quick Review
FAQ
What is the non-interactive version of the Codex CLI?
codex exec. It runs without the interactive interface, streams progress to stderr and prints the final message to stdout.
Can I pipe a prompt into Codex?
Yes, with codex exec. With a prompt argument the piped content is extra context; with - as the argument, the whole prompt is read from stdin.
Why does codex > file.txt fail?
The interactive interface also requires stdout to be a terminal and reports 'stdout is not a terminal'. Use codex exec, or -o to write the final message to a file.
How do I resume a Codex session from a script?
codex exec resume --last "next instruction".
Why do I get 'stdin is not a terminal' after 'Start codex now? [y/n] y ==> launching codex'?
The program that asked that question started Codex from inside its own process, so the interactive interface had no terminal. Codex is installed; open a normal terminal and run codex there, or use codex exec if it should run unattended.
Related errors
- Codex CLI: Error loading config.toml
- Gemini CLI error 429 Resource exhausted
- MCP error -32000: Connection closed
Sources
Read 29 Nov 2026. These tools change often: if a step no longer matches, the linked page wins.
- openai/codex source: codex-rs/tui/src/tui.rs: github.com/openai/codex/blob/main/codex-rs/tui/src/tui.rs
- Codex docs: Non-interactive mode: learn.chatgpt.com/docs/non-interactive-mode
- openai/codex source: codex-rs/cli/src/main.rs: github.com/openai/codex/blob/main/codex-rs/cli/src/main.rs
- openai/codex issue #15886 (stdin is not a terminal in PowerShell): github.com/openai/codex/issues/15886
- reviewready CLI: one command that checks an AI app repo before it ships
- Exposed API key checker: find API keys committed to a repo or shipped to the browser
- CLAUDE.md security check: find risky instructions in agent rules files