Claude Code vs Cursor vs Codex: which AI coding agent to use
All 3 are AI coding agents that read your code, edit files and run commands until a task is done, and all 3 read an AGENTS.md file, so one set of project instructions serves them all. Pick Claude Code for Claude models in the terminal and IDEs with detailed permission rules, Cursor for an AI-first editor with models from several makers, and Codex for OpenAI's models with an operating-system sandbox on by default and an open-source CLI. The bigger differences are in how each one limits what the agent may touch.
Take this page into your AI
Open in ChatGPT (new tab)Open in Claude (new tab)- Claude CodeAnthropicAnthropic's coding agent, using Claude models, in the terminal, VS Code, JetBrains, a desktop app and on the web.
curl -fsSL https://claude.ai/install.sh | bashDocumentation - CursorCursorAn AI code editor with an agent built in, plus a CLI and cloud agents, using Cursor's own models or other makers' models.
curl https://cursor.com/install -fsS | bashDocumentation - CodexOpenAIOpenAI's coding agent, using OpenAI's models, in an open-source CLI, an IDE extension, the ChatGPT desktop app and the cloud.
curl -fsSL https://chatgpt.com/codex/install.sh | shDocumentation
An AI coding AgentAgentA model that uses tools in a loop, deciding each next step from what the last one returned, until the task is done. works in your project the way a developer would: it reads files, changes them and runs commands such as your tests, checking the results until the task is done. Claude Code, Cursor and Codex all work that way, and on a well-described task they all get far. The differences that matter day to day are where you use each one, which models it runs, how you pay, and, most of all, how you limit what it may touch.
Claude Code
Claude Code is Anthropic's agent. It began in the terminal and now runs in VS Code, JetBrains, a desktop app and on the web, with the same settings everywhere. It uses Claude models only, paid through a Claude plan or per token through the Anthropic Console or a cloud provider. Its strength is control: permission rules per tool, such as allowing npm test while denying .env, several permission modes, subagentsSubagentAn agent started by another agent for one part of a task. It works in its own fresh context and returns only its findings., skills, hooks and plugins. The guide covers each one, starting at Claude Code, topic by topic.
Cursor
Cursor is a code editor built around AI, with the agent beside tab completion and inline edits. It also has a CLI, agent, and cloud agents that keep working while you are away. Cursor sells its own models in a weekly usage pool and, on Premium and above, other makers' models, Claude, GPT and Gemini among them, at their API list price. Its instructions are rule files that apply always, to matching files, or when the agent judges them relevant, and it reads AGENTS.md too.
Codex
Codex is OpenAI's agent: an open-source CLI, an IDE extension, the ChatGPT desktop app and cloud tasks, all using OpenAI's models and included in paid ChatGPT plans. It starts the most locked down of the 3. Commands run in an operating-system sandbox that limits writes to the project and turns the network off, with an approval policy deciding when it asks you, and permission profiles and rules files to adjust both.
Side by side
| Claude Code | Cursor | Codex | |
|---|---|---|---|
| Where it runs | Claude CodeTerminal, VS Code, JetBrains, a desktop app and the web. | CursorIts own editor, a CLI (agent) and cloud agents you check on the web or a phone. | CodexA CLI, an IDE extension, the ChatGPT desktop app, the web and iOS. |
| Models | Claude CodeClaude models, from Anthropic or through cloud providers such as Amazon Bedrock. | CursorCursor's own models in the plan; Claude, GPT and Gemini at API list price on Premium and above. | CodexOpenAI's models. With an API key, the models that key can use. |
| How you pay | Claude CodeA Claude plan (Pro, Max, Team or Enterprise) or an Anthropic Console account paid per token. | CursorPlans from $8 to $200 a month with a weekly usage pool; Teams from $30 a seat. | CodexA ChatGPT plan (Plus $20 a month, Pro from $100, Business) or an API key paid per token. |
| Project instructions | Claude CodeCLAUDE.md. Reads AGENTS.md instead when the project has no CLAUDE.md. | CursorRule files in .cursor/rules, each with when it applies, or AGENTS.md, nested by folder. | CodexAGENTS.md from the project root down to the current folder, up to 32 KiB by default. |
| Permission rules | Claude CodeAllow, ask and deny rules per tool in settings.json, such as Bash(npm test) or Read(./.env), plus modes. | CursorAllow and deny rules in .cursor/cli.json for the CLI; run modes and an allowlist in the editor. | CodexAn approval policy, permission profiles for files and network, and rules files for commands. |
| Sandbox | Claude CodeAn operating-system sandbox for shell commands, off until you turn it on. | CursorA sandbox for terminal commands, set by your run mode. | CodexAn operating-system sandbox, on by default, with the network off. |
| MCP servers | Claude Code.mcp.json in the project, or claude mcp add. | Cursor.cursor/mcp.json in the project, or ~/.cursor/mcp.json for every project. | Codex[mcp_servers] in config.toml, or codex mcp add. |
| Hooks | Claude CodeShell commands on events such as PreToolUse and Stop, in settings.json. | Cursorhooks.json, with events such as beforeShellExecution; can load Claude Code's hooks. | Codexhooks.json or [hooks] in config.toml, with events such as PreToolUse and Stop. |
| Scripts and CI | Claude Codeclaude -p "task", with the tools it may use. | Cursoragent -p "task"; add --force to let it change files. | Codexcodex exec "task". |
| Source code | Claude CodeClosed. | CursorClosed. | CodexThe CLI is open source, under Apache 2.0. |
The same project, set up for each
Start with the instructions every agent shares. All 3 read an AGENTS.md at the project root, so a team using several agents keeps one copy of its conventions:
# Shop API
- Install with `npm ci`. Run `npm test` before you say a change is done.
- The code is TypeScript in `src/`; each test sits beside its file as `*.test.ts`.
- Never open or print `.env`. If you need a value from it, ask.
- Never push. Leave the branch for review.
An instruction is only guidance. A model can misread it, and text inside a file or web page it reads can try to override it, which is prompt injectionPrompt InjectionAn attack that hides instructions in text a model reads, such as a web page, an email or a file, so the model follows the attacker instead of you.. So each agent also gets a file that enforces the rules that matter.
The same project set up for each agent: a TypeScript API whose instructions say to run the tests, never open .env and never push. The AGENTS.md above serves all 3; each agent then gets its own file that keeps the agent away from .env. Codex's files were run with Codex CLI 0.162: it loaded AGENTS.md into its prompt, and its sandbox refused cat .env and writes outside the project. Claude Code's settings were checked against the published settings schema, and the same sandbox limits run with Anthropic's sandbox runtime, which Claude Code is built on, refused .env even to a Node script. Cursor's file follows its documented format; Cursor's CLI was not run.
{
"$schema": "https://json.schemastore.org/claude-code-settings.json",
"permissions": {
"allow": ["Bash(npm test)", "Bash(npm run lint)"],
"deny": ["Read(./.env)", "Read(./.env.*)", "Bash(git push *)"]
},
"sandbox": {
"enabled": true,
"filesystem": { "denyRead": ["./.env", "./.env.*"] }
}
}
The permission rules run the tests without asking, refuse git push, and refuse .env to Claude's file tools and to commands it recognises, such as cat. The sandbox blocks .env for every shell command, including a script that opens the file itself.
{
"permissions": {
"allow": ["Shell(npm:test)", "Shell(npm:run lint)"],
"deny": ["Read(.env*)", "Shell(git:push*)"]
}
}
Cursor's CLI reads permissions from this project file; deny wins over allow. In the editor, .env files are on Cursor's default ignore list already, but its docs say ignore files do not stop the terminal or MCP tools.
approval_policy = "on-request"
default_permissions = "shop"
[permissions.shop]
extends = ":workspace"
[permissions.shop.filesystem.":workspace_roots"]
"**/.env*" = "deny"
The profile extends Codex's built-in workspace profile, which lets commands write inside the project only, and denies .env files to every command. Codex loads a project's .codex folder only once you trust the project.
The 3 files enforce them at different depths. Cursor's rules govern its CLI's own tools. Claude Code's rules cover its file tools and the commands it recognises, such as cat, and its sandbox, once enabled, blocks .env for every process a command starts. Codex's profile works at that same operating-system level from the start. When we ran the Codex profile, cat .env failed with "Operation not permitted", while writing a file inside src/ worked.
Codex keeps rules for commands in their own files. This one forbids pushing; match and not_match are examples Codex checks when it loads the file, so a wrong pattern fails at once. codex execpolicy check confirmed that git push origin main is forbidden and npm test is untouched:
# .codex/rules/default.rules
prefix_rule(
pattern = ["git", "push"],
decision = "forbidden",
justification = "Leave the branch for review; never push.",
match = ["git push", "git push origin main"],
not_match = ["git status"],
)
Which to use
I live in the terminal and want Claude models
Claude Code
It is built around the terminal, with the same agent in VS Code, JetBrains and the desktop app, and Claude models only.
I want an editor with the agent built in
Cursor
Cursor is the editor itself, with tab completion, inline edits and the agent in one place.
I want to switch between models from several makers
Cursor
Cursor offers its own models and, on Premium and above, Claude, GPT and Gemini, chosen per task.
I already pay for ChatGPT
Codex
Codex is included in ChatGPT Plus, Pro and Business, in the CLI, IDE extension and cloud.
The agent must not be able to read secrets or reach the network
Codex or Claude Code
Codex's sandbox is on by default and blocks files you deny for every process. Claude Code's does the same once you turn it on.
Agents in CI or scripts
Claude Code or Cursor or Codex
All 3 have a print mode for one task and an exit; give each only the permissions the job needs.
One team, several agents
Claude Code or Cursor or Codex
Keep shared instructions in AGENTS.md, which all 3 read, and each agent's limits in its own file.
Things to watch
- Instructions are not limits. Anything that must never happen, such as reading secrets or pushing, belongs in permission rules or a sandbox, not only in AGENTS.md or CLAUDE.md.
- Keep instructions short. Every line is read on every task and takes room in the context windowContext WindowEverything a model can see at once while it writes an answer, counted in tokens. When the window is full, something has to be left out.. Codex stops adding AGENTS.md files at 32 KiB by default.
- Trust before project settings load. Codex ignores a project's
.codexfolder until you trust the project, and Claude Code asks before using files a project imports from outside it. A cloned repository's settings are someone else's choices. - MCPModel Context ProtocolAn open standard for connecting AI applications to tools and data. A system offered once as an MCP server works in any application that speaks MCP. servers run with your access. All 3 can connect them. Add only servers you trust, and allow their tools one at a time.
To set Claude Code up for your own project, the settings builder writes the settings.json, MCP file and starter CLAUDE.md. To see what each Claude model costs per task, use the LLM cost calculator.
Questions
- What is the difference between Claude Code, Cursor and Codex?
- All 3 are AI coding agents that read code, edit files and run commands. Claude Code is Anthropic's, with Claude models, in the terminal, IDEs, a desktop app and the web. Cursor is an AI code editor, with a CLI and cloud agents, and models from several makers. Codex is OpenAI's, with OpenAI's models, in an open-source CLI, an IDE extension, the ChatGPT app and the cloud.
- Which is best, Claude Code, Cursor or Codex?
- There is no single best; it depends on how you work. If you want an editor, Cursor. If you work in the terminal, both Claude Code and Codex are built for it, and the choice is mostly the model family you prefer and how strictly you want the agent fenced in. Try each on a real task from your project before deciding.
- Can Cursor use Claude models?
- Yes. On Cursor's Premium plan and above, third-party models including Claude, GPT and Gemini are available at the maker's API list price, paid from prepaid credit. They are not part of the plan's included usage pool, which covers Cursor's own models.
- Do Claude Code, Cursor and Codex all read AGENTS.md?
- Yes. Codex and Cursor read AGENTS.md by default, including files in subfolders. Claude Code reads AGENTS.md when the project has no CLAUDE.md, or you can import it from a CLAUDE.md with @AGENTS.md. One AGENTS.md can hold the instructions every agent on a team shares.
- Is Codex free?
- No. Codex is included in paid ChatGPT plans, from Plus at $20 a month, or you can use it with an OpenAI API key and pay per token. The Codex CLI itself is open source under the Apache 2.0 licence.
- Which coding agent is the safest?
- Codex starts the most locked down, with an operating-system sandbox on by default that limits writes to the project and turns the network off. Claude Code has the same kind of sandbox, off until you enable it, and the most detailed permission rules. In every agent, rules in an instructions file are guidance; only permission rules and the sandbox enforce limits.
- Can I use more than one coding agent on the same project?
- Yes. Put the shared instructions in AGENTS.md and give each agent its own permission file, .claude/settings.json, .cursor/cli.json and .codex/config.toml, as in the example above. Each agent ignores the others' files.
Sources
Where each fact comes from
- 1Claude Code overview
- 2How Claude remembers your project
- 3Configure permissions
- 4Sandboxing
- 5Connect Claude Code to tools via MCP
- 6Hooks reference
- 7Run Claude Code programmatically
- 8Rules
- 9CLI
- 10CLI permissions
- 11Headless CLI
- 12Ignore file
- 13Agent security
- 14Terminal
- 15Model Context Protocol (MCP)
- 16Hooks
- 17Models and pricing
- 18Codex CLI
- 19Custom instructions with AGENTS.md
- 20Agent approvals and security
- 21Permissions
- 22Rules
- 23Config basics
- 24Hooks
- 25Model Context Protocol
- 26Codex pricing
- 27openai/codex