When stdin is not a terminal
While installing version 0.169.0 of the Codex CLI on Linux, I encountered a rather interesting error.
The installation completed successfully, and the installer asked whether I wanted to launch Codex. I answered yes.
Error: stdin is not a terminal What caught my attention was that the installer had just successfully interacted with my terminal.
Why couldn’t Codex do the same?
Following stdin
The recommended installation method pipes the installation script directly into a shell:
curl ... | sh In this scenario, the shell’s standard input is connected to a pipe rather than a terminal.
However, the installer still needs to interact with the user. Looking through scripts/install/install.sh, I found that the prompt_yes_no() function reads from /dev/tty.
This allows the installer to obtain input directly from the controlling terminal, independently of what is connected to standard input.
The distinction is important:
/dev/stdinrefers to the process’s standard input./dev/ttyrefers to the process’s controlling terminal, if one exists.
A process can have access to a terminal without its standard input being connected to it.
That was precisely what was happening here.
Following the execution
Further down the installation script, the maybe_launch_codex_now() function launches the newly installed binary:
"$BIN_PATH" Unlike the prompt function, this invocation doesn’t redirect standard input to the terminal.
The new process inherits the installer’s file descriptors, including standard input, which is still connected to the pipe.
The situation looks roughly like this:
curl
|
v
sh (install.sh)
|
+-- prompt_yes_no() <-- /dev/tty
|
+-- codex <-- inherited stdin The installer can read my answer because it explicitly accesses the controlling terminal. Codex, on the other hand, inherits a standard input that isn’t a terminal.
The error now made perfect sense.
A small change
The installer already had a mechanism for interacting with the terminal. There was no need to introduce anything particularly complicated.
Before launching Codex, we can check whether file descriptor 0 (standard input) is connected to a terminal:
if [ -t 0 ]; then
"$BIN_PATH"
else
"$BIN_PATH" </dev/tty
fi If standard input is already a terminal, the existing behavior is preserved.
Otherwise, the redirection connects the application’s standard input to the controlling terminal.
I applied the change locally and ran the patched installer through a pipe again.
This time, after answering yes, the Codex TUI opened successfully.
Reporting the issue
I documented the reproduction steps, the explanation, the proposed patch and the local test result in openai/codex#42712.
The fix reuses the same approach the installer already uses to read user input, redirecting stdin to /dev/tty when launching Codex through a pipe.