Install with the official installer, npm, or Homebrew, run codex in a repository, and pick "Sign in with ChatGPT". Two settings decide how it behaves: the sandbox policy (read-only, workspace-write, or danger-full-access, defaulting to workspace-write) and the approval policy (untrusted, on-request, or never, defaulting to on-request). Everything else lives in ~/.codex/config.toml, and codex exec runs the whole thing non-interactively for CI.
- Codex is included with ChatGPT plans. You can also authenticate with an API key.
- The sandbox is the core concept:
read-only,workspace-write, ordanger-full-access. The default isworkspace-writewith network off. - Approvals are a separate dial:
untrusted,on-request,never. The oldon-failurevalue and the--full-autoshorthand are gone. - Config lives at
~/.codex/config.toml;CODEX_HOMErelocates the whole root, which is how you run two accounts. codex execruns non-interactively and exits, with--jsonfor machine-readable events.- Reasoning effort is a real lever:
minimal,low,medium,high,xhigh.
Install and sign in
Four install paths, all producing the same binary. The curl installer is the one OpenAI documents first and the one that self-updates cleanly.
# macOS / Linux, the official installer
curl -fsSL https://chatgpt.com/codex/install.sh | sh
# Windows (PowerShell)
powershell -ExecutionPolicy ByPass -c "irm https://chatgpt.com/codex/install.ps1 | iex"
# npm
npm install -g @openai/codex
# Homebrew (it is a cask, not a formula)
brew install --cask codex
codex --version
System requirements from the Codex repository, August 2026.
| Requirement | Detail |
|---|---|
| Operating system | macOS 12+, Ubuntu 20.04+ / Debian 10+, or Windows 11 via WSL2 |
| Git | 2.23+ recommended for the built-in PR helpers |
| RAM | 4 GB minimum, 8 GB recommended |
Sign in
Run codex inside a project and pick Sign in with ChatGPT. That is the path most people want: it bills against your existing subscription rather than a metered API key. As of August 2026 OpenAI lists Codex as included in the Free, Go, Plus, Pro, Business, Edu, and Enterprise ChatGPT plans, with the allowance scaling by tier rather than the feature set changing.
codex login # opens the ChatGPT sign-in flow
codex logout # removes stored credentials
codex update # update in place
codex doctor # diagnose install, config, auth, and runtime health
Subscription credentials land in auth.json under the config root. Because that path is derived from CODEX_HOME, pointing it somewhere else is how you run a second account without the two clobbering each other.
CODEX_HOME="$HOME/.codex-work" codex login
CODEX_HOME="$HOME/.codex-work" codex
The sandbox model
This is the part that distinguishes Codex and the part worth understanding before you run it on a real repository. Instead of interrupting you for permission on each action, Codex enforces a policy at the operating-system level about what the agent can reach.
Sandbox modes, checked against the Codex sandboxing documentation in August 2026.
| Mode | Read | Write | Network | Use for |
|---|---|---|---|---|
read-only | Yes | No | Approval needed | Research, review, planning |
workspace-write (default) | Yes | Workspace only | Approval needed | Normal development |
danger-full-access | Yes | Anywhere | Unrestricted | Containers you can throw away |
codex -s read-only # research only, cannot modify anything
codex -s workspace-write # the default, and the sensible one for real work
codex -s danger-full-access # no boundaries at all
It is enforced by the OS, not by the model
The containment is real rather than an instruction in a system prompt. Codex uses platform-native enforcement: Seatbelt on macOS, bubblewrap on Linux and WSL2 (a bundled helper is available as a fallback), and the native Windows sandbox in PowerShell. A model that decides to write outside the workspace does not get talked out of it, it gets an error from the kernel.
Approval policy is the second dial
The sandbox governs what is possible. The approval policy governs when Codex stops to ask you. Three values, and the list is shorter than it used to be.
| Value | Behaviour |
|---|---|
untrusted | Runs only commands on the trusted list (ls, cat, sed and similar) without asking. Escalates everything else. |
on-request (default) | The model decides when it needs you. Asks before leaving the sandbox, reaching the network, or writing outside the workspace. |
never | Never prompts. Execution failures are returned to the model instead of to you. |
codex -a untrusted # ask before anything not on the trusted list
codex -a on-request # the default
codex -a never # never ask (pair this with a tight sandbox)
# Both layers off. Only inside something already isolated.
codex --dangerously-bypass-approvals-and-sandbox
The worktree gotcha, and the flag that fixes it
In workspace-write the writable root is the working directory. Inside a git worktree the real git metadata lives in the main repository’s .git directory, which is outside that root, so git operations that write metadata fail with a permissions error that looks nothing like a sandbox problem.
cd ~/code/myapp-worktrees/feature-auth
codex --add-dir ~/code/myapp
--add-dir takes a directory that should be writable alongside the primary workspace. Point it at the main checkout and commits start working inside worktree sessions. The same thing is available persistently as writable_roots under [sandbox_workspace_write].
config.toml
Anything you find yourself passing as a flag every time belongs in ~/.codex/config.toml. Project-scoped overrides go in a .codex/config.toml inside the repository.
model = "gpt-5.6-sol"
model_reasoning_effort = "high" # minimal | low | medium | high | xhigh
approval_policy = "on-request" # untrusted | on-request | never
sandbox_mode = "workspace-write" # read-only | workspace-write | danger-full-access
[sandbox_workspace_write]
network_access = false
writable_roots = ["/Users/you/code/myapp"]
# Per-project trust
[projects."/Users/you/code/myapp"]
trust_level = "trusted"
# MCP servers
[mcp_servers.github]
command = "npx"
args = ["-y", "@modelcontextprotocol/server-github"]
Any key can be overridden for a single run with -c. The value is parsed as TOML, so quote strings and use dotted paths for nested keys.
codex -c model_reasoning_effort="high"
codex -c model="gpt-5.6-terra" -c approval_policy="never"
codex -c shell_environment_policy.inherit=all
Reasoning effort is the biggest cost lever
Codex exposes reasoning effort as a first-class setting with five values, and the difference between the ends is large in both quality and price. minimal and low are fine for mechanical edits and dramatically faster. high and xhigh are a genuinely different tool for a hard bug. Most people leave it at the default and never discover either end.
Profiles: switching whole configurations
Once you use Codex for more than one kind of work, a single config stops fitting. Current builds layer a named file on top of your base user config: -p review loads $CODEX_HOME/review.config.toml over config.toml.
model_reasoning_effort = "xhigh"
approval_policy = "on-request"
sandbox_mode = "read-only"
model_reasoning_effort = "low"
approval_policy = "never"
sandbox_mode = "workspace-write"
codex --profile review "audit this package for race conditions"
codex --profile grind "convert the remaining callbacks to async/await"
The reasoning-effort difference between those two profiles is the largest lever Codex exposes on both quota and wall-clock time, and switching it per task rather than per account is what makes a subscription last a month.
Interactive, non-interactive, and resuming
cd ~/code/myapp
codex
# Start with a prompt already loaded
codex "add integration tests for the payments module"
# Attach an image (a screenshot of the bug, a design)
codex -i ~/Desktop/error.png "why does this render wrong?"
# Enable live web search for this session
codex --search "check whether the upstream API changed its pagination"
Session management
Sessions are recorded, named, and reachable later. fork is the one people miss: it branches from a previous session so you can try a second approach without losing the first.
codex resume # picker
codex resume --last # continue the most recent
codex resume <session-id> # by id or name
codex fork --last # branch off the most recent session
codex archive <id> # get it out of the picker without deleting it
Non-interactive, for scripts and CI
codex exec "run the test suite and fix any failures"
# Be explicit about both dials in CI
codex exec -s workspace-write -a never "update the changelog for this release"
# Machine-readable: JSONL events on stdout, final message to a file
codex exec --json -o /tmp/last.txt "summarise the risk in this diff"
# Force the shape of the final answer
codex exec --output-schema ./schema.json "classify each failing test"
| exec flag | What it does |
|---|---|
--json | Print events to stdout as JSONL |
-o, --output-last-message | Write the agent’s final message to a file |
--output-schema | Path to a JSON Schema describing the final response shape |
--skip-git-repo-check | Allow running outside a git repository |
--ephemeral | Run without persisting session files to disk |
--ignore-user-config | Ignore config.toml; auth still uses CODEX_HOME |
codex exec reads from stdin when no prompt argument is given, so it drops into a pipeline without a pseudo-terminal wrapper.
git diff origin/main | codex exec -s read-only "review this diff and list only real defects"
Codex in CI
Two rules make an automated Codex run safe: pin both dials explicitly rather than inheriting a default that may move, and never let it approve its own work.
name: Triage failing tests
on:
workflow_dispatch:
jobs:
triage:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Install Codex
run: npm install -g @openai/codex
- name: Diagnose
env:
OPENAI_API_KEY: ${{ secrets.OPENAI_API_KEY }}
run: |
codex exec \
--sandbox workspace-write \
--ask-for-approval never \
"Run the test suite. For each failure, explain the root cause in
docs/triage.md. Do not change application code."
- uses: actions/upload-artifact@v4
with: { name: triage, path: docs/triage.md }
The task above is deliberately read-and-report rather than fix-and-push. An agent that opens its own pull request against your main branch on a schedule is a supply-chain question, not a productivity one.
Reviewing a diff without a pipeline
There is also a first-class review subcommand, which is the fastest way to get a second opinion on work another agent just did.
codex review # interactive review of the current repo state
codex exec review # same thing, non-interactively
AGENTS.md: telling Codex about your repo
Codex reads an AGENTS.md file for standing instructions about the project, the same role CLAUDE.md plays for Claude Code. It is the highest-leverage file in the repository for agent quality, and most people never write one. Run /init in a session to have Codex draft the first version.
Files are merged from three levels, most specific winning:
| Location | Scope | Put here |
|---|---|---|
~/.codex/AGENTS.md | Every project | Your personal preferences: commit style, how blunt you want it |
<repo>/AGENTS.md | This repository | Build and test commands, architecture, conventions the team enforces |
<repo>/sub/AGENTS.md | That subtree | Rules that only apply to one package or service |
# Project
Go API server. Postgres. Deployed on Fly.
## Commands
- Test a package: `go test ./internal/billing/...` (NOT the whole suite; it takes 6 min)
- Lint: `golangci-lint run`
- Regenerate mocks after changing an interface: `make mocks`
## Conventions
- Errors wrap with %w and are checked with errors.Is. Never compare strings.
- Any new endpoint needs a table-driven test in the same package.
- internal/pb is generated. Never hand-edit it.
## Do not
- Do not add dependencies without asking.
- Do not touch migrations/ unless the task is explicitly a migration.
MCP servers and tools
Codex speaks the Model Context Protocol, so you can give it tools beyond the filesystem and shell: an issue tracker, a database, internal documentation. Servers are declared in config.toml and start with the session. Codex can also be an MCP server, via codex mcp-server, which is how other agents drive it.
[mcp_servers.github]
command = "npx"
args = ["-y", "@modelcontextprotocol/server-github"]
env = { GITHUB_TOKEN = "${GITHUB_TOKEN}" }
[mcp_servers.postgres]
command = "npx"
args = ["-y", "@modelcontextprotocol/server-postgres", "postgresql://localhost/dev"]
enabled = true
codex mcp list # what is configured
codex mcp # manage servers
Session history and usage
Codex writes a rollout file per session under ~/.codex/sessions/. Those files carry the full transcript plus token counts, which is what any local usage tool reads, and what you should read yourself when a run goes sideways.
ls -lt ~/.codex/sessions/ | head
du -sh ~/.codex/sessions/
# What kinds of events did the newest session produce?
jq -r 'select(.type=="response_item") | .payload.type' \
"$HOME/.codex/sessions/$(ls -t ~/.codex/sessions | head -1)" | sort | uniq -c
Inside a session, /status prints the current setup: which model, which sandbox, which approval policy, and where you are against your plan’s window.
When it goes wrong
| Symptom | Cause | Fix |
|---|---|---|
| Edits silently fail | Sandbox is read-only | Restart with -s workspace-write |
| Git operations fail inside a worktree | Real git metadata sits outside the writable root | --add-dir <main-repo>, or set writable_roots |
| Cannot reach the network | Network needs approval in workspace-write | Set network_access = true under [sandbox_workspace_write] |
| Sandbox refuses to start on Linux | bubblewrap missing | Install it, or run codex doctor to confirm the bundled fallback |
| Wrong account billed | auth.json from another login | Check CODEX_HOME; each account needs its own config root |
| Stops constantly to ask | Approval policy is untrusted | Use -a on-request, or never with a tight sandbox |
| Slow and expensive on trivial work | Reasoning effort left high | -c model_reasoning_effort="low", or a profile |
| A config key does nothing | Renamed or removed in this version | Re-run with --strict-config |
Command and flag reference
Selected subcommands, verified against codex-cli 0.144.1 in August 2026.
| Command | What it does |
|---|---|
codex | Interactive session in the current directory |
codex exec | Run non-interactively and exit |
codex review | Run a code review over the repository |
codex resume / fork | Continue or branch a previous session |
codex apply | Apply the agent’s latest diff to your working tree with git apply |
codex mcp / mcp-server | Manage MCP servers, or run Codex as one |
codex sandbox | Run an arbitrary command inside the Codex sandbox |
codex doctor | Diagnose install, config, auth, and runtime health |
codex update | Update the CLI in place |
codex app | Launch the Codex desktop app |
| Flag | Effect |
|---|---|
-s, --sandbox | read-only, workspace-write, danger-full-access |
-a, --ask-for-approval | untrusted, on-request, never |
-c key=value | Override any config key for this run (value parsed as TOML) |
-m, --model | Model for this run |
-p, --profile | Layer $CODEX_HOME/<name>.config.toml on the base config |
-C, --cd | Use a different directory as the working root |
--add-dir | Extra writable directory alongside the workspace |
-i, --image | Attach one or more images to the initial prompt |
--search | Enable the native web-search tool |
--strict-config | Error on unrecognised config keys |
--dangerously-bypass-approvals-and-sandbox | Disable both layers. Externally sandboxed environments only. |
Questions people ask
It is included with ChatGPT plans, and as of August 2026 OpenAI lists it against Free, Go, Plus, Pro, Business, Edu, and Enterprise. The allowance scales with the plan. You can also authenticate with an OpenAI API key and pay per token instead.
The sandbox controls what the agent is physically able to touch, enforced by the operating system. The approval policy controls when it pauses to ask you. They are independent, and the useful combinations pair a tight sandbox with fewer prompts.
~/.codex/config.toml for user settings, with project-scoped overrides in a .codex/config.toml inside the repository. Set CODEX_HOME to relocate the whole root, which is also how you run a second Codex account in isolation.
Both are gone from current builds. The approval values are untrusted, on-request, and never. For hands-off work use the default workspace-write sandbox with -a never, which is the combination --full-auto used to approximate.
Use codex exec, which runs non-interactively and exits. Pass --sandbox and --ask-for-approval explicitly rather than relying on defaults, use an API key rather than a subscription login, and add --json if a later step needs to parse what happened.
In workspace-write the writable root is the working directory, but a worktree keeps its real git metadata in the main repository outside that root. Pass --add-dir pointing at the main checkout, or set writable_roots under [sandbox_workspace_write].
Yes. model_reasoning_effort accepts minimal, low, medium, high, and xhigh, either in config.toml or per run with -c model_reasoning_effort="high". The difference in quality, latency, and quota consumption between the ends is substantial.
Every session writes a rollout file under ~/.codex/sessions/ containing the full transcript and token counts. Run /status inside a live session for the current model, sandbox, approval policy, and plan usage.
Sources
Every figure above was read from these pages on August 2026. Vendors reprice without notice; if you find a stale number, tell us.
- openai/codex on GitHub install commands, system requirements
- Codex CLI documentation commands and slash commands
- Codex sandboxing sandbox modes and platform enforcement
- Codex pricing which ChatGPT plans include Codex