# Install Codex CLI and run your first task in 15 minutes

URL: https://opcaios.org/en/blog/cai-codex-cli
Date: 2026-11-03
Author: Lê Quốc Nghĩa

Installing Codex CLI means downloading the command-line version of Codex, OpenAI's programming agent, to your machine, logging in, then opening it in a project folder to assign tasks by voice. This post is for non-programmers who only use commands found in the README at github.com/openai/codex, Codex documentation at learn.chatgpt.com/docs, and `codex --help` version 0.162.1, read on 03/11/2026. "15 minutes" is an estimate for a machine with stable internet and an existing ChatGPT account, not a guarantee: corporate proxy, Windows, or login errors may take longer. This post does not promise Codex will fix things correctly; it goes from system requirements to your first task, reading diffs, slash commands, and common errors.

![Diagram of installing Codex CLI in six steps: check system requirements, install via script, npm, or Homebrew, run codex login, open terminal in a project folder with git, assign read-only tasks, view /diff before accepting changes](https://opcaios.org/images/blog/cai-codex-cli/so-do.webp)
*Six steps from a blank machine to your first safe task, each step with a checkpoint. Diagram: OPCAIOS.*

## What does my machine need to install Codex CLI?

Your machine needs a supported operating system, enough memory, and should have git. According to the docs/install.md file in the github.com/openai/codex repository (read on 03/11/2026):

| Item | Requirement per documentation |
|---|---|
| Operating system | macOS 12 or later, Ubuntu 20.04+ or Debian 10+, Windows 11 via WSL2 |
| RAM | Minimum 4 GB, recommended 8 GB |
| Git | Not required, recommended version 2.23 or later |
| Account | ChatGPT account or OpenAI API key |

A key discrepancy to know: install.md says Windows 11 via WSL2, but the README and current Codex CLI page show an installer that runs directly in PowerShell. Windows users should follow the latest Codex CLI page. The pricing page on the same date notes CLI is included in the Plus plan or higher, or when using an API key. Plan prices are in the post [What is Codex](/blog/codex-la-gi).

## What are the ways to install Codex CLI?

Codex CLI has four official installation methods according to the README and Codex CLI page (read on 03/11/2026); pick one:

1. **Installation script on macOS and Linux,** run in Terminal:

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

2. **Installer on Windows,** run in a new PowerShell window:

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

3. **npm,** if your machine already has Node.js:

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

4. **Homebrew** on macOS:

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

Commands like `curl ... | sh` run the downloaded script immediately, so only paste the correct command from official documentation. After installing, open a new terminal window and type `codex --version`; our machine returned `codex-cli 0.162.1`. Update using the same method you installed with: run the script again, run the npm command again, or `brew upgrade --cask codex`; `codex --help` also has an `codex update` command.

## How do I log in to Codex CLI?

Logging in to Codex CLI has two paths: a ChatGPT account or an API key. According to the Authentication page in the Codex documentation (read on 03/11/2026), the first time you run `codex` you choose "Sign in with ChatGPT", or run `codex login` directly; your browser opens, you log in, and your browser returns the login info to the CLI. With an API key, the documentation shows passing the key via standard input instead of typing it on the command line:

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

`codex login status` shows which method you are logged in with; `codex logout` removes login info from a shared machine. Using an API key means costs are calculated by API pricing on your OpenAI Platform account, not using your ChatGPT plan limit. Login info is stored by default in `~/.codex/auth.json` as plain text or in your operating system's credential store. Do not share this file with anyone, do not put it in git, do not paste the key into a prompt. See also [security when using AI to write code](/blog/bao-mat-khi-dung-ai-viet-code).

## How do I open Codex CLI in my project directory?

Opening Codex CLI in the right directory decides what Codex reads and edits. Codex treats the directory you're standing in as the working directory, so go into your project directory before typing `codex`, or use the `-C` flag (long name `--cd`). According to the "Agent approvals & security" page (read on 03/11/2026), when starting Codex it checks if the directory has git: if it does, it suggests Auto mode (edit files and run commands in the working directory, ask when going outside or using the network); if not, it suggests read-only; depending on settings, Codex may stay read-only until you confirm trusting the directory. For newcomers, prepare in four steps:

1. Copy the real project to a separate directory.
2. Turn on git and create a first commit as a fallback point; Codex documentation recommends creating a git checkpoint before and after each task.
3. Don't put files containing passwords, keys, or customer data in the test directory.
4. Open a terminal in the directory and type `codex`.

How to write project instructions for Codex is in the post [What is AGENTS.md](/blog/agents-md-la-gi).

## How do I safely assign the first task to Codex?

The first safe task is a read-only one: Codex looks at the project and explains, without editing anything. The Codex CLI page suggests starting with a prompt like "Tell me about this project". To make sure Codex doesn't edit files, start in a read-only sandbox with two flags from the documentation and `codex --help`:

```bash
codex --sandbox read-only --ask-for-approval on-request
```

Suppose example for a small website, not a real project:

1. "Explain what this project does, what directories it has, in plain language for someone who doesn't know code."
2. "Suggest three small, low-risk changes, but don't edit anything yet."

After understanding the project, assign one small edit task, like changing one line of text on the home page. Type `/plan` with your request so Codex proposes a plan first; type `@` to find and insert a file path into your prompt. When Codex needs to exceed current permissions, it stops and asks: read the command it's about to run before you agree. Details are in the post [Codex approval mode and sandbox](/blog/che-do-phe-duyet-va-sandbox-cua-codex).

## How do I read the diff before accepting changes?

Diff is a comparison that shows which lines are deleted, which are added, and in which files. According to the Codex CLI commands page (read on 03/11/2026), `/diff` displays git diff, including files git hasn't tracked yet, and is recommended to see Codex's changes before you commit or run tests. The suggested process:

1. Type `/diff` after Codex reports it's done.
2. Count how many files changed; if more than expected, stop and ask why.
3. Ask Codex to explain the changes file by file in plain language.
4. Type `/review` so Codex goes through the changes like a second reviewer; the documentation notes review doesn't edit the working tree.
5. Run a test or open the page the way the project normally does.
6. If it works, commit it yourself; if not, ask for more fixes or revert to the previous commit.

Running code can still be wrong; see also [Using Codex to review code](/blog/dung-codex-review-code).

## What slash commands are useful for newcomers?

Slash commands are commands starting with "/" in a Codex session to control the session, not prompts for the model. The table only includes commands in the built-in command list of the Codex CLI documentation (read on 03/11/2026):

| Command | Use |
|---|---|
| `/status` | See model, approval policy, writable directory, tokens used |
| `/permissions` | Change permission level within a session, for example between Auto and Read Only |
| `/plan` | Plan before doing |
| `/diff` | See changes before commit |
| `/review` | Ask Codex to go through changes in the working tree |
| `/init` | Create AGENTS.md file template in current directory |
| `/model` | Choose model and thinking level if available |
| `/quit` or `/exit` | Exit Codex |

The documentation also notes: type `!` at the start of a line to run a shell command under current permissions, Ctrl+C to exit; outside a session, `codex resume --last` reopens the last session. Long-term settings are in the post [Configure Codex config.toml](/blog/cau-hinh-codex-config-toml).

## What errors do you often get when installing Codex CLI?

Errors when installing Codex CLI usually come from command paths, login, and network. Here's how to handle them according to the documentation (read 03/11/2026):

1. **Typing `codex` says command not found:** open a new terminal; if still broken, reinstall using a different method.
2. **Login doesn't return,** or you hit this on a remote server: use device code (beta) with `codex login --device-auth`, after enabling this in ChatGPT security settings.
3. **Company network has TLS proxy:** set the `CODEX_CA_CERTIFICATE` variable pointing to your company's certificate file before logging in.
4. **Codex reads only, doesn't edit:** the folder has no git or isn't trusted; check `/status`, change with `/permissions`.
5. **Quota runs out midway:** check `/status`; quota changes by model and job length.
6. **Not sure what the error is:** run `codex doctor` to diagnose your setup, config, and login.

Don't "fix" errors with `--dangerously-bypass-approvals-and-sandbox`, a flag that turns off both sandbox and approvals.

## OPCAIOS's experience

OPCAIOS's main work machine has Codex CLI version 0.162.x and the Codex desktop app, running side by side with [Claude Code](/tien-ich/claude-code) and [Google Antigravity](/tien-ich/google-antigravity). What's real:

1. **AGENTS.md gives Codex user-level authority,** so new sessions answer in Vietnamese on their own, read docs in order, and log the session end.
2. **Many project folders are marked trusted** in config.toml.
3. **Each session commits only its own files,** because many agents work on one system; we once hit over 1,500 "different" files just from line ending styles when one agent deployed from a Windows machine.

We haven't measured install time on a fresh machine, so 15 minutes is an estimate; we haven't tried installing on Windows; we don't have hooks to block dangerous commands yet.

## Frequently asked questions

### Does installing Codex CLI cost money?

Installing Codex CLI costs nothing, because Codex CLI is open source under the Apache-2.0 license. The cost comes from using the model, through a ChatGPT plan or an API key billed by usage. According to the pricing page read 03/11/2026, CLI comes in the Plus plan at $20/month and up, or when using an API key; the feature table doesn't list CLI for Free and Go. Price doesn't include tax and may change.

### Should I install using a script, npm, or Homebrew?

All three are in the official documentation. The script method is listed first for macOS, Linux, and Windows. npm works if your machine already has Node.js and you're familiar with npm. Homebrew works for Mac users who have already installed Homebrew. Use only one method, because installing multiple ways can make your machine run the wrong old version.

### Does Codex edit files on its own without asking?

It can, depending on the mode. In Auto mode, Codex edits files and runs commands in the working folder without asking, and only stops when it needs to go outside the folder or use the network. If you want Codex to edit nothing, start with `--sandbox read-only`, or change between sessions with `/permissions`. Always work in a folder with git so you can go back.

### Do I need to know how to code to use Codex CLI?

You don't need to know how to write code to get started, but you need to know how to open a terminal, go to the right folder, and make a git commit. You can ask Codex itself the rest, in Vietnamese, from explaining the project to explaining diffs. The process for newcomers is in [coding agents for people who can't code: safe process](/blog/tac-tu-lap-trinh-cho-nguoi-khong-biet-code-quy-trinh-an-toan).

### What should I learn after I install?

Learn in this order: make AGENTS.md with `/init` then edit by hand, understand approval mode and sandbox, set the default model in config.toml, then move on to MCP, skills, and automation. If you want someone to guide you through your real work, see [OPCAIOS's AI application training course](/services/dao-tao-ung-dung-ai).

*Source: github.com/openai/codex (README, docs/install.md), learn.chatgpt.com/docs (Codex CLI, Authentication, Developer commands, Agent approvals & security, Pricing; developers.openai.com/codex redirects there), `codex --help`, `codex login --help` version 0.162.1, read 03/11/2026; "15 minutes" is an estimate, not measured; install on Windows not verified, official docs list two different ways; price doesn't include tax and may change. The experience is OPCAIOS's.*
