03 / Codex CLI · OpenAI
OpenAI Codex CLI, a real operator's guide
Codex CLI is not another shell wrapper. It is an agent that edits your repo, runs your tests, and commits when it's done. Here is how to install it, wire it into a workflow that respects main, and where it earns its place next to Claude Code and Cursor.
Every time OpenAI ships something new in the coding space, my inbox fills up with the same question: "should I switch?" The honest answer, as of mid 2026, is no. But you should absolutely add Codex CLI to your toolbelt. It does one thing better than anything else, and if you are already paying for ChatGPT Plus, the marginal cost is zero.
This is not a walkthrough of every flag. It is a field guide to installing it, using it without regret, and knowing when to reach for it instead of Claude Code or Cursor.
What Codex CLI actually is
Codex CLI is OpenAI's open-source terminal coding agent. You install it with npm, run codex in a project directory, and get a REPL-style prompt. You describe a task. It reads the code, plans, edits files, runs commands, iterates.
The key thing to internalize: it edits your files directly. Not a preview pane, not a diff you approve line by line. Your working tree changes. Which is exactly the point, and exactly why the safety story matters.
Install, in ninety seconds
- You need Node 18 or newer. Check with
node --version. On Mac,brew install node. On Windows, WSL is the sane path. npm install -g @openai/codex. You can also usebrew install codexon Mac or grab a native binary from the GitHub releases.codex. First run, it asks you to sign in. Two options: use your ChatGPT Plus, Pro, or Team account, or paste an OpenAI API key. Sign-in mode is included in the subscription. API mode is pay-per-token.- Change into a project directory. Run
codexagain. You are in.
The three approval modes, in plain English
- suggest. Codex proposes every edit and every command. You approve. Safe. Slow. Good for the first hour.
- on-request. Codex runs safe operations (reads, edits inside the sandbox) automatically. It asks before running shell commands or reading files outside the project. This is the right default for real work.
- full-auto. Codex runs everything without asking. Do not use this outside a sandbox, a container, or a throwaway branch. Do not use it on main.
How to actually use it
Codex CLI shines when the task has a shape. Not "make this better." Not "add a feature." Specifically:
- Failing test to green.
- Codemod-style refactor across the repo.
- Migrating a file or module from one library to another.
- Writing docs for existing code.
- Bulk find-and-fix across many files with a rule you can describe.
The pattern I use for anything non-trivial:
git checkout -b codex/whatever. Fresh branch. Always.- Write the task as a short markdown file. Paste it into Codex. Two to eight bullet points, the files involved, the success criteria.
- Let it work. Watch the tool calls. Do not interrupt unless it is clearly heading somewhere wrong.
- When it says done, run your tests yourself. Do not trust the "tests pass" claim without seeing the output.
- Read the diff. Not skim, read. Push back or ask it to explain any change that surprises you.
- Commit. Push. Open the PR. Let CI weigh in.
Where Codex CLI beats Claude Code
- Tighter GPT model integration. If your org is standardized on OpenAI, using Codex CLI keeps your billing, your usage tracking, and your model access in one place.
- Native binary. The Rust-based native binary is notably snappier than the Node-only alternatives. On big repositories, the startup difference is noticeable.
- Cheap bulk tasks. Drop to gpt-5-mini for bulk find-and-fix work and the per-token cost is a fraction of Claude Sonnet. If you are running Codex over hundreds of files in a codemod, this matters.
- Free with a subscription you probably already have. If you pay for ChatGPT Plus, Codex CLI is included at generous limits. That is a strong price point.
Where Claude Code still wins
- Long-context reasoning. Claude tends to hold twenty-file mental models more coherently. On big refactors, the finish rate is better.
- Following complex specs without drifting. This is subjective and it changes model by model, but as of this writing, Claude is stickier to the original intent.
- Ecosystem maturity. Claude Code has a larger community, more plugins, more MCP integrations, more shared prompt patterns. Codex CLI is catching up fast, but it is catching up.
How not to wreck main
Every horror story I hear about agent-edited codebases follows the same pattern: someone ran an agent in full-auto on main, went to lunch, came back to a rewritten codebase, and now the tests pass but nothing works. Four rules that make this impossible:
- Never on main. Always a branch. Non-negotiable.
- Never in full-auto outside a container. Run full-auto inside Docker, a devcontainer, or a fresh VM. Never on your working machine.
- CI has to pass before merge. Codex saying "tests pass" is not enough. Your real CI has to be green.
- Code review by a human before merge. Even if the human is you an hour later, with fresh eyes. Agents are confident when they are wrong.
Configuration that pays for itself
Open ~/.codex/config.toml. Add:
approval_mode = "on-request". Default for all sessions.model = "gpt-5-codex". The right default in 2026. Drop togpt-5-minifor bulk tasks by passing--model gpt-5-miniat launch.- A project-scoped
AGENTS.mdat your repo root that lists the conventions of the codebase: test framework, lint rules, directory layout, "never edit these files." Codex reads it automatically. It is the single highest-leverage config change you can make.
The workflow I actually run
Cursor for exploration and small edits. Claude Code for long refactors that need reasoning discipline. Codex CLI for bulk work, codemods, and anything I want to run cheaply at scale. All three, same repo, different jobs.
The teams that pick one and reject the others are usually optimizing for a bill that does not matter (forty dollars a month combined) at the cost of a productivity gap that does (hours per week). Use all three. Pick the right one for the task. Move on.
Common questions
What is Codex CLI?
Codex CLI is OpenAI's open-source terminal agent. It runs on your machine, reads your codebase, edits files, runs commands, and iterates until a task is done. Think of it as Claude Code's OpenAI equivalent: an agent, not an editor.
How do I install Codex CLI?
npm install -g @openai/codex, then run 'codex' in a repo. You need Node 18+, an OpenAI API key or a ChatGPT Plus/Pro/Team subscription for sign-in mode, and a terminal you're comfortable in. Mac, Linux, and Windows via WSL all work.
Is Codex CLI free?
The CLI itself is open source and free. Usage is billed either through your OpenAI API key (pay-per-token) or included in ChatGPT Plus/Pro/Team via sign-in mode. Plus at $20/month is enough for light use; heavy users move to API billing or Pro.
How do I exit Codex CLI?
Type /exit or press Ctrl+C twice. If it's mid-task, Ctrl+C once cancels the current step; a second Ctrl+C or /exit closes the session cleanly.
How do I change models in Codex CLI?
Use /model inside the session to switch, or set --model gpt-5-codex when launching. You can also set a default in ~/.codex/config.toml. Most people leave it on the default gpt-5-codex; drop to a cheaper model only for scripted or bulk tasks.
Codex CLI vs Claude Code, which should I use?
Codex CLI if you're already on OpenAI and want tight integration with GPT models. Claude Code if you prefer Claude's reasoning style, which tends to be better at long-context refactors. In practice, teams that ship a lot use both, one for the task each does best.
If you want the deeper build
Codex CLI (and Claude Code, and Cursor) are the front door. What is behind the door is the harder work: agents that touch production, tools that need permission models, evals that catch regressions before your customers do. That is what I build for teams. See custom AI agent development or the Claude Code vs Cursor breakdown.
Want this shipped in your stack?
The $1,000 AI audit gets you a ranked action plan in 48 hours.
90-minute live review of your workflows, agents, retrieval, permissions, evals, costs, and observability. Fee credits toward the build.