How to Install OpenAI Codex CLI and Run Your First Task

September 17, 2026

OpenAI Codex CLI is a terminal agent: you describe a change, it reads your repository, edits files, and runs commands. It is the command-line counterpart to the Codex cloud agent, and it is open source.

Short answer: install with npm install -g @openai/codex (or Homebrew), run codex in your project, sign in with your ChatGPT account, and keep the default approval mode until you trust it.

What is Codex CLI and how is it different from ChatGPT?

Codex CLI runs locally in your terminal with direct access to the current directory. It can read files, write diffs, and execute shell commands, all with your approval. ChatGPT in a browser can suggest code; Codex CLI can apply it and run the tests.

It is written in Rust, starts in under a second, and supports the GPT-5 family. There is also a VS Code extension and a cloud version, and the CLI shares authentication with them.

How do you install Codex CLI?

  1. Requires Node.js 22 or newer, or use the Homebrew formula on macOS.
  2. Run npm install -g @openai/codex.
  3. Verify with codex --version.
  4. Run codex inside a git repository and complete the browser sign-in.
  5. Alternatively set export OPENAI_API_KEY=sk-... for headless use.

Codex CLI only works well inside a git repo — it uses git to show diffs and to let you revert. If your project is not under version control, run git init first.

What does a first task look like?

Start with something small and verifiable.

cd my-project
codex
> add input validation to the signup handler and run the tests

Codex will read relevant files, propose a diff, and ask before applying. After it edits, it runs the test command it finds and reports results. The whole loop usually takes one to three minutes for a change of this size.

What are the approval modes and which should you use?

The default asks before file writes and before shell commands. That is the right setting for week one.

Mode Behavior Use when
Suggest / read-only Never writes Exploring an unfamiliar repo
Auto-edit Writes files, asks for commands Normal daily work
Full auto Writes and runs unattended Sandboxed or throwaway repos

Full auto on a repo with production credentials is how people delete the wrong thing. Use a container if you want unattended mode.

What are the real limits?

It is a local agent, so it inherits your machine’s permissions — no sandbox by default. Long tasks can stall on a single failing test it keeps retrying. And it consumes tokens quickly on large repos because it reads many files to build context.

Costs depend on your plan: ChatGPT Plus or Pro includes Codex usage with limits, while API keys bill per token. Heavy use on a big monorepo can run into tens of dollars a day on the API.

Codex CLI suits developers who live in the terminal and want an agent close to their files. It is a poor fit if you dislike reviewing diffs or you want a graphical interface.

Quick Summary

  • Install Codex CLI with npm install -g @openai/codex; Node 22+ required.
  • It runs best inside a git repository so changes are reviewable and revertible.
  • Keep the default approval mode until you trust the agent with your repo.
  • Full auto mode has no sandbox — use a container for unattended runs.
  • Usage is included with ChatGPT Plus and Pro, or billed per token via API.