Skip to content
Happy Programming Guide
Start learning
AI for Programmers

Fixing Codex CLI Errors: “stdin is not a terminal” and “error sending request”

The two errors that account for most Codex CLI failures: running it somewhere without an interactive terminal, and a request that cannot reach the API. Causes and fixes for each.

A ladybug climbing on a dry branch

Codex, the terminal coding agent, fails in two characteristic ways. stdin is not a terminal means it was started somewhere it cannot read keyboard input: a script, a pipeline, a CI job, an IDE task runner, or a shell that does not provide a proper terminal. error sending request for url means the request to the API never got a response: authentication, a proxy, a firewall, or a network path. Both are environment problems rather than problems with the tool, and both have short fixes.

Interactive and non-interactive modes#

By default Codex runs as an interactive session: it draws a terminal interface, waits for your prompts, and asks before doing risky things. That requires a real terminal, a TTY, attached to standard input. When there is none, it cannot run that interface, and the error says so. For scripts, pipelines and CI, it has a non-interactive mode that takes the prompt as an argument and prints the result:

Terminal
codex exec "summarise what this repository does"
echo "explain the failing test" | codex exec -
codex exec --full-auto "fix the lint errors and commit"

The exact flags depend on the version; codex --help lists the current ones. The principle is fixed: an interactive session needs a terminal, and anything automated should use exec mode.

stdin is not a terminal#

Situations that produce it, and what to do:

  • Piping input. cat notes.md | codex starts the interactive interface with a pipe on stdin. Use exec mode with the piped prompt.
  • CI jobs and cron. No terminal exists. Use exec mode, and provide authentication through an environment variable rather than the sign-in flow.
  • IDE task runners and some integrated terminals. Certain task-runner panes are not full terminals. Run it from the editor’s real integrated terminal, or a standalone one.
  • Git Bash and MSYS on Windows. Programs that check for a terminal can fail under the MinTTY console. Use Windows Terminal with PowerShell, or run Codex inside WSL, or prefix with winpty.
  • Running inside another agent or tool that captures stdin. Same answer: exec mode.
  • Docker without -it. docker run -it allocates a terminal; without those flags there is none.
Terminal
tty                      # prints a device path in a real terminal, "not a tty" otherwise
[ -t 0 ] && echo interactive || echo not-interactive

error sending request for url#

The client tried to reach the API and got no usable answer. In order of likelihood:

  1. Not signed in, or the session expired. Run the login command again and complete it in the browser. In non-interactive environments, set the API key in the documented environment variable; the browser flow cannot run there.
  2. A proxy. Corporate networks route traffic through one. Set HTTPS_PROXY (and HTTP_PROXY) to it, with credentials in the URL if required, then retry.
  3. TLS inspection. The proxy re-signs certificates and the tool does not trust the corporate root. Install the root certificate in the system store, or point the tool’s certificate bundle variable at it; do not disable verification permanently.
  4. A firewall or DNS block. Test with curl against the API host from the same shell; if curl fails, the network is the problem, not Codex.
  5. A VPN that routes API traffic somewhere it cannot exit. Try with the VPN off to confirm.
  6. Rate limits or an outage. The error message usually differs (a 429 or a 5xx), but a saturated connection can present as a send failure. Check the provider’s status page.
Terminal
curl -sS -o /dev/null -w "%{http_code}\n" https://api.openai.com/v1/models -H "Authorization: Bearer $OPENAI_API_KEY"

A 200 or 401 means the network path works and the problem is inside the tool’s configuration; a timeout or connection error means the path is blocked.

See the real cause#

Run with verbose logging; the flag or environment variable is in codex --help. The log shows the request, the proxy in use, and the exact failure — certificate, DNS, refused, timeout — which is far more specific than the summary error.

Install and version checks#

Terminal
codex --version
node --version               # if installed via npm: a current LTS is expected
npm ls -g @openai/codex       # where and which version

An outdated CLI can fail against a changed API with a send error. Update it. If it was installed under one Node version manager and you have since switched Node versions, the command may be missing or stale; reinstall under the current Node, or use the native installer if one is offered for your platform.

Windows specifics#

  • Use Windows Terminal or PowerShell, or WSL, for interactive sessions.
  • Environment variables set with $env:NAME last for that window only; set them permanently in system settings for persistent configuration.
  • Paths with spaces in the working directory occasionally confuse older versions; try from a simple path to rule it out.

Questions people ask#

Can I use Codex entirely without a terminal?

Yes, through exec mode with an API key in the environment. That is how CI and automation use it.

Why does it work in one terminal app and not another?

Terminal emulators differ in how they present a TTY. MinTTY-based ones on Windows are the usual exception; Windows Terminal, PowerShell and WSL behave normally.

The error mentions a URL I do not recognise.

The CLI talks to more than one endpoint. Allowlist the API domain and any related ones named in the documentation, not just the main site.

Does this apply to Claude Code or other CLIs?

The same two classes of failure exist in every terminal agent: no TTY, and no network path. The flags differ; the diagnosis does not.

Where to go next#

Claude Code vs Codex: which coding agent to useRead next

Keep reading

Keep going — pick your next guide

The fastest way to improve is to read one guide, then build the thing it describes. Start with the basics, or jump straight to a project.

Ask a question or share what worked

Your email address will not be published. Required fields are marked *