How to Install Codex CLI and Set Up config.toml (2026 Guide)
On this page
Short answer: install Codex CLI with npm install -g @openai/codex (needs Node.js), brew install --cask codex on a Mac, or OpenAI's script curl -fsSL https://chatgpt.com/codex/install.sh | sh on macOS and Linux (no Node.js needed). On Windows, run powershell -ExecutionPolicy ByPass -c "irm https://chatgpt.com/codex/install.ps1 | iex". Then open a new terminal, run codex, and sign in. The current version is 0.171.0, which we installed and tested on November 23, 2026.
We first ran every install method and config example below on an Apple-silicon Mac with Codex CLI 0.162.1 on October 15, 2026. On November 23 we reinstalled 0.171.0 with npm and with the standalone script and reran the provider configs and error messages; the steps and messages are unchanged. Windows steps follow OpenAI's documentation. If you set Codex up from an older guide, check what changed first, because a few of the old config keys now stop Codex from starting.
Install methods at a glance
| Method | Command | Node.js needed? | Updating |
|---|---|---|---|
| Standalone installer (macOS, Linux) | curl -fsSL https://chatgpt.com/codex/install.sh | sh |
No | codex update, or rerun the installer |
| Standalone installer (Windows) | powershell -ExecutionPolicy ByPass -c "irm https://chatgpt.com/codex/install.ps1 | iex" |
No | Rerun the installer |
| npm | npm install -g @openai/codex |
Yes | npm install -g @openai/codex@latest |
| Homebrew (macOS) | brew install --cask codex |
No | brew upgrade --cask codex |
| Direct download (macOS, Linux) | A .tar.gz from GitHub Releases |
No | Download the new release |
Pick one. Two installs of Codex on the same machine means your PATH order decides which one runs, and that gets confusing fast.
What changed in 2026
- There's an official standalone installer. You no longer need Node.js just to get Codex.
wire_api = "chat"is gone. Codex only uses the Responses API now. Configs that still setchatfail to load.- Profiles moved to their own files. Since 0.134.0,
[profiles.name]tables insideconfig.tomlno longer work with--profile. - The Codex desktop app is now part of the ChatGPT desktop app.
Which plan you need
The CLI is free, and model usage is what you pay for:
- ChatGPT Plus, Pro, Business, Edu or Enterprise: Codex works in the CLI, IDE extension, web and desktop app, using your plan's included usage. Plus is $20/month.
- ChatGPT Free and Go: limited Codex access in the ChatGPT desktop app only, not in the CLI.
- OpenAI API key: works in the CLI and IDE extension and is billed at standard API rates. Cloud features like GitHub code review aren't available this way.
- A compatible provider or gateway: any service that implements the OpenAI Responses API. See custom providers.
Install on macOS and Linux
curl -fsSL https://chatgpt.com/codex/install.sh | sh
Our run on November 23, 2026:
==> Installing Codex CLI
==> Detected platform: macOS (Apple Silicon)
==> Resolved version: 0.171.0
==> Downloading Codex CLI
==> Installing standalone package to ~/.codex/packages/standalone/releases/0.171.0-aarch64-apple-darwin
==> Current terminal: export PATH="~/.local/bin:$PATH" && codex
==> Future terminals: open a new terminal and run: codex
==> PATH was added to ~/.zprofile
Codex CLI 0.171.0 installed successfully.
The installer puts a codex command in ~/.local/bin and adds that folder to your PATH for you, in ~/.zprofile on a Mac. That only applies to new terminal windows, so open one before running codex. To update later, run the same command again or codex update.
The script downloads from OpenAI's release server and falls back to GitHub Releases if that fails. If it finds an existing npm, Homebrew or bun install, it warns Multiple managed Codex installs can be ambiguous and, when run interactively, offers to remove the old one. Saying yes saves you trouble later.
Download Codex for Mac or Linux without an installer
If you'd rather not pipe a script into your shell, download the archive for your machine from the latest GitHub release:
| Machine | File |
|---|---|
| Mac with Apple silicon | codex-aarch64-apple-darwin.tar.gz |
| Intel Mac | codex-x86_64-apple-darwin.tar.gz |
| Linux x86_64 | codex-x86_64-unknown-linux-musl.tar.gz |
| Linux arm64 | codex-aarch64-unknown-linux-musl.tar.gz |
The release page lists dozens of files with similar names (codex-app-server-…, codex-package-… and so on), so match the name exactly. Each archive holds a single binary named after the platform. Rename it to codex and move it to a folder on your PATH, such as ~/.local/bin. You update this kind of install by downloading the next release yourself. We confirmed these four files exist in the 0.171.0 release but installed with npm and the script, not from an archive.
Install on Windows
Open PowerShell and run:
powershell -ExecutionPolicy ByPass -c "irm https://chatgpt.com/codex/install.ps1 | iex"
The -ExecutionPolicy ByPass part only relaxes PowerShell's script policy for this one command and doesn't change your system settings. Codex installs to %LOCALAPPDATA%\Programs\OpenAI\Codex\bin and runs natively on Windows with its own sandbox. You don't need WSL, though Codex works inside WSL2 too.
We didn't test on Windows. These steps follow OpenAI's documentation as of November 2026.
Install with npm or Homebrew
npm works on every platform:
npm install -g @openai/codex
npm installs the @openai/codex wrapper plus the native binary for your platform (on our Mac, @openai/codex-darwin-arm64). The package declares Node.js 16 or later; we installed 0.171.0 with Node 22. Avoid sudo npm install -g, which leaves root-owned files that break later updates.
Homebrew on macOS:
brew install --cask codex
Note that it's a cask (--cask), not a regular formula. The cask was current when we checked on November 23, 2026 (0.171.0, same as npm).
Verify the install
Open a new terminal:
codex --version
codex-cli 0.171.0
If you see an older number, another copy of Codex is earlier on your PATH; see two installs.
For a full health check, run codex doctor. It inspects the install, config, sign-in, network, Git and sandbox without starting a session. On a fresh npm install of 0.171.0 that isn't signed in yet, the top of the report looked like this (shortened):
Codex Doctor v0.171.0 · macos-aarch64
Notes
✗ auth no Codex credentials were found - Run codex login or provide an API key through a supported auth env var.
⚠ websocket Responses WebSocket failed; HTTPS fallback may still work - Check proxy, VPN, firewall, DNS, custom CA, and WebSocket policy support.
…
✓ runtime npm (…)
✓ install consistent
The auth failure goes away once you sign in. The websocket warning means Codex couldn't open a WebSocket connection. We saw it on a signed-out install behind a proxy. It isn't fatal, because Codex falls back to plain HTTPS. If it persists after you sign in, check your proxy, VPN or firewall, as the message suggests.
Sign in
Run codex inside a project folder. On first launch you choose:
- Sign in with ChatGPT to use your plan. A browser window opens and hands the credentials back to the CLI.
- An API key for usage-based billing. Pipe it in so it doesn't sit in your shell history as an argument:
printenv OPENAI_API_KEY | codex login --with-api-key
Codex replies API key saved. Authentication is checked when you send a request., so a wrong key only shows up on your first prompt. codex login status shows which method is active, and codex logout clears saved credentials. They're stored in ~/.codex/auth.json, which the CLI and the IDE extension share.
Set up config.toml
Where it lives
| Scope | Path | Notes |
|---|---|---|
| Your defaults | ~/.codex/config.toml (Windows: %USERPROFILE%\.codex\config.toml) |
Create it if it doesn't exist. Moves with CODEX_HOME if you set that |
| One project | .codex/config.toml in the repo |
Only loaded for projects you've marked as trusted |
| A profile | ~/.codex/<name>.config.toml |
Applied when you run codex --profile <name> |
In the VS Code extension, the gear icon → Codex Settings → Open config.toml opens the same user file. The CLI and the extension read the same configuration.
When the same key is set in several places, the more specific one wins: command-line flags, then project config (the folder closest to where you're working), then the profile you selected, then your user config, then system defaults.
A starter config
# ~/.codex/config.toml
model = "gpt-6.1-sol" # default model
model_reasoning_effort = "medium" # low | medium | high (levels depend on the model)
approval_policy = "on-request" # ask before risky actions; "never" for unattended runs
sandbox_mode = "workspace-write" # read-only | workspace-write | danger-full-access
web_search = "cached" # cached (default) | indexed | live | disabled
What each one does:
| Key | What it controls |
|---|---|
model |
Which model Codex uses by default. /model switches it mid-session |
model_reasoning_effort |
How long the model thinks before answering. Higher means slower and more tokens |
approval_policy |
When Codex stops to ask you. untrusted is no longer supported and on-failure is deprecated. Use on-request or never |
sandbox_mode |
What commands can touch. workspace-write lets Codex edit your project but not the rest of the disk |
web_search |
cached serves results from an OpenAI-maintained search index without fetching pages, live fetches pages in real time, disabled removes the search tool. See web access |
TOML is picky: text values need straight double quotes ("gpt-6.1-sol", not gpt-6.1-sol), and a single mistake stops Codex from starting. The error tells you the line and column. See string values must be quoted.
Override settings for one run
codex --model gpt-6.1-sol
codex --config model_reasoning_effort='"high"'
The value after --config is TOML, which is why strings need the inner double quotes.
Give Codex web access
By default (web_search = "cached") Codex searches an OpenAI-maintained index and doesn't open live web pages. To let it fetch pages in real time:
codex --search # this session only
codex exec -c web_search='"live"' "…" # non-interactive runs; exec has no --search flag
Or make it permanent in ~/.codex/config.toml:
web_search = "live"
Two things to know, both from OpenAI's config reference:
- With a full-access sandbox (
danger-full-accessor--yolo), the default is alreadylive. - This setting only controls Codex's search tool. Shell commands that Codex runs, like
curlornpm install, are still blocked from the network in theworkspace-writesandbox unless you add:
[sandbox_workspace_write]
network_access = true
We checked that --search is listed in codex --help and that Codex 0.171.0 loads web_search = "live" with --strict-config. We didn't run a live search, since that needs a signed-in account.
Profiles
Profiles are named sets of overrides. Since Codex 0.134.0, each one is a separate file. To create a deep-review profile:
# ~/.codex/deep-review.config.toml
model_reasoning_effort = "high"
approval_policy = "on-request"
codex --profile deep-review
Only put the keys that differ from your main config.toml. Write them at the top level, not under a [profiles.deep-review] header.
Custom providers and API gateways
Codex can send requests to any service that implements the OpenAI Responses API (/v1/responses):
| Service | Base URL | Works with Codex? |
|---|---|---|
| A gateway that serves GPT models over the Responses API, e.g. api.foo | https://api.foo/v1 |
Yes |
| OpenRouter | https://openrouter.ai/api/v1 |
Yes, it offers /responses (FAQ, checked November 1, 2026); billed in USD, and GPT models are region-restricted for users in mainland China |
| DeepSeek's official API | https://api.deepseek.com/ |
Yes, natively; follow DeepSeek's Codex guide for its models.json catalog |
| Providers with Chat Completions only | — | Not directly. Codex dropped wire_api = "chat"; add a local translating proxy or switch providers |
Using Cursor instead? Its custom base URL works differently — requests leave from Cursor's servers and use Chat Completions. See Cursor API key setup.
There are two ways to set it up.
Option 1: change the base URL of the built-in provider. This is the simplest if you only use one provider:
model = "gpt-6.1-sol"
openai_base_url = "https://api.foo/v1"
Then sign in with that provider's key:
printf 'sk-your-key' | codex login --with-api-key
Option 2: define a named provider. Use this to keep your ChatGPT sign-in as the default and switch to the provider only when you want to. Putting it in a profile file means plain codex stays on ChatGPT:
# ~/.codex/apifoo.config.toml
model = "gpt-6.1-sol"
model_provider = "apifoo"
[model_providers.apifoo]
name = "api.foo"
base_url = "https://api.foo/v1"
env_key = "APIFOO_API_KEY"
export APIFOO_API_KEY="sk-your-key"
codex --profile apifoo
The examples use api.foo, the API gateway that publishes these docs. Swap in your own provider's URL and key. To check the wiring before spending anything, we ran both options with a deliberately wrong key, first on Codex 0.162.1 and most recently on 0.171.0 on November 23, 2026, using codex exec. Each request reached the gateway, and the gateway rejected the key:
model: gpt-6.1-sol
provider: apifoo
ERROR: unexpected status 401 Unauthorized: 无效的令牌 (request id: …), url: https://api.foo/v1/responses
Before that final line you may see a few Reconnecting... 1/5 lines or a note about Falling back from WebSockets to HTTPS transport; Codex retries before giving up. The url in the error is the provider's address and the error text comes from the provider, which tells you the config works and only the key is wrong. (api.foo returns this message in Chinese by default. It means "invalid token".)
Things to get right:
- Include
/v1in the base URL. Codex appends/responsesdirectly to it. - Use a model name the provider actually offers.
- Provider settings only work in your user config or a profile. Codex ignores
openai_base_url,model_providerandmodel_providersin a project's.codex/config.tomland prints a warning. env_keyreads an environment variable. Apps launched from the macOS Dock, including VS Code, may not see variables set in~/.zshrc. If the extension reports a missing variable, use Option 1.
Fix common errors
command not found: codex
The installer added ~/.local/bin to your PATH in ~/.zprofile, but terminal windows that were already open don't pick that up. Open a new one. On Linux with bash, make sure export PATH="$HOME/.local/bin:$PATH" is in ~/.bashrc or ~/.profile. For npm installs, the bin folder under npm config get prefix must be on PATH.
Two installs, wrong one runs
WARNING: Multiple managed Codex installs can be ambiguous because PATH order decides which one runs.
Run which -a codex (where.exe codex on Windows) to list them, then uninstall all but one. The install method line in codex doctor shows which one is running.
spawn … ENOENT
Error: spawn …/node_modules/@openai/codex/node_modules/@openai/codex-darwin-arm64/vendor/aarch64-apple-darwin/codex/codex ENOENT
We hit this ourselves on an old npm install: the platform binary inside the npm package was missing. Reinstalling the latest version fixed it:
npm install -g @openai/codex@latest
wire_api = "chat" is no longer supported
Error loading config.toml: `wire_api = "chat"` is no longer supported.
How to fix: set `wire_api = "responses"` in your provider config.
Delete the wire_api line, since responses is the default. If your provider then returns 404, it doesn't support the Responses API and won't work with current Codex.
--profile can't be used with a legacy [profiles] table
Error loading config.toml: --profile `apifoo` cannot be used while …/config.toml contains legacy `profile = "apifoo"` or `[profiles.apifoo]` config; move those settings into …/apifoo.config.toml and remove the legacy profile selector/table.
Move the keys from [profiles.apifoo] into ~/.codex/apifoo.config.toml at the top level, then delete the table and any profile = "…" line from config.toml.
Error loading config.toml: string values must be quoted
Error loading config.toml:
…/config.toml:1:9: string values must be quoted, expected literal string
|
1 | model = gpt-6.1-sol
| ^^^^^^^^^^^
Add straight double quotes around the value. Curly quotes pasted from a web page or document cause the same error.
Missing environment variable: APIFOO_API_KEY
Your provider uses env_key, but Codex can't see that variable. Export it in your shell profile and open a new terminal. On Windows, run setx APIFOO_API_KEY "sk-…" and reopen PowerShell. For editor extensions, switch to Option 1 above.
401 Unauthorized
The request reached the provider but the key was rejected. Usually that's a missing character, a stray space, or a key from a different provider. Sign in again with codex login --with-api-key.
Update and uninstall
| Installed with | Update | Uninstall |
|---|---|---|
| Standalone (macOS/Linux) | codex update or rerun the installer |
rm -f ~/.local/bin/codex ~/.local/bin/codex-code-mode-host and rm -rf ~/.codex/packages/standalone |
| npm | npm install -g @openai/codex@latest |
npm uninstall -g @openai/codex |
| Homebrew | brew upgrade --cask codex |
brew uninstall --cask codex |
The standalone installer also adds a block to ~/.zprofile between # >>> Codex installer >>> and # <<< Codex installer <<<, which you can delete. Uninstalling never touches ~/.codex, where your config, credentials and chat history live. Delete that folder only if you want a clean slate.
Related
FAQ
Is Codex CLI free?
The CLI is free to install, but it needs model access. Codex in the CLI and IDE extension is included with ChatGPT Plus ($20/month) and higher plans. The Free and Go plans only get limited Codex access in the ChatGPT desktop app. You can also sign in with an OpenAI API key and pay standard API rates, or point Codex at a compatible provider.
Do I need Node.js to install Codex CLI?
No. The standalone installer (curl -fsSL https://chatgpt.com/codex/install.sh | sh on macOS and Linux, or the PowerShell command on Windows) installs a self-contained binary. Node.js is only needed for the npm install method.
Where is the Codex config.toml file?
Your personal config is ~/.codex/config.toml on macOS and Linux and %USERPROFILE%\.codex\config.toml on Windows. If you set CODEX_HOME, it lives there instead. Trusted projects can add a .codex/config.toml in the repository, but it can't change the model provider or credentials.
How do I use Codex with a custom API base URL?
To keep the built-in OpenAI provider and only change the address, add openai_base_url = "https://your-provider/v1" to config.toml and sign in with codex login --with-api-key. For a separate named provider, define a [model_providers.<id>] table with base_url and env_key and set model_provider to that id. The provider must support the OpenAI Responses API.
Which third-party APIs work with Codex?
Only services that implement the OpenAI Responses API (/v1/responses). Examples are multi-model gateways that serve GPT models (for api.foo, base_url = "https://api.foo/v1"), OpenRouter (https://openrouter.ai/api/v1) and DeepSeek's official API, which needs its own model catalog file. Providers that only offer Chat Completions no longer work, because Codex removed wire_api = "chat".
What does "wire_api = chat is no longer supported" mean?
Your config still has wire_api = "chat" from an older guide. Current Codex only talks to the Responses API (/v1/responses). Delete the line or set wire_api = "responses". If the provider only offers Chat Completions, it won't work with current Codex.
How do I give Codex web access in the CLI?
Start it with codex --search for one session, or add web_search = "live" to ~/.codex/config.toml to keep it on. The default, "cached", answers from an OpenAI-maintained search index without fetching live pages, and "disabled" turns search off. For codex exec, pass -c web_search='"live"'. This only covers the search tool; letting shell commands reach the network in the workspace-write sandbox is a separate setting, network_access = true under [sandbox_workspace_write].
Can I run Codex on Windows without WSL?
Yes. Run the PowerShell installer and Codex runs natively with its own Windows sandbox. WSL2 is optional, for projects that live in Linux.
How do I update Codex CLI?
For the standalone install, run codex update or rerun the install command. For npm, run npm install -g @openai/codex@latest. For Homebrew, run brew upgrade --cask codex.
Found a mistake? Email support@api.foo.