Guides · AI Stack · 31

Code with OpenAI Codex: CLI, IDE extension and cloud tasks

Install the Codex CLI, sign in with ChatGPT or an API key, write an AGENTS.md, choose safe permissions, build a small tool end to end, review the diff and keep usage under control.

2 to 3 hoursIn ChatGPT plans (limited on Free), $20/month Plus, or API usageIntermediate

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

SurfaceWhat it is
ChatGPT desktop appPick Codex from the top-left menu for local folders, terminals and diffs
Codex CLIOpen-source agent in your terminal (Apache-2.0, github.com/openai/codex), also used in scripts and CI
IDE extensionFor VS Code, Cursor and Windsurf. JetBrains and Xcode have their own Codex integrations
Codex CloudTasks on OpenAI-managed computers that keep running while yours sleeps
PlanPriceCodex access (pricing)
Free, Go$0, $8/monthLimited Codex, which OpenAI lists for the desktop app. No Codex Cloud
Plus$20/monthCodex on the web, CLI, IDE extension and iOS, cloud code review, optional credits
Pro$100, $200 or $500/monthMuch higher usage, currently no five-hour limit
Business$20/user/month yearly, $25 monthlyTeam workspace and admin controls
API keyPay per tokenCLI, 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.

Install the Codex CLI (as of October 2026)
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.md holds 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.md replaces that folder's file.
  • Limit: loading stops at 32 KiB combined by default, so keep it short.
AGENTS.md starter
# 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.

SetupHow to start itWhat happens
Read onlycodex --sandbox read-only --ask-for-approval on-requestReads, runs read-only commands and plans. Asks before anything more
Auto (default in a git folder)codexEdits and runs commands inside the project. Asks before leaving it or using the network
Auto-reviewcodex -c approvals_reviewer=auto_reviewSame limits, but a reviewer agent handles eligible approval requests
Full accesscodex --yoloNo 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.

  1. Make a repo: mkdir lead-cleaner && cd lead-cleaner && git init. Git unlocks the Auto preset and gives you an undo button.
  2. Add samples/leads.csv with 20 made-up contacts, including duplicates with different capitalization (Codex can generate it). Never practice on real customer data.
  3. Run codex, type /init, and replace the draft with the AGENTS.md above.
  4. In a second terminal, commit the starting point: git add -A && git commit -m "Start".
  5. Type /plan and paste the prompt below. Plan mode gathers context and asks questions before writing code. Correct the plan, then approve it.
  6. Watch it work and approve only commands you understand. Press Enter to steer the current run, or Tab to queue a message for afterward.
  7. When it reports done, run python3 -m unittest yourself.
First task prompt (paste into Codex; also works in Claude Code)
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

  • /diff shows every change, including new untracked files.
  • /review starts 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 .git read-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: /status shows token use. Check the usage dashboard every week or two. Plus and Pro can buy extra credits in Settings > Usage.
  • Right-size the model: /model sets 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 (/new starts one, /compact shrinks 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-write runs without the chat interface; never add --yolo.

8Compare it with Claude Code and Gemini CLI

Codex CLIClaude CodeGemini CLI
Maker, licenseOpenAI, open source (Apache-2.0)Anthropic, proprietaryGoogle, open source (Apache-2.0)
Installnpm install -g @openai/codex or brew install --cask codexNative installer from claude.ai, or brew install --cask claude-codenpm install -g @google/gemini-cli or brew install gemini-cli
Pay withChatGPT plan (limited on Free and Go) or API keyClaude Pro ($20/month), Max (from $100), Team, Enterprise or Console API credits. Not on FreePaid Gemini API key, or Gemini Code Assist Standard or Enterprise
Instructions fileAGENTS.mdCLAUDE.md, or AGENTS.md if there's no CLAUDE.mdGEMINI.md
Default safetyOS sandbox, edits only in the project, network offAuto mode in recent versions: a classifier reviews actionsAsks before actions. Sandbox off until you add -s
Other surfacesDesktop app, IDE extension, web, iOSDesktop app, IDE extensions, webIDE 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.

Codex setup checklist0/7

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.

Get the next lesson in your inbox

Your free AI path in the right order, plus new guides when they come out.

Free. No card. One click to unsubscribe.

Want it done,not just learned?

The AI Skill Pack: 13 ready Claude Skills for your inbox, weekly report, meetings, content, research, proposals and SOPs. Installed in ten minutes. $27, one time.

See the AI Skill PackOr keep going free: everything in one place