Codex CLI: what it is, how to install it, and how to use it
Codex CLI is OpenAI's coding agent that runs in your terminal. It reads your repository, edits files and runs commands, asking before it does anything risky. Install it with npm install -g @openai/codex, a shell installer or Homebrew, then run codex and choose Sign in with ChatGPT or use an API key. It is open source under Apache-2.0. Plus, Pro, Business and Enterprise ChatGPT plans include it, or you pay API rates.
What is Codex CLI?
Codex CLI is a coding agent from OpenAI that you run inside a terminal, in the folder of a project. You describe a task in plain English. It reads the files it needs, proposes edits, runs commands such as your test suite, and shows you the diff. OpenAI's own description is that it lets you inspect, edit and run code from your terminal. The source is public at github.com/openai/codex under the Apache-2.0 license.
It is one surface of a larger product called Codex. The same agent also runs in a desktop app, an IDE extension and in the cloud. The CLI is the one to pick when you already live in a terminal, want to script the agent, or want it to run in CI. If you want the product overview instead of the command-line tool, read what OpenAI Codex is.
| Capability | What it means in practice | Command or setting |
|---|---|---|
| Work in your repository | Reads files, edits them, runs your own tools | codex (interactive) |
| Choose how much freedom it has | Sandbox mode plus approval policy | /permissions, --sandbox, --ask-for-approval |
| Resume earlier work | Reopen a saved chat from the same repository | codex resume |
| Review before you commit | Reports prioritized findings without touching your working tree | /review or codex review |
| Script it | Run once, print the result, exit | codex exec |
| Hand work to the cloud | Submit a task to a cloud environment and apply the result locally | codex cloud, codex apply |
| Connect tools | Add MCP servers to your session | codex mcp |
Codex CLI is a tool for people who are comfortable reading a diff. If you cannot read code at all, a browser-based builder is a better start. The board has an idea page for developer tools if you want something to point the agent at.
How do you install Codex CLI?
OpenAI documents four ways to install it. All of them give you the same codex command. The shell and PowerShell installers need no Node.js. The npm route needs it.
| Method | Install | Update |
|---|---|---|
| macOS or Linux installer | curl -fsSL https://chatgpt.com/codex/install.sh | sh | Run the same command again |
| Windows installer (PowerShell) | powershell -ExecutionPolicy ByPass -c "irm https://chatgpt.com/codex/install.ps1 | iex" | Run the same command again |
| npm | npm install -g @openai/codex | npm install -g @openai/codex |
| Homebrew | brew install --cask codex | brew upgrade --cask codex |
The docs say to start the Windows installer from a new PowerShell window. Piping a script from the internet into a shell is a trade-off: the installers download from OpenAI's release host and fall back to GitHub Releases, per the repository README. If you prefer to read before you run, download the script first, open it, then execute it. You can also download a binary from the latest GitHub release.
# install curl -fsSL https://chatgpt.com/codex/install.sh | sh # check it is on your PATH codex --version # go to a project and start it cd ~/code/my-project codex # update later: run the installer again curl -fsSL https://chatgpt.com/codex/install.sh | sh
How do you sign in to Codex CLI?
Open a project folder and run codex. The first time, choose Sign in with ChatGPT. A browser window opens, you sign in, and the browser hands credentials back to the CLI. You can also run codex login directly. The authentication page lists two methods for local work: a ChatGPT sign-in for subscription access, or an API key for usage-based access.
# put the key in an environment variable first (never in a file you commit) export OPENAI_API_KEY="your-key-here" # pipe it to codex login printenv OPENAI_API_KEY | codex login --with-api-key # confirm which method is active (exit code 0 when credentials exist) codex login status # clear stored credentials codex logout
The two methods are billed differently, and they do not give the same features. With an API key, usage is billed to your OpenAI Platform account at standard API rates instead of drawing on your plan's included credits. The docs also say that features relying on ChatGPT workspace access or cloud services are limited or unavailable on an API key. Cloud tasks require a ChatGPT sign-in. The docs recommend API-key sign-in for CI jobs and say not to expose Codex execution in untrusted or public environments.
How do you run your first task?
Start with a task that is easy to check, so you learn how the tool behaves before you trust it with a big change.
- Commit your current state. A clean working tree makes the diff easy to read.
- Run `codex` in the project root. The banner shows the model, the directory and a few starter commands such as /init, /status, /permissions, /model and /review.
- Ask it to explain before it edits. The docs suggest a prompt as plain as “Tell me about this project”. Check that its summary matches what you know.
- Give one focused change. Name the file, the behavior and the test that should pass. Type @ to search for a file and add its path to the prompt.
- Read each proposed command and diff. Approve, decline, or type a correction. Press Enter while it works to inject new instructions into the current turn.
- Run `/diff`, then `/review`. /diff shows the Git diff including untracked files. /review asks Codex to look over your working tree for behavior changes and missing tests.
- Commit. Then start the next task from a clean state.
In this repository, add input validation to the signup form in src/components/SignupForm.tsx. Behavior: reject empty names and emails without an @ sign, and show the error under the field. Do not change the API route or add new dependencies. Done when: the existing tests pass and you have added two tests for the new rules. Run the test command and show me the result before you stop.
For the general craft of writing a brief like this, see how to write an app build prompt. Every idea on the board comes with a generated build prompt in the same spirit that you can paste straight into a terminal agent.
What are Codex CLI's approval modes and sandbox settings?
Codex separates two controls. The sandbox mode decides what the agent can do technically: where it can write and whether it can reach the network. The approval policy decides when it must stop and ask you. By default, the agent runs with network access off, and the sandbox limits writes to the current workspace, per the approvals and security page.
Switch presets in a session with /permissions. The picker offers Auto, Read Only and, where you have named profiles, those too.
| Goal | Flags | What happens |
|---|---|---|
| Everyday work (the Auto preset) | --sandbox workspace-write --ask-for-approval on-request | Reads files, edits and runs commands in the workspace. Asks before editing outside it or using the network. |
| Look but do not touch | --sandbox read-only --ask-for-approval on-request | Reads and runs commands inside a read-only sandbox. Anything outside can prompt. |
| Read-only in CI | --sandbox read-only --ask-for-approval never | Never asks. Cannot write. |
| Reviewed approvals | --sandbox workspace-write --ask-for-approval on-request -c approvals_reviewer=auto_review | Eligible requests go to an automatic reviewer instead of to you. |
| No guard rails | --dangerously-bypass-approvals-and-sandbox (alias --yolo) | No sandbox and no approvals. The docs mark this as not recommended. |
- Default start. In a Git-tracked folder Codex starts in Auto. In a folder without version control it starts read-only, and may stay read-only until you trust the directory.
- Protected paths. Even in a writable root, the
.git,.agents,.codexand.awsdirectories are read-only. - Network access. Off by default in the workspace-write sandbox. Turn it on in config with
network_access = trueunder[sandbox_workspace_write], and consider the network proxy feature to allow only named domains. - Retired setting. The older
untrustedapproval policy is no longer supported, and a leftoverapproval_policy = "untrusted"can stop the client from starting. Remove it from your config. - Extra folders. To let the agent write somewhere else, prefer
--add-dirover switching to full access.
What are the core Codex CLI commands?
There are two layers: commands you type in your shell, and slash commands you type inside a running session. Type / to open the slash list and keep typing to filter it. While Codex is working, Tab queues a command for the next turn.
| Command | What it does |
|---|---|
| codex | Opens the interactive terminal UI |
| codex "prompt" | Starts the UI with a first prompt |
| codex exec "task" (or codex e) | Runs once without human interaction, then exits |
| codex resume | Continues an interactive session by ID, or the most recent one for this directory with --last |
| codex fork | Copies a previous session into a new chat |
| codex review | Runs a code review non-interactively on uncommitted changes, a commit or a base branch |
| codex login / logout / login status | Manage authentication |
| codex mcp | Add and manage MCP servers in config.toml |
| codex cloud | Browse, submit and list cloud chats |
| codex apply | Applies the latest diff from a cloud chat to your local repository |
| codex doctor | Prints a diagnostic report on installation, config and authentication |
| codex completion | Generates shell completions, for example codex completion zsh |
| Command | Use it to |
|---|---|
| /init | Generate an AGENTS.md scaffold in the current directory |
| /status | See the active model, approval policy, writable roots and context left |
| /permissions | Change the approval preset mid-session |
| /model | Choose the model and reasoning effort |
| /diff | Show the Git diff, including untracked files |
| /review | Ask for a review of your working tree |
| /compact | Summarize a long chat to free up context |
| /mention | Attach a file or folder to the chat |
| /new, /resume | Start fresh or return to a saved chat |
Two shortcuts are worth learning on day one. Prefix a line with ! to run a local shell command under your current approval and sandbox settings. Press Escape twice with an empty prompt to edit your previous message and fork the chat from that point. The full list sits in the developer commands reference.
What is AGENTS.md and how does Codex use it?
AGENTS.md is a plain Markdown file of standing instructions. Codex reads it before it does any work, so you do not repeat yourself in every prompt. Run /init to create a first version, then edit it. The rules for discovery come from the AGENTS.md guide.
- Global. In your Codex home folder (
~/.codexunless you set CODEX_HOME), Codex readsAGENTS.override.mdif it exists, otherwiseAGENTS.md. It uses only the first non-empty file at this level. - Project. From the project root (usually the Git root) down to your current directory, it checks each folder for
AGENTS.override.md, thenAGENTS.md, then any fallback names you configured. At most one file per folder. - Merge. Files are joined from the root down, so the file closest to where you are wins on conflict.
Codex stops adding files once the combined size reaches 32 KiB by default (the project_doc_max_bytes setting). Keep the file short enough to be read, and put team-specific rules in nested folders. For a longer treatment of the format, which other tools also read, see the guide to AGENTS.md.
# AGENTS.md ## What this project is [Two sentences: who uses it and what it does.] ## Commands - Install: pnpm install - Dev server: pnpm dev - Tests: pnpm test (run before saying a task is done) - Lint: pnpm lint ## Rules - Make the smallest change that satisfies the task. - Do not add dependencies without asking. - Never write secrets into source files. Read them from environment variables. - Do not edit generated files or anything under /migrations without asking. ## Out of scope for now [Your later list: written down so the agent does not build it.]
How do you run Codex CLI in scripts and CI?
codex exec runs one task and exits. By default it uses a read-only sandbox, so a script that only needs analysis is safe by default. Grant the least you need for the job, per the non-interactive mode docs.
# analysis only (default sandbox is read-only) codex exec "summarize the repo structure" # allow edits inside the workspace codex exec --sandbox workspace-write "fix the failing lint errors" # pipe input in curl -s https://example.com/data.json | codex exec "format the top 20 items into a markdown table" > table.md # newline-delimited JSON events for tooling codex exec --json "summarize the repo structure" | jq # CI: capture progress and a final summary codex exec --json --output-last-message summary.txt "review the diff for risky changes"
- `--full-auto` is gone. The docs say it is no longer supported. Use
--sandbox workspace-write, or--approve-for-meto send approval requests through automatic review. - Reproducible runs.
--ignore-user-configskips your personal config.toml, and--ignore-rulesskips execution-policy rule files. - Use an API key in CI. Create a key for the job, store it as a secret, and run
codex login --with-api-keyfrom stdin.
How much does Codex CLI cost?
The tool is free to install. What you pay for is the model usage behind it. As of October 2026, the Codex pricing page lists these routes.
| Route | Price | What to know |
|---|---|---|
| Free | USD 0 | Listed for exploring Codex on quick coding tasks. The Free and Go cards mention the desktop app, subject to rollout, so check the CLI is included before you rely on it. |
| Go | USD 8 a month | Lightweight coding tasks |
| Plus | USD 20 a month | Codex on the web, in the CLI, in the IDE extension and on iOS; cloud code review and Slack; extra usage through ChatGPT credits |
| Pro | From USD 100 a month | Tiers at USD 100, 200 and 500 a month; higher limits |
| Business | USD 20 per user a month on annual billing (USD 25 billed monthly), 2+ users | Workspace admin controls, SSO, no training on business data by default |
| API key | Pay at API rates | Works in CLI, SDK and IDE extension. No cloud features such as GitHub review or Slack. |
Included usage is not a fixed message count. The pricing page gives local-message estimates per five-hour window for Plus and standard Business, which vary by model, and says Pro plans currently have no five-hour limit. It also says cloud tasks can use more of your allowance than local messages, and that API token prices should not be used to estimate what a subscription includes. Check the usage dashboard for your real limits.
What should you build with Codex CLI?
Pick a task with a clear finish line, like “add this validation and make the tests pass”, and run it in Auto. Terminal agents are strongest at tasks with a fast feedback loop: a failing test, a linter, a type error, a build that either passes or does not.
- A small tool nobody has built yet. Browse the developer-tools ideas on the board. One posted idea asks for a way to see which of your abandoned repos is closest to finished. Every idea has a ready build prompt you can paste into Codex.
- A chore you do by hand. Changelogs, dependency bumps, test scaffolding.
- Reviews of your own diffs.
/reviewbefore every commit costs little and catches missed tests.
If you have an idea you will never build yourself, you can post it on the board for someone with a terminal agent to pick up. To compare Codex with Anthropic's equivalent, read Claude Code vs Codex.
Frequently asked questions
Is Codex CLI free?
The CLI is free and open source under the Apache-2.0 license, but the models behind it are paid for. You use it through a ChatGPT plan (Plus, Pro, Business or Enterprise are the ones the pricing page lists for the CLI) or pay API rates with an API key. As of October 2026, Plus is USD 20 a month and includes Codex in the CLI.
How do I install Codex CLI on Windows?
Open a new PowerShell window and run the official installer: powershell -ExecutionPolicy ByPass -c "irm https://chatgpt.com/codex/install.ps1 | iex". You can also install with npm using npm install -g @openai/codex. Then open a project folder, run codex, and sign in with ChatGPT or an API key.
What is the difference between Codex and Codex CLI?
Codex is OpenAI's coding agent product, available in a desktop app, an IDE extension, the cloud and the terminal. Codex CLI is the terminal version. It works on your local repository, can be scripted with codex exec, and can send tasks to Codex cloud. Cloud tasks need a ChatGPT sign-in rather than an API key.
Is Codex CLI safe to run on my own code?
It is built with guard rails: by default it has no network access and can only write inside your workspace, and it asks before going beyond that. Safety depends on the mode you pick. Stay on the Auto preset, commit before each task, read the diff, and avoid full access outside a disposable container or VM.
Can I use Codex CLI with an API key instead of ChatGPT?
Yes. Pipe the key to the login command with printenv OPENAI_API_KEY | codex login --with-api-key. Usage is then billed at standard API rates instead of drawing on plan credits. Cloud features such as GitHub code review and Slack are not available with an API key, and the docs recommend it for CI jobs.
Does Codex CLI read AGENTS.md or CLAUDE.md?
Codex reads AGENTS.md. It checks a global file in your Codex home folder, then each folder from the project root down to your current directory, and merges them with the closest file winning. You can configure fallback file names in config.toml. Run /init to generate a starter AGENTS.md.
Created with AI assistance and edited for this site. Examples are illustrative and do not represent customer research. About the publisher.