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.

By OmniAI Editorial · Nov 20, 2026 · 15 min read

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:

SurfaceWhere it runsBest for
Codex CLIYour terminal, on your machineHands-on work in a local repo, scripting, CI
IDE extensionVS Code, Cursor, Windsurf; JetBrains and Xcode have their own integrationsFocused edits with the files you have open
ChatGPT desktop appmacOS, Windows and LinuxCodex chats on local folders alongside other ChatGPT work
Codex CloudOpenAI's cloud, from the web, desktop app or mobileLonger 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 codex

On 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:

codex

The 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 project

Then 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

CommandWhat it does
codexStart an interactive session in the current folder
codex resumeReopen a recent chat from this repository
codex --image screenshot.pngAttach an image, such as an error screenshot or a design
codex --searchAllow live web search for tasks that need current docs
codex exec "..."Run a task non-interactively, for scripts and CI
codex cloudBrowse and submit cloud tasks, and apply results locally
codex mcpAdd and manage MCP servers that give Codex extra tools
/permissionsInside 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:

  1. 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.
  2. Open the sidebar. Click the Codex icon, or open the Command Palette and run Codex: Open Codex Sidebar.
  3. Sign in with your ChatGPT account or an API key.
  4. 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.
  5. 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.
  6. 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.

A light code editor window drawn in ink with a grey sidebar panel on its right, ink lines of code in the main area and one orange highlighted line.
In the IDE extension, Codex works beside the files you already have open.

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.

  1. Open ChatGPT on the web or desktop, start a chat and choose Work in > Cloud. On mobile, open Codex.
  2. 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.
  3. Send a task, for example "Find why the nightly export job times out and propose a fix with a test."
  4. 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 exec in 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 CLICodex in the desktop or web app
Where it worksYour terminal, in a local repositoryA window with chats, projects and cloud tasks
Best forDevelopers who live in the terminal, scripting, CIManaging several tasks, reviewing diffs visually, mobile follow-up
Local or cloudLocal by default; can send tasks to the cloudLocal folders and cloud tasks
Automationcodex exec for scripts and pipelinesMostly 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_providers section,
  • 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 /permissions in 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:

PlanPriceCodex access
Free$0Limited Codex in the desktop app, subject to rollout
Go$8 a monthLimited, for lightweight tasks
Plus$20 a monthCodex on web, CLI, IDE extension and iOS; cloud integrations like code review and Slack
Pro$100, $200 or $500 a monthMuch higher usage; the $500 plan adds an extra-fast mode
Business$20 per user a month billed annually ($25 monthly), 2+ usersWorkspace with admin controls and no training on business data by default
Enterprise and EduContact salesEnterprise security, audit logs, data residency
API keyPay per tokenCLI, 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 CodexClaude Code
Made byOpenAIAnthropic
SurfacesCLI, IDE extension, desktop app, cloud tasks, mobileCLI, IDE extensions, desktop and web
Included withChatGPT Plus, Pro, Business, EnterpriseClaude Pro, Max, Team, Enterprise
Project instructionsAGENTS.mdCLAUDE.md
Remote tasksCodex Cloud environmentsClaude Code on the web
ExtensibilityMCP servers, skills and pluginsMCP 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

  1. Describe the goal and the check. "Fix the bug and make pnpm test pass" beats "fix the bug".
  2. Point to the right files or attach a screenshot of the error.
  3. Ask for a plan first on big changes, then approve it before Codex edits.
  4. Keep tasks small. Several focused tasks are easier to review than one huge diff.
  5. Run reviews before you merge, with Codex's review feature or a teammate.
  6. Teach it once: when Codex repeats a mistake, add a rule to AGENTS.md.
Four light cards in a row connected by ink arrows, each card with ink lines, the last card marked with an orange check-shaped stroke.
Plan, edit, test and review: the loop that keeps an agent's changes safe to merge.

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.

All articles

Read next

Language

EnglishEnglish · en TürkçeTurkish · tr DeutschGerman · de العربيةArabic · ar

Account

Enter your email. We’ll send you a sign-in link and a 6-digit code. No password needed.

Sign in

Theme

Language

Show our email address

To keep spam out of our inbox, please confirm your own email first. We will send you a 6-digit code.

We send codes only to these providers: gmail.com, googlemail.com, outlook.com, hotmail.com, live.com, msn.com, proton.me, protonmail.com, pm.me, icloud.com, me.com, mac.com, yahoo.com, aol.com, gmx.de, gmx.net, web.de, t-online.de, yandex.com, omniai.blog