OpenAI Codex
OpenAI Codex is a coding agent that runs in your terminal, IDE, desktop app, and the cloud. It is not the same as the retired 2021 Codex API model.
Last reviewed: June 2026
Codex ships frequent CLI and IDE updates. Verify install steps and flags in OpenAI Codex docs before scripting CI jobs.
Codex Surfaces
| Surface | Best for |
|---|---|
| Codex CLI | Daily terminal agent; local repo edits and commands |
| IDE extension | Codex inside VS Code, Cursor, Windsurf / Devin Desktop, and other editors |
| Codex app | Desktop experience with browser and plugin workflows |
| Codex cloud | Long-running tasks on isolated machines; hand off from CLI |
| Codex SDK / GitHub Action | Embed the same agent in CI/CD and internal tools |
Official overview: Codex on OpenAI Developers.
Codex vs Building with the OpenAI API
| Codex (agent product) | OpenAI API (your app) | |
|---|---|---|
| Purpose | AI pair programmer for you | AI features for your users |
| Auth | ChatGPT plan or API key | API key / Azure OpenAI |
| UX | CLI, IDE, cloud agent | You build routes and UI |
| When | Refactors, reviews, automation | Chat widgets, RAG products |
Use Codex to write code faster. Use the API when shipping AI inside your product.
Install and Sign In
# Common install paths (confirm latest on GitHub)
npm install -g @openai/codex
# or: brew install codex
Run codex and sign in with ChatGPT (Plus, Pro, Business, Edu, Enterprise) or configure an API key for team automation. See Codex authentication.
Always run from your project root so Codex sees git context and project structure.
CLI Workflow
cdinto the repo- Run
codexfor the interactive terminal UI - Describe the task with file boundaries and verification (
run npm test when done) - Review diffs before accepting; use
/reviewfor dedicated code review presets
# Non-interactive / CI-style run
codex exec "Add input validation to src/api/users.ts. Run npm test when done."
# Resume the last session in this directory
codex exec resume --last "Also update the README"
For scripted pipelines, add --json for machine-readable events. See Codex CLI reference.
MCP and Plugins
Codex supports Model Context Protocol servers. Connect databases, internal APIs, and docs the same way you would in Cursor:
codex mcp # configure and inspect MCP servers
Codex also supports plugins (skills, MCP bundles, app integrations). Useful for team-specific workflows you reuse across sessions.
See Building MCP Servers for server patterns that work across Codex, Cursor, and Claude Code.
Codex vs Other Agents
| Codex | Cursor | Claude Code | |
|---|---|---|---|
| Home surface | Terminal + IDE extension | AI-native IDE | Terminal CLI |
| OpenAI models | Native, Codex-tuned models | Via model picker | Anthropic-first |
| Multi-file agent | Yes (CLI / cloud) | Yes (Agent mode) | Yes |
| Best fit | OpenAI stack, CI embed, Codex cloud | Visual IDE workflow | Anthropic stack, headless |
Many teams run Codex CLI alongside Cursor or Copilot: Codex for scripted refactors and reviews, an IDE agent for visual multi-file work.
Effective Prompts
Same rules as Prompting for Code:
In src/utils/date.ts, add formatRelativeTime(iso: string): string
using Intl.RelativeTimeFormat. Match existing error handling.
Do not add dependencies. Run npm test when done.
Avoid: "make this better" or unbounded "refactor the codebase."
Sandboxing and Approvals
Codex can edit files and run shell commands. Use sandbox and approval settings appropriate to your environment:
- Local dev:
--sandbox workspace-write --ask-for-approval on-requestfor balanced safety - CI:
codex execwith explicit scopes; never expose secrets in prompts - Protected paths: use hooks or team policy to block edits to
main, CI configs, or infra
See Verifying AI Output before merging agent diffs.
When Codex Shines
- Terminal-first workflows: SSH, remote dev boxes, no GUI
- Code review: use
/reviewon selected diffs - CI automation: Codex SDK and GitHub Action for PR triage
- Cloud handoff: long tasks via
codex cloudwithout blocking your laptop - OpenAI ecosystem: same account as ChatGPT; pairs with OpenAI API product work
When to Prefer Another Tool
- Heavy JSX/CSS with live preview: IDE agents (Cursor, Devin Desktop) win
- Anthropic-only enterprise contract: Claude Code
- Inline tab completions only: GitHub Copilot
- AWS-native stack and IAM: Amazon Q Developer