1. ai
  2. /tools
  3. /codex

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

SurfaceBest for
Codex CLIDaily terminal agent; local repo edits and commands
IDE extensionCodex inside VS Code, Cursor, Windsurf / Devin Desktop, and other editors
Codex appDesktop experience with browser and plugin workflows
Codex cloudLong-running tasks on isolated machines; hand off from CLI
Codex SDK / GitHub ActionEmbed 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)
PurposeAI pair programmer for youAI features for your users
AuthChatGPT plan or API keyAPI key / Azure OpenAI
UXCLI, IDE, cloud agentYou build routes and UI
WhenRefactors, reviews, automationChat 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

  1. cd into the repo
  2. Run codex for the interactive terminal UI
  3. Describe the task with file boundaries and verification (run npm test when done)
  4. Review diffs before accepting; use /review for 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

CodexCursorClaude Code
Home surfaceTerminal + IDE extensionAI-native IDETerminal CLI
OpenAI modelsNative, Codex-tuned modelsVia model pickerAnthropic-first
Multi-file agentYes (CLI / cloud)Yes (Agent mode)Yes
Best fitOpenAI stack, CI embed, Codex cloudVisual IDE workflowAnthropic 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-request for balanced safety
  • CI: codex exec with 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 /review on selected diffs
  • CI automation: Codex SDK and GitHub Action for PR triage
  • Cloud handoff: long tasks via codex cloud without blocking your laptop
  • OpenAI ecosystem: same account as ChatGPT; pairs with OpenAI API product work

When to Prefer Another Tool