Codex is OpenAI's coding agent. It reads your code, edits files, runs commands and tests, and reviews changes, all tied to your ChatGPT account. This guide takes you from install to a reviewed first project in the terminal, as of October 2026. OpenAI moved its Codex docs this year: developers.openai.com/codex now redirects to ChatGPT Learn.
1Know the pieces and what your plan includes
| Surface | What it is |
|---|---|
| ChatGPT desktop app | Pick Codex from the top-left menu for local folders, terminals and diffs |
| Codex CLI | Open-source agent in your terminal (Apache-2.0, github.com/openai/codex), also used in scripts and CI |
| IDE extension | For VS Code, Cursor and Windsurf. JetBrains and Xcode have their own Codex integrations |
| Codex Cloud | Tasks on OpenAI-managed computers that keep running while yours sleeps |
| Plan | Price | Codex access (pricing) |
|---|---|---|
| Free, Go | $0, $8/month | Limited Codex, which OpenAI lists for the desktop app. No Codex Cloud |
| Plus | $20/month | Codex on the web, CLI, IDE extension and iOS, cloud code review, optional credits |
| Pro | $100, $200 or $500/month | Much higher usage, currently no five-hour limit |
| Business | $20/user/month yearly, $25 monthly | Team workspace and admin controls |
| API key | Pay per token | CLI, SDK and IDE extension, no cloud features |
OpenAI estimates Plus at 15 to 160 local messages per five hours on GPT-6.1 Sol, or 350 to 3,000 on GPT-6 Luna, depending on the task. Weekly limits may also apply, and ChatGPT Work draws from the same allowance.
2Install and sign in
Check these against the CLI quickstart before you run one.
macOS or Linux: curl -fsSL https://chatgpt.com/codex/install.sh | sh Windows PowerShell: powershell -ExecutionPolicy ByPass -c "irm https://chatgpt.com/codex/install.ps1 | iex" npm: npm install -g @openai/codex Homebrew: brew install --cask codex
Open a project folder, run codex and choose Sign in with ChatGPT. codex login status shows how you're signed in. For pay-per-token use or CI, keep an OpenAI API key in an environment variable and pipe it in: printenv OPENAI_API_KEY | codex login --with-api-key. That bills at API rates, not against your plan, and can't use Codex Cloud, which needs a ChatGPT sign-in with multi-factor authentication. In your editor, install openai.chatgpt from the VS Code Marketplace and sign in the same way.
3Write an AGENTS.md
AGENTS.md is a plain markdown file of standing instructions that Codex reads before every task. Type /init inside Codex to generate a starter, then edit it.
- Global:
~/.codex/AGENTS.mdholds your personal rules for every project. - Project: Codex loads one file per folder, from the repo root down to where you're working. Closer files override earlier ones, and an
AGENTS.override.mdreplaces that folder's file. - Limit: loading stops at 32 KiB combined by default, so keep it short.
# AGENTS.md Project: lead cleaner, a Python 3 command-line tool that deduplicates CSV contact exports. Commands - Run tests: python3 -m unittest - Run the tool: python3 lead_cleaner.py samples/leads.csv Rules - Use only the Python standard library unless I approve a dependency. - Add or update a test for every behavior change, and run the tests before you finish. - Never read, print or commit .env files, keys or real customer data. - Keep changes small. Explain any file you delete.
One file can serve several agents: Claude Code reads AGENTS.md when a repo has no CLAUDE.md, and Google's Antigravity CLI reads it too. To check what Codex loaded, run codex --sandbox read-only --ask-for-approval never "Summarize the current instructions." More in the AGENTS.md docs.
4Choose how much Codex can do alone
The sandbox limits what Codex can technically touch. The approval policy decides when it stops to ask. Change both with /permissions and check them with /status.
| Setup | How to start it | What happens |
|---|---|---|
| Read only | codex --sandbox read-only --ask-for-approval on-request | Reads, runs read-only commands and plans. Asks before anything more |
| Auto (default in a git folder) | codex | Edits and runs commands inside the project. Asks before leaving it or using the network |
| Auto-review | codex -c approvals_reviewer=auto_review | Same limits, but a reviewer agent handles eligible approval requests |
| Full access | codex --yolo | No sandbox, no approvals. OpenAI marks it elevated risk |
Network access is off in Auto, and .git, .codex and .agents folders stay read-only. Web search reads an OpenAI-maintained cache, not live pages, unless you add --search. Delete any approval_policy = "untrusted" line from old configs: that setting is retired and can stop Codex from starting. See approvals and security.
5Build a small project end to end
The goal: a script that removes duplicate contacts from a CSV, in about 45 minutes.
- Make a repo:
mkdir lead-cleaner && cd lead-cleaner && git init. Git unlocks the Auto preset and gives you an undo button. - Add
samples/leads.csvwith 20 made-up contacts, including duplicates with different capitalization (Codex can generate it). Never practice on real customer data. - Run
codex, type/init, and replace the draft with the AGENTS.md above. - In a second terminal, commit the starting point:
git add -A && git commit -m "Start". - Type
/planand paste the prompt below. Plan mode gathers context and asks questions before writing code. Correct the plan, then approve it. - Watch it work and approve only commands you understand. Press Enter to steer the current run, or Tab to queue a message for afterward.
- When it reports done, run
python3 -m unittestyourself.
Build lead_cleaner.py as described in AGENTS.md. Read a CSV with name, email and company columns, normalize emails (trim, lowercase), remove duplicates by email, keep the most complete row, and write cleaned.csv plus one summary line: "X rows in, Y duplicates removed, Z rows out". Exit with a clear error if a column is missing. Add unittest tests for duplicates, blank emails and a missing column. Run the tests and show me the results. Don't add dependencies.
6Review the diff, then the pull request
/diffshows every change, including new untracked files./reviewstarts a separate reviewer that reports prioritized findings without touching your files. Pick a scope: a base branch, uncommitted changes, a commit, or custom instructions.- Fix what matters, rerun the tests, then commit from your own terminal (Auto keeps
.gitread-only for Codex). If the run went badly, go back to your "Start" commit.
On GitHub (cloud code review starts at Plus and needs a ChatGPT sign-in): connect your repository to Codex, then turn on Automatic review in Codex's code review settings, or comment @codex review for security issues on a pull request. It flags only P0 and P1 issues there. To steer it, add a heading called ## Code Review Rules to AGENTS.md with rules like "flag any change that could merge distinct contacts". See Codex in GitHub.
Cloud tasks: in ChatGPT on the web or desktop, go to Work in > Cloud, open Select environment and choose Create environment for your repo. Each task gets its own workspace; review the changes, then commit or open a pull request. From the terminal, codex cloud sends work and codex apply pulls the latest cloud diff locally. Saved cloud state is recoverable for only 7 days, so commit what you keep. Setup: Codex Cloud.
7Keep usage and cost under control
- Watch it:
/statusshows token use. Check the usage dashboard every week or two. Plus and Pro can buy extra credits in Settings > Usage. - Right-size the model:
/modelsets model and reasoning effort. Use low effort for small, clear tasks. GPT-6 Luna stretches your allowance furthest, and Fast mode burns it 2.5 times as fast. - Cut context: keep AGENTS.md short, point Codex at the files that matter, turn off unused MCP servers, and keep one chat per unit of work (
/newstarts one,/compactshrinks a long one). - API keys and CI: GPT-6.1 Sol lists at $2 per million input tokens and $10 per million output tokens on the API pricing page, and a long-running task uses far more than a short request. Keep the hard cap on. For scripts,
codex exec --sandbox workspace-writeruns without the chat interface; never add--yolo.
8Compare it with Claude Code and Gemini CLI
| Codex CLI | Claude Code | Gemini CLI | |
|---|---|---|---|
| Maker, license | OpenAI, open source (Apache-2.0) | Anthropic, proprietary | Google, open source (Apache-2.0) |
| Install | npm install -g @openai/codex or brew install --cask codex | Native installer from claude.ai, or brew install --cask claude-code | npm install -g @google/gemini-cli or brew install gemini-cli |
| Pay with | ChatGPT plan (limited on Free and Go) or API key | Claude Pro ($20/month), Max (from $100), Team, Enterprise or Console API credits. Not on Free | Paid Gemini API key, or Gemini Code Assist Standard or Enterprise |
| Instructions file | AGENTS.md | CLAUDE.md, or AGENTS.md if there's no CLAUDE.md | GEMINI.md |
| Default safety | OS sandbox, edits only in the project, network off | Auto mode in recent versions: a classifier reviews actions | Asks before actions. Sandbox off until you add -s |
| Other surfaces | Desktop app, IDE extension, web, iOS | Desktop app, IDE extensions, web | IDE integration |
On June 18, 2026, Google moved free users and Google AI Pro and Ultra subscribers from Gemini CLI to Antigravity CLI (command agy), which reads GEMINI.md and AGENTS.md. Pick the agent your current subscription pays for. Keep your rules in AGENTS.md and switching stays cheap; Codex's /import command can even bring over a Claude Code setup.
What's next
Get the rest of your account in shape with Set up ChatGPT properly. Then give your agent tools with MCP, or ship a public page with Claude Code.