OpenAI Codex CLI: the complete guide

Codex is OpenAI’s terminal coding agent, included with ChatGPT plans. Its defining design choice is the sandbox: unlike most agents, Codex decides what it may touch by operating-system policy rather than by asking you every time.

By the Continuum team. We build a workbench that runs Claude Code, Codex, and their peers, so the model rates quoted here are the ones our own cost analytics ship with.

The short version

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.

What you need to know
  • Codex is included with ChatGPT plans. You can also authenticate with an API key.
  • The sandbox is the core concept: read-only, workspace-write, or danger-full-access. The default is workspace-write with network off.
  • Approvals are a separate dial: untrusted, on-request, never. The old on-failure value and the --full-auto shorthand are gone.
  • Config lives at ~/.codex/config.toml; CODEX_HOME relocates the whole root, which is how you run two accounts.
  • codex exec runs non-interactively and exits, with --json for 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.

Installing, as of August 2026
# 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.

RequirementDetail
Operating systemmacOS 12+, Ubuntu 20.04+ / Debian 10+, or Windows 11 via WSL2
Git2.23+ recommended for the built-in PR helpers
RAM4 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.

Auth, updates, and a health check
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.

A second Codex account, isolated
CODEX_HOME="$HOME/.codex-work" codex login
CODEX_HOME="$HOME/.codex-work" codex

The sandbox model

agentdanger-full-accessanywhere your user can writeworkspace-writethe project directoryread-onlynothing is writtenThe sandbox sets what is possible. Approval policy sets when it stops to ask.
Two independent dials. The sandbox sets what the agent can reach at all. The approval policy sets how often it stops to ask you about it.

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.

ModeReadWriteNetworkUse for
read-onlyYesNoApproval neededResearch, review, planning
workspace-write (default)YesWorkspace onlyApproval neededNormal development
danger-full-accessYesAnywhereUnrestrictedContainers 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.

ValueBehaviour
untrustedRuns 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.
neverNever 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.

Let the sandbox see the main repo too
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.

~/.codex/config.toml
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.

~/.codex/review.config.toml
model_reasoning_effort = "xhigh"
approval_policy = "on-request"
sandbox_mode = "read-only"
~/.codex/grind.config.toml
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

Interactive
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
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 flagWhat it does
--jsonPrint events to stdout as JSONL
-o, --output-last-messageWrite the agent’s final message to a file
--output-schemaPath to a JSON Schema describing the final response shape
--skip-git-repo-checkAllow running outside a git repository
--ephemeralRun without persisting session files to disk
--ignore-user-configIgnore 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.

.github/workflows/codex-triage.yml
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:

LocationScopePut here
~/.codex/AGENTS.mdEvery projectYour personal preferences: commit style, how blunt you want it
<repo>/AGENTS.mdThis repositoryBuild and test commands, architecture, conventions the team enforces
<repo>/sub/AGENTS.mdThat subtreeRules that only apply to one package or service
An AGENTS.md that actually changes behaviour
# 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.

~/.codex/config.toml
[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

SymptomCauseFix
Edits silently failSandbox is read-onlyRestart with -s workspace-write
Git operations fail inside a worktreeReal git metadata sits outside the writable root--add-dir <main-repo>, or set writable_roots
Cannot reach the networkNetwork needs approval in workspace-writeSet network_access = true under [sandbox_workspace_write]
Sandbox refuses to start on Linuxbubblewrap missingInstall it, or run codex doctor to confirm the bundled fallback
Wrong account billedauth.json from another loginCheck CODEX_HOME; each account needs its own config root
Stops constantly to askApproval policy is untrustedUse -a on-request, or never with a tight sandbox
Slow and expensive on trivial workReasoning effort left high-c model_reasoning_effort="low", or a profile
A config key does nothingRenamed or removed in this versionRe-run with --strict-config

Command and flag reference

Selected subcommands, verified against codex-cli 0.144.1 in August 2026.

CommandWhat it does
codexInteractive session in the current directory
codex execRun non-interactively and exit
codex reviewRun a code review over the repository
codex resume / forkContinue or branch a previous session
codex applyApply the agent’s latest diff to your working tree with git apply
codex mcp / mcp-serverManage MCP servers, or run Codex as one
codex sandboxRun an arbitrary command inside the Codex sandbox
codex doctorDiagnose install, config, auth, and runtime health
codex updateUpdate the CLI in place
codex appLaunch the Codex desktop app
FlagEffect
-s, --sandboxread-only, workspace-write, danger-full-access
-a, --ask-for-approvaluntrusted, on-request, never
-c key=valueOverride any config key for this run (value parsed as TOML)
-m, --modelModel for this run
-p, --profileLayer $CODEX_HOME/<name>.config.toml on the base config
-C, --cdUse a different directory as the working root
--add-dirExtra writable directory alongside the workspace
-i, --imageAttach one or more images to the initial prompt
--searchEnable the native web-search tool
--strict-configError on unrecognised config keys
--dangerously-bypass-approvals-and-sandboxDisable 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.

  1. openai/codex on GitHub install commands, system requirements
  2. Codex CLI documentation commands and slash commands
  3. Codex sandboxing sandbox modes and platform enforcement
  4. Codex pricing which ChatGPT plans include Codex
Try it

Codex, without
the terminal tax.

Continuum drives Codex through its app-server interface: structured tool rows, live quota gauges, per-repo spend, worktree isolation, and the same sidebar as your Claude Code sessions.

free app · your subscriptions · local-first