Tool Guide · Coding
OpenAI Codex Guide
The definitive guide to OpenAI Codex — the codex CLI, Codex Cloud agent, IDE integrations, sandboxing, when to delegate vs run inline, and how it differs from Claude Code.
Key takeaways
- 1codex CLI — terminal-native agent (install: npm i -g @openai/codex or brew install codex)
- 2Codex Cloud — fire-and-forget background tasks that run in an isolated cloud sandbox and return a PR
- 3VS Code + JetBrains plugins for inline edits and chat
- 4Tasks can run in parallel — kick off 5 background tasks and review them as PRs
- 5Backed by GPT-5 family + Codex-tuned models for code-specific work
- 6Sandbox environments with internet + tool access (configurable)
- 7AGENTS.md — repo-level instructions Codex reads automatically (analogous to CLAUDE.md)
- 8Slack + GitHub integrations — kick off tasks from Slack, ship PRs to GitHub directly
- 9Cost included in ChatGPT subscriptions (no per-token billing for typical use)
- 10Approval modes — auto-edit / suggest-only / read-only — per session
- 11Resume + branch — pause a Codex task, edit manually, then resume
- 12Headless mode for CI scripts and automation pipelines
Best for
- Engineers already on ChatGPT Plus / Pro — Codex is included, no extra spend
- Parallelizable tasks — fire 5 PRs to fix 5 small issues simultaneously
- Background tasks you want to come back to (Codex Cloud)
- Teams that prefer GPT-5's coding style over Claude's
- Slack-driven workflows — file a task in Slack, review the PR later
- Standardized refactors across many repos — Codex's sandbox model fits this
- Anyone who wants both an in-editor agent and a cloud delegated agent in one product
Not for
- Engineers who want the strongest single-task agent loop — Claude Code still leads here
- Workflows that require very specific tool/MCP integrations — Codex's MCP support exists but lags Claude Code's depth
- Repos with weak tests — same problem as any agent, but Codex Cloud's PR-back model amplifies it
- Anyone allergic to OpenAI's ecosystem politics
- Teams that want full local sandboxing — Codex Cloud is hosted, not self-hostable
What it is
OpenAI Codex is OpenAI's agentic coding suite. It's not a single product — it's three:
- codex CLI — a terminal-native agent that runs locally, reads your repo, edits files, runs commands. Same shape as Claude Code or Aider.
- Codex Cloud — a delegated background agent. You describe a task, it runs in an isolated cloud sandbox, and returns a pull request when done. You can fire off multiple in parallel.
- IDE plugins — first-class extensions for VS Code and JetBrains for inline edits, chat, and Codex Cloud task spawning from your editor.
All three are powered by GPT-5 family models (with Codex-tuned variants for coding). All three are included in paid ChatGPT plans — there's no separate Codex subscription line for typical use.
If you've used Claude Code, the closest analogy is: Codex CLI ≈ Claude Code, plus Codex Cloud (which Claude doesn't have a direct equivalent for), plus the deepest IDE plugin story of any major agent in 2026.
When to reach for Codex
Use Codex when:
- You're already on ChatGPT Plus / Pro — it's included
- You have parallelizable tasks — fire 5 Codex Cloud PRs simultaneously
- You want to delegate background work — kick off a task in Slack or the CLI, come back to a PR
- You're in JetBrains or want a polished VS Code plugin (not a fork like Cursor/Windsurf)
- You want to A/B GPT vs Claude on coding tasks — different strengths, useful comparisons
Don't use Codex when:
- You need the strongest single-task agent loop — Claude Code still leads on hard, multi-step interactive work
- Your stack depends on a long-tail MCP server — Claude Code's MCP ecosystem is deeper
- You need self-hosting — Codex Cloud is hosted-only
- You're allergic to OpenAI's ecosystem politics or breaking-change cadence
Setup
codex CLI
# npm
npm install -g @openai/codex
# Homebrew
brew install codex
Sign in with your ChatGPT account:
codex auth
Then run codex from any git repo. First-launch flow:
- It detects the repo and offers to read it.
- Pick an approval mode (auto / suggest / read-only).
- Type a task.
Codex Cloud
Codex Cloud lives at chatgpt.com under the Codex tab, or you can fire tasks from the CLI:
codex cloud submit "Add input validation to all /api routes using zod"
The task runs in an isolated sandbox, executes against a clone of your repo, and opens a pull request when done. You'll get a Slack notification (if configured) or an email.
IDE plugins
- VS Code: install "OpenAI Codex" from the marketplace
- JetBrains: install from the JetBrains plugin marketplace
Both authenticate with your ChatGPT account and offer:
- Inline edits (Cmd-K / Alt-Enter)
- Chat panel with full project context
- One-click "send to Codex Cloud" for any selection or file
AGENTS.md
Drop an AGENTS.md at the root of your repo (and/or subdirectories). Codex reads it automatically. Same role as CLAUDE.md for Claude Code:
# AGENTS.md
## Stack
- Next.js 15 / TypeScript strict / Tailwind
- Vitest for tests, Playwright for e2e
## Conventions
- Components: PascalCase, files match component name
- API routes: validate input with zod
- Errors: typed Error subclasses, never throw strings
- Tests: colocate with source file (foo.ts + foo.test.ts)
## Commands
- Test: npm test
- Build: npm run build
- Lint: npm run lint --fix
The AGENTS.md convention is now widely adopted — it works for Codex, Cursor (with rules import), and several other agents in 2026.
The Codex CLI loop
Same shape as Claude Code: type a task, Codex reads/edits/runs/iterates. Differences:
- Approval modes are explicit and per-session:
--auto(Codex applies edits without asking),--suggest(proposes diffs, you accept/reject),--read-only(reads + reports, doesn't edit). - Resume + branch — pause a Codex session, edit manually, then
codex resumeto continue from your edits. - Headless mode for CI —
codex run --prompt-file task.md --output-format jsonis the standard pattern.
For interactive coding, the loop feels similar to Claude Code. As of mid-2026, Claude Code edges out on raw "got it right first try" rates on hard tasks, but Codex CLI is close enough that ecosystem and pricing usually drive the choice.
Codex Cloud (the novel piece)
This is where Codex genuinely differs from Claude Code. You describe a task, it runs in an isolated cloud sandbox, and returns a PR. Patterns it shines on:
1. Parallelizable small fixes
You have 5 small bugs to fix. Instead of doing them serially in Claude Code, fire 5 Codex Cloud tasks. Each gets its own sandbox, branch, and PR. Review and merge in any order.
2. Background work while you focus
You're deep in a Cascade or Claude Code session. You realize the README is out of date. Instead of context-switching, fire a Codex Cloud task: "Update the README to reflect the changes in commits since X." Come back to a PR.
3. Slack-triggered tasks
Codex Cloud integrates with Slack. Post @codex Update the changelog with recent PRs and it files a PR. Great for team workflows where non-engineers can trigger small tasks.
4. Scheduled / recurring work
Pair Codex Cloud with cron or GitHub Actions: "Every Monday, find dependencies with new minor versions and open an upgrade PR." The sandbox model fits this well.
Caveats
- You can't watch and steer mid-task. Once submitted, you wait for the PR. If the agent went off-script, you find out at the end.
- Clean repo state needed. Codex Cloud doesn't handle dirty working trees well — submit from a clean branch.
- Test suite matters more. Since you can't course-correct mid-task, the test suite is your only guardrail. Bad tests = bad PRs.
IDE plugins
Two flavors:
- Inline edit (Cmd-K / Alt-Enter) — select code, describe a change, Codex rewrites in place. Fast for one-off tweaks.
- Chat panel — full project context, multi-turn conversation. Can spawn Codex Cloud tasks from any reply.
The plugins are notably more polished than community alternatives. If you're committed to JetBrains specifically, Codex has the strongest plugin story of any major agent in 2026 — Claude Code is terminal-only and Cursor/Windsurf are VS Code forks.
Model picker
Codex uses GPT-5 family models with Codex-tuned variants:
- GPT-5 (general) — default for most tasks
- GPT-5 Coder — tuned for coding, better at multi-file edits
- GPT-5 Mini — fast and cheap, good for autocomplete + glue
- o4 reasoning — for hard architecture / debugging work where "think harder" helps
The codex CLI's --model flag swaps mid-session. Codex Cloud auto-selects based on task complexity.
Cost discipline
Codex usage is included in ChatGPT subscriptions — no per-token billing for typical use. Heavy users (CI automation, hundreds of daily Codex Cloud tasks) can hit fair-use limits and may need API-key access for the overflow.
Practical tactics:
- Use Codex Mini / GPT-5 Mini for autocomplete-heavy work. Save the big models for hard tasks.
- Don't fire 50 parallel Codex Cloud tasks. Stay within fair use.
- For automation, use the API. The codex CLI's
OPENAI_API_KEYmode lets you bill against an API key instead of subscription — useful for CI.
Security & sandboxing
- codex CLI runs locally with your file/network access. Use approval modes to gate edits; configure a tool allow-list in
~/.codex/config.json. - Codex Cloud runs in OpenAI's isolated sandbox — can't touch your local machine. Repo is cloned in, PR comes out via GitHub.
- IDE plugins run inside your editor's sandbox; same posture as any VS Code/JetBrains extension.
- For sensitive repos, set up a fine-scoped GitHub App for Codex Cloud rather than a personal access token.
Honest limitations
- Single-session agent loop is behind Claude Code on hard tasks. Codex closes the gap each quarter; as of mid-2026, Claude Code is still the pick for the hardest interactive work.
- Codex Cloud's PR-back model has a longer feedback loop. You can't steer mid-task. Plan for re-runs.
- MCP ecosystem is smaller. Common servers work; long-tail community MCP servers tend to be Claude Code-first.
- No live token meter in the CLI. Forecast cost via your ChatGPT account dashboard.
- Self-hosting isn't available. Codex Cloud is hosted-only; CLI talks to OpenAI's API.
- OpenAI's breaking-change cadence has historically been faster than Anthropic's — invest in workflow recipes carefully.
Comparison: Codex vs Claude Code vs Cursor
| Dimension | OpenAI Codex | Claude Code | Cursor |
|---|---|---|---|
| Home | CLI + Cloud + IDE plugins | CLI only | VS Code fork |
| Synchronous loop strength | Strong | Strongest (2026) | Strong |
| Delegated / async | Codex Cloud (unique) | Background commands | Limited |
| Free tier | None | None | Limited |
| Included with | ChatGPT Plus / Pro / Business / Enterprise | None (own subscription) | None (own subscription) |
| IDE plugin polish | Best (VS Code + JetBrains) | None (terminal-only) | N/A (it IS the editor) |
| MCP ecosystem | Mid | Largest | Mid |
| Self-host | No | No | No |
| Model | GPT-5 family | Claude Sonnet/Opus/Haiku | Multi-provider |
| Best for | Parallel + delegated + IDE | Synchronous deep work | Editor-time autocomplete + agent |
Most engineers running multiple use Codex Cloud + Claude Code: Codex Cloud for parallel/delegated, Claude Code for synchronous deep work. Or Codex IDE plugin + Claude Code for the JetBrains-first crowd.
Workflow patterns that work
-
AGENTS.md first, code second. 15 minutes of writing rules saves hours of agent re-runs.
-
Codex Cloud for parallel batches. When you have 3+ independent tasks, parallelize them through Cloud. Don't serialize in your CLI.
-
CLI for interactive deep work. When you need to steer mid-task, use the CLI with approval mode "suggest." Same discipline as Claude Code plan mode.
-
IDE plugin for inline edits. Don't fire up the full agent for a one-line tweak. Cmd-K and move on.
-
Slack integration for cross-team tasks. "@codex Update the README" from a non-engineer is a real productivity unlock.
-
GitHub App, not personal token. For Codex Cloud, install a properly scoped GitHub App so the agent's PR permissions are auditable.
When to walk away
- You want the strongest interactive agent loop — Claude Code wins.
- You want a unified editor experience — Cursor or Windsurf, not Codex's IDE plugin.
- You want self-hosting — none of the three big agents truly offer this; look at Continue + local model.
- You want a model-agnostic agent — Aider, Continue.
- You want minimum vendor lock-in to OpenAI — Claude Code or model-agnostic options.
Next steps
- Install the codex CLI:
npm install -g @openai/codexand runcodex auth. - Write an
AGENTS.mdfor your current project. - Try a Codex Cloud task on a low-stakes refactor — get a feel for the PR-back loop.
- If you're in JetBrains, install the Codex plugin — best agent IDE plugin available in 2026.
- Pair Codex Cloud + Claude Code for the strongest combined setup.
Pros and cons
Pros
- Codex Cloud's parallel + delegated model is genuinely different from Claude Code's synchronous loop
- Included in ChatGPT subscriptions — no separate billing line for daily use
- Strongest IDE plugin story of the three big agents (VS Code + JetBrains both first-class)
- GPT-5 family models — different strengths from Claude, useful for A/B testing
- Slack integration is real and useful for cross-team tasks
- Mature sandbox model — cloud tasks can't touch your local machine
- Headless mode + GitHub integration make CI/CD use straightforward
Cons
- Single-session agent loop is still behind Claude Code on hard, multi-step tasks (as of mid-2026)
- Codex Cloud's PR-back model means you can't watch and steer mid-task — feedback loop is longer
- MCP ecosystem is smaller than Anthropic's — fewer high-quality third-party servers
- Cost discipline is harder — no live token meter in the CLI
- Cloud tasks need clean repo state — Codex Cloud doesn't handle dirty working trees gracefully
- Sandbox is hosted — can't self-host the Codex Cloud runtime
- OpenAI's history of breaking changes makes long-term workflow investment riskier
Real workflows using this tool
Prompt examples
Copy any of these, replace the placeholders, run.
codex CLI — onboard to a repo
Read this codebase and write an AGENTS.md at the root.
Cover:
- Architecture (2 paragraphs)
- Conventions (naming, tests, commits, branch policy)
- Common commands (test, build, lint, deploy)
- Anything quirky — call it out, don't fix it
Save only AGENTS.md. Do not modify other files.Codex Cloud — fire a background task
[via codex cloud command]
Add input validation to every public API route in /api/ using zod.
Use the existing schema patterns in src/lib/schemas/. Add unit tests for each validator. Run the full test suite when done. Open as a PR to a branch named codex/api-validation.
If any route already has validation, leave it alone. Skip routes under /api/internal/.VS Code inline — refactor selection
Convert this useState pair (loading + error) into a single status enum: "idle" | "loading" | "success" | "error".
Update all reads of loading/error in this file. Keep the public component API unchanged.codex CLI — parallel small fixes
I have 5 small bugs to fix. Spawn 5 parallel Codex Cloud tasks, one per bug, each opening its own branch and PR.
Bugs (one per line):
1. {{bug 1}} (file: ...)
2. {{bug 2}} (file: ...)
3. {{bug 3}} (file: ...)
4. {{bug 4}} (file: ...)
5. {{bug 5}} (file: ...)
For each: read the file, write a failing test, fix, ensure test passes, open PR.codex CLI — guided code review
Review the diff between origin/main and HEAD.
Score against:
- Correctness vs the PR description
- Test coverage (gaps?)
- Naming + style consistency with AGENTS.md
- Security: external input handling, secrets, auth
- Risk: anything irreversible if merged?
Output a punch list. Don't apply changes.Slack-triggered task
[posted in Slack with @codex prefix]
@codex Update the README.md changelog with the last 5 merged PRs from this repo (use the GitHub MCP). Open as a PR.Alternatives
Frequently asked questions
Watch
Hand-picked videos from official + trusted channels. Opens in a new tab.
Related on AIKnowHub
Tool Guide
Claude Code Guide
The definitive guide to Anthropic's terminal-native AI coding agent — install, configure, MCP, hooks, skills, sub-agents, plan mode, cost, security, limitations.
Tool Guide
Cursor AI Guide
The most popular AI-native IDE. A VS Code fork with deep model integration, multi-file edits, and a strong agent loop.
Comparison
Best AI Model for Coding
Which model actually writes the best code? Benchmarked against real tasks — refactors, bug fixes, new features, code review.
Directory
Claude Code
Terminal-native agent that reads, writes, runs, and reviews your codebase.
Directory
Cursor
AI-native VS Code fork with multi-model support, tab autocomplete, and an agent mode.
Concept
AI Agents Explained
Agents are LLMs that can take actions in a loop. Here's what that actually means, where they shine, and where they fall over.