# Installing Codex CLI and signing in

Course: Codex from Zero — https://zero2vibecode.com/learn/codex
Canonical URL: https://zero2vibecode.com/learn/codex/0-1-install-codex-cli
Verified against: Codex CLI v0.163.0 (2026-10-22)
Last updated: 2026-10-22

Codex CLI is one program called codex that lands in a folder your shell searches. Install it with the official script, npm or Homebrew, then sign in with your ChatGPT account or an API key the first time you run it.

Codex is OpenAI's coding agent, and it comes in several shapes: an editor extension, a desktop app, a cloud version you reach through ChatGPT. This course is about one of them, **Codex CLI**, the agent that runs in your terminal. Everything here applies to that one.

## What the install actually does

It puts one program, `codex`, into a folder that your shell searches when you type a command name. That list of folders is your PATH.

The program does not watch your files in the background. It starts when you type `codex`, works in the folder you started it from, and stops when you close it.

## Install it

These commands come from the official [Codex CLI page](https://learn.chatgpt.com/docs/codex/cli) and the [project README](https://github.com/openai/codex). If one ever stops working, those two are the ones to trust.

**macOS or Linux** — the standalone installer:

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

**Windows** — open a new PowerShell window and run:

```text
powershell -ExecutionPolicy ByPass -c "irm https://chatgpt.com/codex/install.ps1 | iex"
```

**With a package manager**, if you already use one:

```bash
npm install -g @openai/codex
```

```bash
brew install --cask codex
```

The `-g` in the npm command means global: install it as a program for your whole user, not as a library inside one project.

Updating is the same move as installing. Run the installer script again, or the same `npm install -g` command; with Homebrew it is `brew upgrade --cask codex`.

Then open a **new** terminal window and check it worked:

```bash
codex --version
```

A version number means you are done. `command not found` (or "not recognized" on Windows) almost always means the terminal you are in was opened before the install added its folder to your PATH. A new window fixes that more often than anything else.

## Try the PATH idea for yourself

Run `echo $PATH` below to see the folders your shell searches, then install Codex the npm way. The simulator does not run the real agent, but the install command is the real one.

## The first run: signing in

The model does not run on your machine; it runs on OpenAI's side, so the first time you start `codex` it needs to know who you are. Open a project folder, run `codex`, and pick one of two answers.

**Sign in with ChatGPT.** Codex opens a browser window, you sign in there, and the browser hands the credentials back to the terminal. OpenAI recommends this route if you have a ChatGPT plan that includes Codex — the README names Plus, Pro, Business, Edu and Enterprise. What each plan includes changes over time, so check OpenAI's [Codex in ChatGPT](https://help.openai.com/en/articles/11369540-codex-in-chatgpt) page rather than trusting a list in a course.

**Sign in with an API key.** Usage is then billed through your OpenAI Platform account at API rates, and some features that depend on a ChatGPT workspace or the cloud side are limited. The key travels through a pipe from an environment variable, so the key itself is never part of a command you type:

```bash
printenv OPENAI_API_KEY | codex login --with-api-key
```

**Keys are passwords.** 
An API key is a password with a bill attached. Keep it in an environment variable or a .env file that Git ignores, never in a source file, and never in a commit.

## Three commands for day one

`codex login status` tells you how you are signed in right now. When something behaves as if you are on the wrong account, start there.

`codex logout` clears the cached login. Codex keeps it in `~/.codex/auth.json` or in your operating system's credential store, and reuses it every session, so you do not sign in daily.

`codex --help` lists everything else. Reading `--help` before a tutorial is a habit that will outlast every command in this lesson.

**Do I need a paid plan to use Codex CLI?**

You need either a ChatGPT plan that includes Codex, or an OpenAI API key billed at API rates. OpenAI recommends signing in with ChatGPT and lists the plans that include Codex on its help page, which is the place to check what yours covers today. The lessons on this site run in a browser simulator and need neither.

**Should I install with the script, npm or Homebrew?**

Any of them gives you the same codex command. The standalone script is the one the Codex docs lead with and needs nothing else installed. Use npm or Homebrew if you already manage your tools that way, and update Codex the same way you installed it.
