How to install and set up Codex CLI (Windows, macOS and Linux)
Checked against the official docs:
[Codex CLI](/plugins/codex-cli/) is OpenAI's open-source coding agent that runs in your terminal. You start it inside a project folder, tell it what you want in plain words, and it reads the code, makes changes and runs commands there. This guide covers installing it on Windows, macOS and Linux, signing in, your first task, keeping it updated, and the errors people run into most. It was checked against OpenAI's Codex docs and the openai/codex README on 27 November 2026, when the current release was 0.172.0.
Get new guides by email
New MCP servers and agent tools, checked by hand. Free, unsubscribe anytime.
Paid prompt and rules packs are on the packs page.
Quick answer
- macOS or Linux: run
curl -fsSL https://chatgpt.com/codex/install.sh | sh. Windows: in a new PowerShell window, runpowershell -ExecutionPolicy ByPass -c "irm https://chatgpt.com/codex/install.ps1 | iex". - Open a new terminal,
cdinto your project and runcodex. - Choose Sign in with ChatGPT and finish signing in in the browser window that opens.
- Type what you want, for example "Tell me about this project".
Free: MCP Starter Checklist
One page: Inspector smoke-test, Claude Code + Cursor connect steps, and the stdout gotcha. Join the list and download it free.
What you need
- A ChatGPT plan or an OpenAI API key. The README recommends signing in with ChatGPT so Codex usage comes out of your Plus, Pro, Business, Edu or Enterprise plan. An API key works too, billed at standard API rates.
- macOS, Linux or Windows. On Windows, OpenAI recommends Windows 11. A fully updated Windows 10 (version 1809 or newer) works on a best-effort basis, and winget should be available.
- 4 GB of RAM at least (8 GB recommended), per the install notes in the Codex repository.
- Git is optional but recommended. The install notes ask for Git 2.23 or newer for the built-in pull request helpers.
- Node.js only if you install with npm. The
@openai/codexpackage needs Node.js 16 or newer. The standalone installers and Homebrew don't need Node.
1. Install Codex CLI
macOS and Linux
curl -fsSL https://chatgpt.com/codex/install.sh | shThe installer puts codex in ~/.local/bin and adds that folder to your PATH in your shell profile. It works for new terminals, so open a new one when it finishes (the installer also prints a line you can paste to use codex in the current terminal).
Windows
Open a new PowerShell window and run:
powershell -ExecutionPolicy ByPass -c "irm https://chatgpt.com/codex/install.ps1 | iex"It installs Codex into %LOCALAPPDATA%\Programs\OpenAI\Codex\bin. Open a new PowerShell window afterwards and run codex. Codex runs natively on Windows with its own sandbox, so you don't need WSL. OpenAI suggests WSL only if you need Linux tools or already work inside WSL2.
npm or Homebrew
You can also install it with a package manager:
# npm (any OS with Node.js)
npm install -g @openai/codex
# Homebrew (macOS)
brew install --cask codexCheck that it worked:
codex --version2. Sign in
Run codex (or codex login) and choose Sign in with ChatGPT. A browser window opens. After you sign in, the browser hands the login back to Codex and you're ready to go. Codex keeps you signed in and refreshes the session on its own.
Use an API key instead
Create a key in the OpenAI dashboard, put it in the OPENAI_API_KEY environment variable, and pipe it into Codex:
printenv OPENAI_API_KEY | codex login --with-api-keyAPI key usage is billed through your OpenAI Platform account at API rates, not from your ChatGPT plan. Some features that rely on ChatGPT, such as Codex cloud, are limited or unavailable with a key.
On a remote server or a machine without a browser
Use device code sign-in (beta): run codex login --device-auth, open the link it shows on any device, sign in and enter the one-time code. If that option isn't available, turn on device code login in your ChatGPT security settings first (a workspace admin controls it for business accounts).
codex login --device-authCheck or clear your sign-in
codex login status prints how you're signed in. codex logout clears the saved login. Codex stores it in ~/.codex/auth.json or your system's credential store. Treat auth.json like a password: don't commit it or paste it anywhere.
3. Run your first task
Go to a project folder and start Codex there:
cd my-project
codexThen type a request in plain words, such as "Tell me about this project" or "Find out why the login test fails and fix it". OpenAI suggests making a Git commit before and after a task so you can undo anything you don't like.
Handy commands inside Codex:
/initcreates anAGENTS.mdfile with instructions for Codex. See Cursor rules vs AGENTS.md for what to put in it./modelpicks the model and reasoning effort./permissionssets what Codex may do without asking you first./statusshows the current session settings./reviewreviews your changes and lists problems./mcplists the MCP servers Codex can use.
From the terminal, codex resume reopens a recent chat, and codex exec "your task" runs Codex without the interactive screen, for scripts and CI. To connect tools such as GitHub or Context7, see how to add an MCP server to Codex.
4. Update Codex
codex update checks for a new version and installs it, when your install supports updating itself. Otherwise, update the same way you installed:
# Standalone installer (macOS / Linux): run it again
curl -fsSL https://chatgpt.com/codex/install.sh | sh
# npm
npm install -g @openai/codex
# Homebrew
brew upgrade --cask codexOn Windows, run the PowerShell install command again from a new PowerShell window.
Common errors and fixes
"codex: command not found" or "codex is not recognized"
Open a new terminal or PowerShell window. The installer adds Codex to your PATH for new windows only. If it still isn't found, check that ~/.local/bin (macOS and Linux) or %LOCALAPPDATA%\Programs\OpenAI\Codex\bin (Windows) is on your PATH.
The browser sign-in never finishes
This happens on remote or headless machines, or when your network blocks the localhost address Codex uses to receive the login. Use codex login --device-auth. If you're connected over SSH and can forward ports, you can also forward Codex's callback port and sign in normally:
ssh -L 1455:localhost:1455 user@remoteThen run codex login in that SSH session and open the address it prints on your own computer. Each codex login run also writes a codex-login.log file in your Codex log folder, which helps if you need support.
Certificate errors on a company network
If your network uses a TLS proxy or a private root certificate, point CODEX_CA_CERTIFICATE at the PEM bundle before you sign in, for example export CODEX_CA_CERTIFICATE=/path/to/corporate-root-ca.pem and then codex login.
Windows sandbox setup fails
Codex runs commands on Windows inside a sandbox. The "elevated" sandbox needs you to approve a Windows administrator prompt during setup. If setup fails, run it again and approve the prompt. On a company laptop, IT may block the steps it needs (creating local sandbox users, firewall rules and logon rights), so ask them.
On Windows 11 builds that support Microsoft's newer MXC isolation, Codex can use a sandbox that needs no admin setup. For the CLI, turn it on in config.toml:
[features]
prefer_mxc = trueSomething else is wrong
Run codex doctor. It builds a diagnostic report covering your install, config, sign-in, Git and terminal.
FAQ
Is Codex CLI open source?
Yes. The code is on GitHub at openai/codex under the Apache-2.0 license. Using it still needs a ChatGPT plan or an API key.
Do I need WSL on Windows?
No. Codex CLI installs and runs natively in PowerShell. WSL is an option if your work already lives there.
Can I use Codex in VS Code or Cursor?
Yes. OpenAI has a Codex IDE extension for VS Code, Cursor and Windsurf. It shares its saved login with the CLI, so signing out of one signs you out of both.
Where are the settings?
In ~/.codex/config.toml. The CLI, IDE extension and desktop app all read it. The Codex MCP guide shows how to add servers there.
Sources
Commands and config above come from these official docs. Tools change often, so check them for the latest steps.
- openai/codex README (install commands, sign-in, plans)
- openai/codex docs: Installing & building (system requirements)
- Codex CLI docs (install and update commands, quickstart)
- Codex docs: Authentication (ChatGPT, API key, device code, headless login)
- Codex docs: Command reference (update, doctor, login status, exec, slash commands)
- Codex docs: Windows sandbox (version support, sandbox setup errors)
- Codex docs: Troubleshooting (codex --version)
- Codex releases (0.172.0)
PluginStack is independent and not affiliated with or endorsed by the companies mentioned. Spotted something out of date? Email pluginstackai@gmail.com.
Related guides
Tools in this guide
- Coding Agents · OpenAI
Codex CLI
OpenAI's open-source coding agent that runs locally in your terminal. It reads and edits your code, runs commands and connects to MCP servers. Codex also comes as an IDE extension (VS Code, Cursor, Windsurf), a desktop app and a cloud version. Apache-2.0.
- Coding Agents · Anthropic
Claude Code
Anthropic's agentic coding tool. It reads your codebase, edits files, runs commands, works with git and connects to MCP servers. It runs in the terminal, with VS Code/JetBrains extensions, a desktop app and a web version too.
- Coding Agents · Anomaly
OpenCode
An open-source AI coding agent with a terminal UI, a desktop app for macOS, Windows and Linux, and a web interface. It works with many LLM providers, and OpenCode also sells its own model access (OpenCode Console and the OpenCode Go plan). It ships a build agent that makes changes and a plan agent that plans without editing your project files. The current version is OpenCode 2. The code is on GitHub at anomalyco/opencode. MIT licensed.
- Editor Extensions · Cline
Cline
Open-source coding agent for VS Code (also JetBrains, a CLI and a desktop app). It edits files across your project, runs terminal commands and uses a browser, with Plan/Act modes and approval for every change unless you turn on auto-approve.
Get new guides by email
New MCP servers and agent tools, checked by hand. Free, unsubscribe anytime.
Paid prompt and rules packs are on the packs page.