OpenAI Codex CLI setup — comparison with Claude Code and Cursor
OpenAI's official coding-agent CLI. Install, auth, autonomy modes, and how it compares to Claude Code — all in 30 minutes.
OpenAI now ships its own coding-agent CLI. Codex CLI is the OpenAI counterpart to Anthropic's Claude Code: built on GPT-5 (or the o1/o3 line) and providing autonomous shell execution, multi-file editing, and a plan-then-execute flow.
This guide sets up Codex CLI and — assuming you already use Claude Code or Cursor — explains which tasks belong to Codex. Starting fresh? Read this alongside Claude Code setup.
TL;DR
- Node.js 20+ →
npm install -g @openai/codex→codex→ browser auth - Use an OpenAI API key or ChatGPT Plus/Pro subscription
- Default is approval mode (confirm each command) —
--auto-edit/--full-autoraise autonomy - Pick a model:
--model gpt-5oro3(perf vs. cost tradeoff) - Role split with Claude Code: see §5
Prerequisites
- Node.js 20+ (mac/dev-toolchain or windows/initial-setup)
- OpenAI account — platform.openai.com or ChatGPT Plus/Pro
- A git-managed project
1. Where Codex CLI fits
This is OpenAI's first-party coding-agent CLI. Unlike third-party tools (Cursor, Aider, Continue) that call OpenAI models, Codex CLI is OpenAI's own standard release.
Similarities to Claude Code
- Runs autonomously in the terminal
- Multi-file editing · shell commands · git integration
- Project context (Codex stores it in a
.codex/directory) - Plan → execute → verify workflow
Differences
| Aspect | Codex CLI | Claude Code |
|---|---|---|
| Model | GPT-5 · o3 · o4 | Claude Opus / Sonnet / Haiku |
| Context window | 200K (varies by model) | 1M (Opus/Sonnet 4) |
| Autonomy flags | --auto-edit, --full-auto | permission mode + hooks |
| Auth | API key or ChatGPT subscription | API key or Pro/Max subscription |
| Pricing | Token-based or Plus($20)/Pro($200) | Token-based or Pro($20)/Max($100/$200) |
| MCP support | Partial (in progress) | Full |
| IDE integration | Separate IDE extension | VS Code · JetBrains · CLI |
Who's it for
- Already on ChatGPT Plus/Pro — Codex CLI is included
- Already in the OpenAI ecosystem — share keys with Embeddings, DALL·E, etc.
- Want the o3/o4 reasoning advantage for long-thinking tasks
- Need GPT-5 multimodal — images / diagrams as input
2. Install
2.1 npm global
npm install -g @openai/codex
codex --versionIf install fails or you hit permission errors, see Claude Code setup §1.1 for the npm-prefix workaround.
2.2 First run
cd ~/projects/my-repo
codexA browser tab opens for OpenAI login → grant access → back to the CLI. The token is stored in the OS keychain.
2.3 Auth options
Three paths:
# A. ChatGPT Plus/Pro (subscription)
codex auth login --use-chatgpt
# B. OpenAI API key
codex auth login --use-api
# → reads OPENAI_API_KEY or prompts
# C. Dedicated Codex.com account (beta)
codex auth login --use-codexCheck:
codex auth status
# Account: <email>
# Plan: ChatGPT Plus / API tier 23. Autonomy modes
The default is conservative — confirm every shell command and edit. Levels:
| Flag | Behavior | Risk |
|---|---|---|
| (default) | Ask before every command and edit | Low |
--auto-edit | Edits auto, shell still asks | Medium |
--full-auto | Everything auto (dangerous) | High |
Recommendation: stay on the default until you trust the tool, then switch to --auto-edit on familiar repos.
codex --auto-edit
> Refactor the auth module into smaller files4. Core commands
4.1 Start a session
codex
> Plan: add a password reset featureNatural-language prompt → Codex proposes a plan → you approve → execution.
4.2 Slash commands
Inside a session:
/help— command list/init— analyze the project and createAGENTS.md/model gpt-5— switch model/clear— reset context/exit— quit
4.3 AGENTS.md — project guidance
Codex's counterpart to CLAUDE.md. At the project root:
# AGENTS.md
## Stack
- Next.js 16 + TypeScript strict
- Supabase + Postgres
- pnpm 11
## Commands
- Dev: `pnpm dev`
- Test: `pnpm test`
- Build: `pnpm build`
## Conventions
- No `any` types
- Routes: kebab-case
- Commits: `[Project] type: description`
## Working principles
- Plan before 5+ file changes
- Tests + lint + build must pass before "done"
- Never commit secretsAuto-loaded on session start. Functionally near-identical to CLAUDE.md.
When using both with Claude Code: either duplicate content between
CLAUDE.mdandAGENTS.md, or keep onlyAGENTS.mdand reference it fromCLAUDE.mdvia@AGENTS.md.
5. Claude Code vs Codex CLI — task mapping
| Task | Pick | Why |
|---|---|---|
| 1M-context multi-file work | Claude Code | Opus/Sonnet 4's 1M window |
| Long reasoning (debugging, architecture) | Codex CLI (o3) | reasoning model edge |
| Code + image (screenshot analysis) | Codex CLI (GPT-5 multimodal) | image input |
| Autonomous verification after changes | Claude Code | hooks + verify system |
| OpenAI-ecosystem integration (embeddings, etc.) | Codex CLI | unified keys |
| MCP servers (Linear, Notion, etc.) | Claude Code | full MCP |
| Cost minimization | Whichever subscription you already have | avoid API tokens |
Both work in the same repo without conflict (both are git-based).
6. Pricing (as of 2026-05)
API pricing (Codex CLI)
| Model | Input | Output | Per-1k cost |
|---|---|---|---|
| GPT-5 | $1.25 / 1M | $10 / 1M | Low input cost |
| o3 | $2 / 1M | $8 / 1M | Reasoning-tuned |
| o4-mini | $0.3 / 1M | $1.2 / 1M | Best value |
Subscriptions
| Plan | Price | Codex CLI usage |
|---|---|---|
| ChatGPT Plus | $20/mo | GPT-5 limited, some o3 |
| ChatGPT Pro | $200/mo | near-unlimited |
Real spend varies. Rough average for a fullstack dev on API: $30-100/month. Heavy users come out ahead on Pro.
7. Verify
# 1. Installed
codex --version
# 2. Auth
codex auth status
# 3. Project files
ls -la AGENTS.md .codex/
# 4. First command test
echo "create a hello.py that prints 'hello'" | codex --auto-editAll four passing = setup complete.
8. Troubleshooting
codex: command not found
- Check npm prefix:
npm config get prefix's/binmust be on PATH - Open a fresh terminal and retry
Browser auth won't open
- Headless environment (WSL2/SSH): copy the URL from the CLI into a browser
- Still failing? Delete
~/.codex/auth.jsonand usecodex auth login --use-apiwith a key
"Insufficient quota"
- Your OpenAI usage cap was hit — platform.openai.com/usage
- The free tier is very restrictive. Tier 1+ (activated after $10 prepay) is the practical minimum
Codex and Claude Code edit the same file simultaneously
- Run one at a time, or have the second wait
- Or add a
.codex-lock-style sentinel file to.gitignoreto coordinate
--full-auto ran too aggressively
Ctrl+Cimmediatelygit reset --hard HEADorgit stashto recover- Stay on
--auto-editgoing forward
MCP server won't connect
- As of 2026-05, Codex CLI's MCP support is partial (beta)
- For full MCP integration, use Claude Code
9. What's next
- Claude Code setup — /ai-agents/claude-code
- Cursor setup — /ai-agents/cursor-setup
- Copilot setup — /ai-agents/github-copilot
- Multi-tool workflow — /ai-agents/multi-tool-workflow
References
Changelog
- 2026-05-16: First draft. Codex CLI install + three auth methods + autonomy modes + AGENTS.md + Claude Code comparison table + six troubleshooting cases.