How to install Codex CLI on Mac and Windows (and sign in with ChatGPT)
Install OpenAI's Codex CLI on macOS or Windows, sign in with your ChatGPT plan instead of an API key, log in on a headless machine, and set up AGENTS.md.
To install Codex CLI on a Mac, run curl -fsSL https://chatgpt.com/codex/install.sh | sh in Terminal. On Windows, run powershell -ExecutionPolicy ByPass -c "irm https://chatgpt.com/codex/install.ps1 | iex" in a new PowerShell window. npm (npm install -g @openai/codex) and Homebrew (brew install --cask codex) work too. Then open a project folder, run codex, and choose Sign in with ChatGPT: no API key needed, but the CLI needs ChatGPT Plus or higher. That’s all from OpenAI’s Codex CLI docs, checked on October 4, 2026.
Codex CLI is OpenAI’s coding agent for the terminal: it reads your repository, edits files and runs commands, on your ChatGPT plan or an API key.
I’ve used Codex heavily for about four months, mostly to review what Claude Code builds. This is the setup I’d give a friend, with the parts the quick-start skips: which plan you need, how to log in on a machine with no browser, and how to check it worked.
Before you install: which ChatGPT plan includes the CLI
| Plan | Price (US) | Codex CLI | What OpenAI lists for Codex |
|---|---|---|---|
| Free | $0 | No | Quick coding tasks in the desktop app, subject to rollout |
| Go | $8 a month | No | Lightweight tasks in the desktop app, subject to rollout |
| Plus | $20 a month | Yes | Web, CLI, IDE extension and iOS; “a few focused coding sessions each week” |
| Pro | From $100 a month | Yes | Everything in Plus, with more usage |
| API key | Pay per use | Yes | CLI, SDK and IDE extension, at API rates; no cloud features |
Source: Codex pricing. Business and Enterprise plans include it too. For what each plan includes and how the limits work, and what you can do without paying, see my Codex pricing guide.
Install Codex CLI on a Mac
Option 1: the install script (OpenAI’s first choice)
curl -fsSL https://chatgpt.com/codex/install.sh | shI read the script before writing this. By default it puts the codex command in ~/.local/bin, keeps the actual releases under ~/.codex/packages/standalone, and adds ~/.local/bin to your PATH in your shell profile (~/.zprofile on a Mac with the default zsh shell). My own Mac has this kind of install (~/.local/bin/codex is a link into ~/.codex/packages/standalone):
$ which codex~/.local/bin/codex$ codex --versioncodex-cli 0.160.0Open a new terminal after installing, so the PATH change applies. To update later, run the same command again.
Option 2: Homebrew
brew install --cask codexUpdate with brew upgrade --cask codex. The cask is codex, and it installs the same CLI.
Option 3: npm
If you already have Node.js, npm works on every platform. This is the one I ran, into a throwaway folder (--prefix) so it didn’t touch my real install:
$ npm install --prefix ./codex-test @openai/codexadded 2 packages in 28s$ ./codex-test/node_modules/.bin/codex --versioncodex-cli 0.160.0The two packages are the small @openai/codex launcher and the native binary for your platform (@openai/codex-darwin-arm64 on an Apple Silicon Mac). For a normal install, use npm install -g @openai/codex; update with the same command.
Pick one method and stay with it. If the install script finds a Codex installed by npm, Bun or Homebrew, it asks whether to uninstall that one; if you keep both, whichever comes first in your PATH is the one that runs.
Install Codex CLI on Windows
Open a new PowerShell window and run:
powershell -ExecutionPolicy ByPass -c "irm https://chatgpt.com/codex/install.ps1 | iex"On my Windows 11 machine it took 39 seconds and printed this:
==> Installing Codex CLI==> Detected platform: Windows (ARM64)==> Resolved version: 0.160.0==> Downloading Codex CLI==> PATH updated for future PowerShell sessions.==> Current PowerShell session: codex==> Future PowerShell windows: open a new PowerShell window and run: codexCodex CLI 0.160.0 installed successfully.It puts codex.exe in %LOCALAPPDATA%\Programs\OpenAI\Codex\bin and adds that folder to your user PATH. As the last line says, other PowerShell windows that were already open won’t find codex until you open a new one.
npm works on Windows too: npm install -g @openai/codex. On the same machine it installed two packages, @openai/codex and @openai/codex-win32-arm64 (on an Intel or AMD PC it’s the x64 one), in 41 seconds.
The first time you run codex and sign in, Codex sets up its Windows sandbox. On my machine Windows showed an administrator prompt (the “allow this app to make changes” dialog); I clicked Yes, and Codex said:
• Sandbox ready Codex can now safely edit files and execute commands in your computerAfter that, config.toml in your Codex folder (%USERPROFILE%\.codex) has sandbox = "elevated" under [windows]: that’s the stronger of the two sandbox modes.
What OpenAI’s Windows sandbox page adds:
- Windows 11 is recommended. A recent, fully updated Windows 10 is “best effort”, and needs version 1809 or newer.
wingetshould be available. If it’s missing, update Windows or install the Windows Package Manager first.- What the sandbox does. Natively, Codex runs commands in a Windows sandbox that blocks writes outside your project folder and network access without your approval. If you can’t approve the administrator prompt (on a work machine, say), there’s a weaker fallback mode that doesn’t need it.
Or inside WSL2
If your projects live in Linux, or the native sandbox won’t set up on a managed machine, run Codex inside WSL2 instead (Codex on WSL). From an administrator PowerShell, install WSL and open it:
wsl --installwslThen, inside the WSL shell, use the Linux install script:
curl -fsSL https://chatgpt.com/codex/install.sh | shcodexKeep your repositories under your Linux home directory (~/code/...), not under /mnt/c/...: OpenAI notes the Windows-mounted paths are slower. WSL1 isn’t supported anymore.
If you also want Claude Code on the same machine, here’s Claude Code on Windows, including the PATH step.
Sign in with ChatGPT
In a project folder, run codex. The first time, it asks how to sign in: choose Sign in with ChatGPT, and a browser window opens. After you sign in, the browser hands the credentials back to the CLI (authentication docs). You can also start the same flow on its own:
codex loginCheck where you stand with codex login status. On the throwaway npm install, which had never signed in, it printed this and exited with code 1 (0 when you’re signed in, which makes it handy in scripts):
$ codex login statusNot logged inCodex keeps the login in ~/.codex/auth.json or in your system’s credential store. OpenAI’s advice: treat auth.json like a password. Don’t commit it, paste it into a ticket or share it in chat. codex logout removes it.
On a server, over SSH, or in a container
The browser sign-in needs a browser on the same machine and a free local port for the callback. Without one, use the device code flow:
codex login --device-authIt prints a link and a one-time code: open the link on your laptop or phone, sign in, enter the code. Two catches from the docs: it’s in beta, and you have to turn on device code login first, in your ChatGPT security settings (on a work account, your workspace admin does it). If that’s not possible, the docs give two fallbacks: copy ~/.codex/auth.json from a machine where you signed in, or forward the callback port with ssh -L 1455:localhost:1455 user@remote and sign in through the tunnel.
With an API key instead
printenv OPENAI_API_KEY | codex login --with-api-keyThat bills the API account at API rates instead of your ChatGPT plan, and some features that need a ChatGPT workspace aren’t available. OpenAI recommends it for CI and other automation.
Check that everything works
codex doctor checks the install, the sign-in, the network and the tools Codex needs. On my throwaway install, signed out, the first lines were:
$ codex doctorCodex Doctor v0.160.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.The rest of its report lists the platform, how Codex was installed, which git it found and the terminal it’s in. The auth line goes away once you sign in. I didn’t dig into the WebSocket warning: the docs say the HTTPS fallback may still work, and the throwaway install never sent a request.
First run: AGENTS.md
Codex reads AGENTS.md files before it does any work: a global one in ~/.codex/AGENTS.md for your own habits, and one at the root of each repository for the project’s rules (AGENTS.md docs). Run /init inside a Codex session to generate a starting file. Keep it short: how to run the tests, what not to touch, the conventions an outsider would get wrong.
Two other commands worth knowing from day one: /review asks Codex to review your uncommitted changes, and codex resume reopens a previous session.
Using Codex next to Claude Code
That’s how I use it: Claude Code builds, Codex reviews the plan and the diff, read-only. Both can read the same AGENTS.md: Codex natively, and Claude Code (v2.1.277 or later) when the repository has no CLAUDE.md. If you also keep a CLAUDE.md, put @AGENTS.md at the top of it, or Claude reads only CLAUDE.md (Claude Code memory docs). Then one rules file serves both agents.
If you run them at the same time, give each its own git worktree so they don’t edit the same folder; I wrote up how to set that up, and the pitfalls. Why I split the work this way, and what Codex catches that Claude misses, is in Codex vs Claude Code: one builds, one reviews.
Plyloft, the app I build, runs the official codex and claude CLIs on plans you already pay for, and does the copying between them for you. One plan is enough: with only ChatGPT, the reviewer is a second Codex session, and the card says so. Like the CLI, it needs ChatGPT Plus or higher; with Claude instead, Claude Pro or higher. Its setup can install Codex for you with OpenAI’s install script: it shows you the command and asks before it runs it.
If you’d rather have one place for both agents, download Plyloft and try the Free plan.
Questions people ask
Is Codex CLI free?
The CLI itself is open source, but using it needs a ChatGPT Plus plan or higher, or an OpenAI API key billed at API rates. On ChatGPT Free and Go, OpenAI lists Codex for quick tasks in the desktop app only, subject to rollout. Checked October 4, 2026. More in my post Is Codex free?
Do I need an OpenAI API key for Codex CLI?
No. Choose Sign in with ChatGPT the first time you run codex, or run codex login, and usage counts against your ChatGPT plan. An API key is an alternative, billed separately at API rates.
How do I log in to Codex CLI over SSH or on a server?
Run codex login --device-auth, open the link on any device with a browser, sign in and enter the one-time code. Device code login is in beta and has to be enabled first in your ChatGPT security settings (or by a workspace admin).
Does Codex CLI work on Windows?
Yes, natively in PowerShell with a Windows sandbox, or inside WSL2. OpenAI recommends Windows 11; a fully updated Windows 10 (1809 or newer) is best effort. WSL1 is no longer supported.
How do I update Codex CLI?
Run the same command you installed with: the install script again, npm install -g @openai/codex, or brew upgrade --cask codex. The CLI also has a codex update command.