Dev tools
How to Use OpenAI Codex: CLI, IDE and Cloud
How to use OpenAI Codex step by step: install the CLI, use it in VS Code or Cursor, run cloud tasks, write AGENTS.md, set permissions, and compare plans.
Here's how to use OpenAI Codex: sign in with your ChatGPT account and pick a surface: the Codex CLI in your terminal (npm install -g @openai/codex, then run codex in your project), the Codex IDE extension in VS Code, Cursor or Windsurf, or Codex Cloud for tasks that run remotely while you do something else. Codex is OpenAI's coding agent: it reads your code, edits files, runs commands and tests, and shows you a diff to review. It's included in paid ChatGPT plans and can also run on an API key.
This guide shows how to use OpenAI Codex on each surface step by step, how to give it project instructions, how to control what it may do, what each plan includes, and how it compares with Claude Code.
What Is OpenAI Codex?
Codex is an AI coding agent. Instead of only suggesting the next line, it works on a whole task: "fix this failing test", "add pagination to this endpoint", "explain how authentication works in this repo". It plans the change, edits files, runs your tools, checks the result and reports back with a summary and a diff.
It runs in four places that share the same account and usage:
| Surface | Where it runs | Best for |
|---|---|---|
| Codex CLI | Your terminal, on your machine | Hands-on work in a local repo, scripting, CI |
| IDE extension | VS Code, Cursor, Windsurf; JetBrains and Xcode have their own integrations | Focused edits with the files you have open |
| ChatGPT desktop app | macOS, Windows and Linux | Codex chats on local folders alongside other ChatGPT work |
| Codex Cloud | OpenAI's cloud, from the web, desktop app or mobile | Longer tasks that keep running while your laptop sleeps |
Don't confuse this with the original "OpenAI Codex" model from 2021, which powered early GitHub Copilot. Today's Codex is an agent product built on OpenAI's current models.
How to Use OpenAI Codex CLI
The OpenAI Codex CLI is the most flexible way to use Codex. These steps follow OpenAI's official docs.
1. Install the CLI
Pick one method:
# macOS and Linux: standalone installer
curl -fsSL https://chatgpt.com/codex/install.sh | sh
# npm (any platform with Node.js)
npm install -g @openai/codex
# Homebrew
brew install --cask codexOn Windows, OpenAI provides a PowerShell installer:
powershell -ExecutionPolicy ByPass -c "irm https://chatgpt.com/codex/install.ps1 | iex"2. Sign in
Open your project folder and run:
codexThe first time, choose Sign in with ChatGPT to use your plan's included usage, or sign in with an API key to pay per token instead.
3. Start with a safe first task
Ask something read-only first so you can see how it explores your code:
Tell me about this projectThen try a focused change: "Add input validation to the signup form and update the tests." Codex will show the commands it runs and the files it changes.
4. Create Git checkpoints
OpenAI's docs recommend committing before and after each task, so you can always roll back. Work on a branch, and review the diff before you commit Codex's changes.
Useful CLI commands
| Command | What it does |
|---|---|
codex | Start an interactive session in the current folder |
codex resume | Reopen a recent chat from this repository |
codex --image screenshot.png | Attach an image, such as an error screenshot or a design |
codex --search | Allow live web search for tasks that need current docs |
codex exec "..." | Run a task non-interactively, for scripts and CI |
codex cloud | Browse and submit cloud tasks, and apply results locally |
codex mcp | Add and manage MCP servers that give Codex extra tools |
/permissions | Inside a session: choose when Codex may edit files or run commands without asking |
The CLI can also review changes before you ship: point it at uncommitted changes, a commit or a base branch, and it reports prioritized findings without modifying your working tree.
How to Use OpenAI Codex in VS Code
Here's how to use OpenAI Codex in VSCode (Visual Studio Code) and similar editors:
- Install the extension. In VS Code, Cursor or Windsurf, search the extension marketplace for the official OpenAI Codex extension (published by OpenAI) and install it.
- Open the sidebar. Click the Codex icon, or open the Command Palette and run Codex: Open Codex Sidebar.
- Sign in with your ChatGPT account or an API key.
- Add context. Reference open files, a selection or a recent chat directly from the composer, so Codex starts with the code you're looking at.
- Review changes in place. Codex shows a summary and the changed lines; keep the edits you want and ask for follow-ups in the same chat.
- Delegate bigger tasks to Codex Cloud from the extension, then come back to review the result.
In JetBrains IDEs, open AI Chat and select Codex. In Xcode, open the coding assistant, start a new chat and choose Codex as the agent.
How to Use Codex Cloud
Codex Cloud runs tasks in a remote workspace, so they keep going while your computer is asleep, and you can start several in parallel.
- Open ChatGPT on the web or desktop, start a chat and choose Work in > Cloud. On mobile, open Codex.
- Pick an environment. Use the default environment to start without a repository, select a published environment someone prepared, or connect GitHub or GitLab so Codex can check out your repository.
- Send a task, for example "Find why the nightly export job times out and propose a fix with a test."
- Review the result: inspect changed files and test output, ask for follow-up changes, then commit or open a pull request.
For real projects, create and publish an environment that installs your dependencies and tools once, so every task starts ready to run. You can control the environment's internet access and supply secrets for the services it needs.
Paid plans also include cloud integrations such as automatic code review on GitHub pull requests and a Slack integration.
What You Can Do With Codex: Real Use Cases
Once Codex is set up, these are the tasks where it tends to save the most time:
- Understand an unfamiliar codebase. Ask "How does a request flow from the API to the database?" or "Where is billing calculated?" and let it read the code and summarize, with file references.
- Fix bugs from an error. Paste the stack trace or attach a screenshot, and ask it to reproduce the bug with a failing test before fixing it.
- Write and extend tests. Ask for tests around code you're about to change, then make the change with a safety net.
- Refactor safely. Rename modules, split large files or migrate to a new library version, with tests run after each step.
- Review your own changes. Run a review on your branch before you open a pull request, and fix the findings first.
- Update documentation. Generate or refresh READMEs, docstrings and API docs from the actual code.
- Handle chores in parallel. Send several small cloud tasks at once, such as dependency updates, lint fixes and small features, and review each result separately.
- Automate in CI. Use
codex execin a pipeline to triage failing builds, label issues or draft fixes for a human to approve.
Tasks with clear success criteria, like a failing test that must pass, get the best results. Vague tasks like "improve the code" get vague results.
Codex CLI vs the Codex App
A common question is whether to use the Codex CLI or the app (the ChatGPT desktop app's Codex mode, or Codex in the browser).
| Codex CLI | Codex in the desktop or web app | |
|---|---|---|
| Where it works | Your terminal, in a local repository | A window with chats, projects and cloud tasks |
| Best for | Developers who live in the terminal, scripting, CI | Managing several tasks, reviewing diffs visually, mobile follow-up |
| Local or cloud | Local by default; can send tasks to the cloud | Local folders and cloud tasks |
| Automation | codex exec for scripts and pipelines | Mostly interactive |
They share the same account and usage, so many developers use both: the CLI or IDE extension for hands-on work, the app for monitoring longer cloud tasks.
How to Use OpenAI Codex for Free
There are a few ways to try Codex without paying for Plus:
- Free and Go plans include limited Codex access in the desktop app, subject to rollout.
- Business and Enterprise users may already have Codex through their company's ChatGPT workspace; check with your admin.
- API credits: if you already have OpenAI API credits, sign in with an API key and you pay only for the tokens you use, which can be cheap for small tasks.
For regular use, Plus is the simplest option, because the included allowance usually costs less than paying API rates for the same amount of agent work.
Use Codex With an API Key or Another Provider
Codex isn't tied to ChatGPT sign-in. In the CLI and IDE extension you can sign in with an OpenAI API key instead. The local client is configured with a config.toml file, which lets you:
- point the built-in OpenAI provider at a different base URL, such as a company proxy, an LLM gateway or a data-residency project,
- define other model providers in a
model_providerssection, - use OpenAI models through Amazon Bedrock, which OpenAI documents as a supported setup.
That's useful for companies that must route all AI traffic through their own gateway or cloud account. Check OpenAI's configuration reference for the exact keys, because they change between versions.
Give Codex Project Instructions With AGENTS.md
Codex reads an AGENTS.md file in your repository for project-specific instructions. Use it to tell the agent what a new teammate would need:
# AGENTS.md
## Setup
- Install with `pnpm install`; Node 20.
## Commands
- Run tests: `pnpm test`
- Lint and format: `pnpm lint --fix`
## Rules
- Write tests for every bug fix.
- Never edit files in `migrations/` without asking.
- Use the existing logger, not console.log.Short, specific instructions work best. Our guide to AGENTS.md explains what to put in the file and how other coding agents read it too.
Control What Codex Can Do
Codex can edit files and run commands, so set boundaries that match the task:
- Permissions: use
/permissionsin the CLI (or the extension's settings) to choose whether Codex asks before editing files and running commands, or works more autonomously inside a sandbox. - Sandbox and writable folders: check which folders Codex may write to before you start.
- Git as a safety net: commit before each task and review every diff.
- Network access: in Codex Cloud, limit which services an environment can reach and which secrets it gets.
- Sensitive repos: keep secrets out of the repository and the environment unless the task truly needs them.
OpenAI Codex Pricing
Codex shares usage limits with ChatGPT's work features. According to OpenAI's Codex pricing page:
| Plan | Price | Codex access |
|---|---|---|
| Free | $0 | Limited Codex in the desktop app, subject to rollout |
| Go | $8 a month | Limited, for lightweight tasks |
| Plus | $20 a month | Codex on web, CLI, IDE extension and iOS; cloud integrations like code review and Slack |
| Pro | $100, $200 or $500 a month | Much higher usage; the $500 plan adds an extra-fast mode |
| Business | $20 per user a month billed annually ($25 monthly), 2+ users | Workspace with admin controls and no training on business data by default |
| Enterprise and Edu | Contact sales | Enterprise security, audit logs, data residency |
| API key | Pay per token | CLI, SDK and IDE extension only; no cloud features |
Eligible plans can extend usage with ChatGPT credits when you run out. For automation in CI, an API key is usually the better fit because usage is billed directly and doesn't use a person's allowance.
Codex vs Claude Code
Codex vs Claude Code is the comparison most developers make, since both are terminal-first coding agents that also run in editors.
| OpenAI Codex | Claude Code | |
|---|---|---|
| Made by | OpenAI | Anthropic |
| Surfaces | CLI, IDE extension, desktop app, cloud tasks, mobile | CLI, IDE extensions, desktop and web |
| Included with | ChatGPT Plus, Pro, Business, Enterprise | Claude Pro, Max, Team, Enterprise |
| Project instructions | AGENTS.md | CLAUDE.md |
| Remote tasks | Codex Cloud environments | Claude Code on the web |
| Extensibility | MCP servers, skills and plugins | MCP servers, skills, hooks, subagents |
Both are strong; the practical decision is usually which subscription you already pay for and which model you prefer for your codebase. Our Claude Code vs Cursor vs Codex comparison goes deeper on quality and workflow, and our guide on how to use Claude Code covers Anthropic's agent step by step.
Troubleshooting Common Codex Problems
Codex can't run your tests. It only has the tools installed where it runs. Locally, make sure the project builds in your terminal first. In Codex Cloud, add the install and setup steps to the environment, publish it, and start new tasks from that environment.
It changes too much at once. Ask for a plan first, approve it, and break the work into smaller tasks. Point it to the specific files and say what must not change.
It keeps repeating a mistake. Add a rule to AGENTS.md, and if possible a test or lint check that fails when the mistake happens. A failing check teaches the agent faster than any instruction.
You hit usage limits. Limits reset over time; eligible plans can add ChatGPT credits, and heavy users can move to a Pro plan. Use faster, lighter settings for simple tasks and save the strongest model and longest reasoning for hard problems.
Sign-in problems in the CLI. Run codex again and choose the sign-in method you want. On a remote machine without a browser, follow the device sign-in steps in OpenAI's authentication docs, or use an API key.
It suggests outdated library usage. Allow web search for that task with codex --search, or paste the relevant part of the library's current documentation into the prompt.
Tips for Getting Good Results
- Describe the goal and the check. "Fix the bug and make
pnpm testpass" beats "fix the bug". - Point to the right files or attach a screenshot of the error.
- Ask for a plan first on big changes, then approve it before Codex edits.
- Keep tasks small. Several focused tasks are easier to review than one huge diff.
- Run reviews before you merge, with Codex's review feature or a teammate.
- Teach it once: when Codex repeats a mistake, add a rule to AGENTS.md.
Does Codex Work on Windows?
Yes. OpenAI provides a PowerShell installer for the Codex CLI on Windows, the IDE extension works in VS Code, Cursor and Windsurf on Windows, and the ChatGPT desktop app with Codex is available for Windows as well as macOS and Linux. If a project's tooling expects a Unix shell, running it inside WSL can avoid path and script issues.
FAQ
Is OpenAI Codex free?
Codex has limited access on the Free and Go plans. Full access, including the CLI, IDE extension and cloud tasks, comes with ChatGPT Plus, Pro, Business, Enterprise and Edu, or by paying per token with an API key.
How do I install the OpenAI Codex CLI?
Run npm install -g @openai/codex, use Homebrew with brew install --cask codex, or use OpenAI's standalone installer. Then run codex in your project folder and sign in with ChatGPT or an API key.
Can I use Codex in Cursor?
Yes. The official Codex extension installs in Cursor and Windsurf as well as VS Code. Open the Codex sidebar, sign in and use it alongside the editor's own AI features.
Can I use Codex with an API key?
Yes. With an API key you can use the CLI, SDK and IDE extension and pay per token at API prices. Cloud features such as GitHub code review and Slack aren't available with API-key sign-in.
Is Codex better than Claude Code?
Neither is better for everyone. Both edit code, run commands and review changes. Try both on a real task in your own codebase; most developers choose based on results with their stack and the subscription they already have.