Codex Environment Variables
OpenAI's docs list 12 public environment variables for Codex, read Nov 17, 2026, plus OPENAI_API_KEY for image batches. CODEX_HOME moves its whole folder (default ~/.codex), CODEX_API_KEY gives codex exec an API key, CODEX_NON_INTERACTIVE=1 installs without prompts and RUST_LOG=debug turns on logging. Each one with a line to copy.
The environment variable most people need is CODEX_HOME, which moves the folder where Codex keeps its config, sign-in, logs, chats and skills from the default ~/.codex to any folder that already exists, for example export CODEX_HOME="$HOME/work-codex" before you run codex (Environment variables, OpenAI docs, read Nov 17, 2026). OpenAI's page lists 12 public variables, and its image generation page names a 13th; we count them below. The page says durable settings belong in config.toml: the variables are for one shell, a script, an installer or a fault you are chasing.
Next: the installers these variables change, the rules folder that lives under CODEX_HOME or running codex exec in CI with an API key.
All of them, with a line to copy
| Variable | Read by | Default | A line to copy (ours) |
|---|---|---|---|
CODEX_HOME |
CLI, IDE extension, app server, installers | ~/.codex |
export CODEX_HOME="$HOME/work-codex" |
CODEX_SQLITE_HOME |
CLI and app server state | CODEX_HOME |
export CODEX_SQLITE_HOME="/var/tmp/codex-db" |
CODEX_NON_INTERACTIVE |
The standalone installers | false |
See the install lines under the table |
CODEX_INSTALL_DIR |
The standalone installers | ~/.local/bin; on Windows %LOCALAPPDATA%\Programs\OpenAI\Codex\bin |
See the install lines under the table |
CODEX_API_KEY |
codex exec, review, the TypeScript SDK, remote exec server |
None | CODEX_API_KEY="$KEY" codex exec "summarize the diff" |
CODEX_ACCESS_TOKEN |
CLI, app server, trusted automation | None | Pipe it to codex login --with-access-token to stay signed in |
OPENAI_FEDERATION_RULE_ID |
Workload identity | None | Set by your CI's identity setup |
OPENAI_IDENTITY_TOKEN_FILE |
Workload identity | None | An absolute path to the OIDC token file |
OPENAI_WORKLOAD_IDENTITY_CONTEXT |
Workload identity | None | Optional JSON for audit labels; it does not affect sign-in |
CODEX_CA_CERTIFICATE |
HTTPS, sign-in and WebSocket clients | None | export CODEX_CA_CERTIFICATE=/etc/ssl/corp-root.pem |
SSL_CERT_FILE |
The same clients, as a fallback | None | Used only when CODEX_CA_CERTIFICATE is unset |
RUST_LOG |
CLI and app server | error for codex exec |
RUST_LOG=debug codex -c log_dir=./.codex-log |
Those are the 12 on OpenAI's list. The 13th is OPENAI_API_KEY, which OpenAI's image generation page (read Nov 17, 2026) tells you to set when you want Codex to make a large batch of images through the API at API prices instead of from your plan's limits. Variables, defaults and the "Read by" column are from OpenAI's Environment variables page; the example lines are ours, built from the forms OpenAI's page shows (paths such as corp-root.pem and work-codex are placeholders).
The two installer variables go in front of the shell that runs the downloaded script. An unattended install on macOS or Linux, as OpenAI's page gives it:
curl -fsSL https://chatgpt.com/codex/install.sh | CODEX_NON_INTERACTIVE=1 sh
The same on Windows PowerShell:
$env:CODEX_NON_INTERACTIVE=1; irm https://chatgpt.com/codex/install.ps1 | iex
To put the codex command in another folder, ours: curl -fsSL https://chatgpt.com/codex/install.sh | CODEX_INSTALL_DIR="$HOME/bin" sh. The package cache still lives under CODEX_HOME/packages/standalone.
The five that solve real problems
Two separate Codex setups on one machine. Point CODEX_HOME at a second folder and Codex there has its own config, sign-in, history and skills. OpenAI's page warns that "the directory must already exist", so create it first (mkdir -p "$HOME/work-codex"). Its rules folder moves with it, so an allow rule written under one home does not apply under the other. Coding With Chuck's Aug 10, 2026 lesson on Codex configuration uses exactly this for a clean test: a setup script sets CODEX_HOME to a subfolder for that one PowerShell session, so the demo starts from known files with its own user-level config.toml and none of his everyday profile, tools or history.
An API key for a script, not for the whole job. CODEX_API_KEY signs a non-interactive run in with an API key, so usage is billed at API prices. OpenAI's advice is to "set it inline rather than job-wide when running repository-controlled code": put it in front of the one codex exec line, as in the table, so other steps of a CI job cannot read it.
ExamPro's May 14, 2026 lesson on automating Codex walks through the same non-interactive mode: codex exec with a prompt, piped input and output, an ephemeral run that keeps no session, JSON output for jq, and passing a Codex API key so a run does not draw on your subscription, or so several keys can be used side by side; its most common use is a GitHub Actions job.
An install that asks nothing. CODEX_NON_INTERACTIVE=1 (or true, or yes) makes the install script take every default. OpenAI says to use it for scripted installs and updates, "not first-run setup".
A company network that breaks sign-in. Behind a proxy that inspects TLS, point CODEX_CA_CERTIFICATE at your company's root certificate in PEM form. It takes precedence over SSL_CERT_FILE.
A log to send with a bug report. The interactive CLI writes no plain-text log by default. RUST_LOG=debug codex -c log_dir=./.codex-log writes one to ./.codex-log/codex-tui.log, and tail -F ./.codex-log/codex-tui.log follows it. RUST_LOG also takes narrower filters such as codex_core=debug,codex_tui=debug; codex exec prints its messages inline instead of to that file.
What is not on the list
OpenAI's page leaves out internal and test variables on purpose. A key for another model provider has no fixed name: you choose it with env_key in that provider's section of config.toml, and Codex reads whatever variable you named there. Anything you want every time (the model, the sandbox, the approval policy) goes in config.toml, covered on Codex CLI.
Sources
- Environment variables, OpenAI docs (learn.chatgpt.com), read Nov 17, 2026
- Image generation, OpenAI docs, read Nov 17, 2026
- Automating Codex - Non-Interactive Mode, OpenAI API, SDKs & GitHub Actions, ExamPro, May 14, 2026 (video)
- Codex CLI Setup & Configuration: Which Setting Wins?, Coding With Chuck, Aug 10, 2026 (video)
Moments
Codex CLI Setup & Configuration: Which Setting Wins?
Coding With Chuck
Automating Codex - Non-Interactive Mode, OpenAI API, SDKs & GitHub Actions
ExamPro
See also
-
CodexCodex is OpenAI's coding agent: it reads a codebase, edits files, runs commands and tests, reviews pull requests and works in the cloud. As of Nov 6, 2026 it lives inside the ChatGPT desktop app, in the Codex CLI, in IDE extensions, in Codex Cloud and on mobile, and every ChatGPT plan includes some of it, Free and Go too.
-
How to Install Codex CLITo install OpenAI's Codex CLI, run curl -fsSL https://chatgpt.com/codex/install.sh | sh on macOS or Linux, or the PowerShell installer on Windows (npm install -g @openai/codex and brew install --cask codex also work), then run codex in a project folder and sign in with ChatGPT. Steps for every system, WSL, updating, removing and fixing common problems, as of Nov 6, 2026.
-
How to Let Codex Run a Command Without AskingTo let Codex run one command outside its sandbox without asking you each time, add prefix_rule(pattern = ["npm", "test"], decision = "allow") to ~/.codex/rules/default.rules and restart Codex. The file, the three decisions, how Codex treats chained shell commands, and how to test a rule with codex execpolicy check, read in OpenAI's docs on Nov 17, 2026. -
Codex SDKThe Codex SDK lets programs run OpenAI's Codex agent: npm install @openai/codex-sdk for TypeScript (Node.js 18 or later) or pip install openai-codex for Python (3.10 or later). For CI there is also codex exec, the non-interactive CLI mode, and the GitHub Action openai/codex-action@v1; the App Server is the protocol for building full Codex clients.
-
Codex CLICodex CLI is OpenAI's open-source coding agent for the terminal: install it with one command, run codex in a project folder, sign in with ChatGPT or an API key, and it reads, edits and runs your code inside a sandbox. This page covers its commands, models, approval modes, config.toml, codex exec, resume and MCP as of Nov 6, 2026. -
AGENTS.mdAGENTS.md is a plain Markdown file of instructions for AI coding agents, a "README for agents", that Codex reads before doing any work. Codex loads a global ~/.codex/AGENTS.md and then every AGENTS.md from the repository root down to the working folder, closest last, up to 32 KiB; /init writes a first one. The open format is now stewarded by the Agentic AI Foundation.