Ad space · Your tool here
PluginStack
Tutorial

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.

The newsletter hasn't started sending yet. Join the list now and we'll email you when the first issue goes out. From PluginStack (pluginstackai@gmail.com). Privacy policy.

Paid prompt and rules packs are on the packs page.

Quick answer

  1. macOS or Linux: run curl -fsSL https://chatgpt.com/codex/install.sh | sh. Windows: in a new PowerShell window, run powershell -ExecutionPolicy ByPass -c "irm https://chatgpt.com/codex/install.ps1 | iex".
  2. Open a new terminal, cd into your project and run codex.
  3. Choose Sign in with ChatGPT and finish signing in in the browser window that opens.
  4. 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.

Markdown download + occasional PluginStack updates. No spam. Privacy policy.

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/codex package needs Node.js 16 or newer. The standalone installers and Homebrew don't need Node.

1. Install Codex CLI

macOS and Linux

macOS / Linux
bash
curl -fsSL https://chatgpt.com/codex/install.sh | sh

The 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:

Windows (PowerShell)
powershell
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:

bash
# npm (any OS with Node.js)
npm install -g @openai/codex

# Homebrew (macOS)
brew install --cask codex

Check that it worked:

bash
codex --version

2. 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:

macOS / Linux
bash
printenv OPENAI_API_KEY | codex login --with-api-key

API 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).

bash
codex login --device-auth

Check 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:

bash
cd my-project
codex

Then 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:

  • /init creates an AGENTS.md file with instructions for Codex. See Cursor rules vs AGENTS.md for what to put in it.
  • /model picks the model and reasoning effort.
  • /permissions sets what Codex may do without asking you first.
  • /status shows the current session settings.
  • /review reviews your changes and lists problems.
  • /mcp lists 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:

bash
# 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 codex

On 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:

bash
ssh -L 1455:localhost:1455 user@remote

Then 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:

~/.codex/config.toml
text
[features]
prefer_mxc = true

Something 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.

PluginStack is independent and not affiliated with or endorsed by the companies mentioned. Spotted something out of date? Email pluginstackai@gmail.com.

Get new guides by email

New MCP servers and agent tools, checked by hand. Free, unsubscribe anytime.

The newsletter hasn't started sending yet. Join the list now and we'll email you when the first issue goes out. From PluginStack (pluginstackai@gmail.com). Privacy policy.

Paid prompt and rules packs are on the packs page.