Skip to content

Menu

Codex CLI Cheat Sheet: Commands, Sandbox Modes, config.toml and MCP

Checked against OpenAI Codex CLI Codex CLI 0.172.0 (GitHub release rust-v0.172.0, 24 Nov 2026) on 28 November 2026. Each section links to the official docs it was checked against.

This sheet is for people who run OpenAI's Codex agent in a terminal and want the flags, files and slash commands in one place. It follows the Codex docs (the old developers.openai.com/codex links now redirect to learn.chatgpt.com) and the 0.172.0 release from 24 Nov 2026. Codex wasn't installed on the machine used to write this, so every row was checked against the docs only.

When to use what

Pick the sandbox first and the approval policy second. read-only is right when you only want Codex to explain or review code. workspace-write with on-request approvals is the setting the docs describe as the low-friction default: Codex edits inside your project and asks before it reaches outside. Keep danger-full-access for throwaway containers or VMs, because it removes the sandbox altogether.

Use the interactive TUI (plain codex) for work you want to steer, and codex exec for scripted runs such as CI jobs, where nobody is there to answer a prompt. Put long-lived defaults in ~/.codex/config.toml and per-repo ones in .codex/config.toml; the project file is only loaded once you've marked the folder as trusted.

For team instructions, write an AGENTS.md at the repo root. Codex, Zed, Cline and Devin all read that name, so one file serves several agents; the agent rules generator gives you a starting draft and our AGENTS.md post compares what each agent loads. Our Codex page covers plans and pricing.

Set CODEX_INSTALLER_USE_RELEASES_OPENAI_COM=false before the script if you need it to download from GitHub Releases.

curl -fsSL https://chatgpt.com/codex/install.sh | sh

Install or update the native binary on macOS and Linux with the official script

From the docs, not run by us
npm install -g @openai/codex

Install the CLI globally through npm instead of the script

From the docs, not run by us
brew install --cask codex

Install the Homebrew cask on macOS

From the docs, not run by us
powershell -ExecutionPolicy ByPass -c "irm https://chatgpt.com/codex/install.ps1 | iex"

Install on Windows from PowerShell

From the docs, not run by us

The docs also list --dangerously-bypass-approvals-and-sandbox (alias --yolo). It turns off both safety layers, so only use it inside a disposable environment.

codex

Open the interactive terminal UI in the current folder

From the docs, not run by us
codex exec "fix the failing test"

Run one task non-interactively, for scripts and CI

From the docs, not run by us
codex resume

Pick up a saved session instead of starting from nothing

From the docs, not run by us
codex login

Sign in with your ChatGPT account or an API key; codex logout clears it

From the docs, not run by us
codex -m <model>

Choose the model for this run (--model)

From the docs, not run by us
codex -s workspace-write

Set the sandbox: read-only, workspace-write or danger-full-access (--sandbox)

From the docs, not run by us
codex -a on-request

Set when Codex asks first: on-request or never (--ask-for-approval)

From the docs, not run by us
codex -C ../api

Start with a different working directory (--cd)

From the docs, not run by us
codex --add-dir ../shared

Give the agent write access to an extra folder; repeat for more

From the docs, not run by us
codex -i screenshot.png

Attach an image to the first prompt (--image)

From the docs, not run by us
codex --search

Turn on live web search for the session

From the docs, not run by us
codex -p work

Load a named profile file from the Codex home folder (--profile)

From the docs, not run by us
codex -c model="gpt-6.1-sol"

Override one config.toml key for this run only (--config key=value)

From the docs, not run by us
/init

Write a starter AGENTS.md for the repository

Try it: AGENTS.md / CLAUDE.md GeneratorFrom the docs, not run by us
/status

Show the model, sandbox and approval settings of the session

From the docs, not run by us
/permissions

Change what Codex may do without asking, mid-session

From the docs, not run by us
/model

Switch model and reasoning effort

From the docs, not run by us
/review

Ask Codex to review your uncommitted changes for problems

From the docs, not run by us
/diff

Show the Git diff of what has changed

From the docs, not run by us
/compact

Summarise the conversation so far to free context tokens

Try it: Token CounterFrom the docs, not run by us
/plan

Switch into plan mode before any edits

From the docs, not run by us
/mcp

List the MCP servers and tools loaded in this session

From the docs, not run by us
/new

Start a fresh chat without leaving the CLI

From the docs, not run by us
/fork

Branch the current chat so you can try another approach

From the docs, not run by us
/mention

Attach a file to the conversation

From the docs, not run by us

Profiles are separate files named <profile>.config.toml in $CODEX_HOME, chosen with --profile; config.toml itself has no profiles table. Don't set default_permissions and sandbox_mode together.

~/.codex/config.toml

User-level config; .codex/config.toml in a repo applies only to trusted projects

Try it: toml-formatterFrom the docs, not run by us
model = "gpt-6.1-sol"

Default model when you don't pass -m

From the docs, not run by us
approval_policy = "on-request"

Ask before going outside the sandbox; never disables prompts

From the docs, not run by us
sandbox_mode = "workspace-write"

Default sandbox: read-only, workspace-write or danger-full-access

From the docs, not run by us
web_search = "cached"

Web search mode: disabled, cached, indexed or live

From the docs, not run by us
[sandbox_workspace_write] writable_roots = ["../shared"]

Extra folders the workspace-write sandbox may write to

From the docs, not run by us
project_doc_max_bytes = 32768

Raise or lower the AGENTS.md size cap (32 KiB by default)

From the docs, not run by us
project_doc_fallback_filenames = ["CLAUDE.md"]

Other instruction file names to read when a folder has no AGENTS.md

From the docs, not run by us

Codex reads at most one file per directory and skips empty ones. The combined text is built once per run.

~/.codex/AGENTS.md

Personal instructions applied to every repository

Try it: AGENTS.md / CLAUDE.md GeneratorFrom the docs, not run by us
AGENTS.override.md

Takes the place of AGENTS.md in the same folder when both exist

From the docs, not run by us
<repo>/AGENTS.md ... <cwd>/AGENTS.md

Files from the repo root down to your folder are joined, so the closest one wins on conflicts

From the docs, not run by us

Remote servers use url instead of command, with bearer_token_env_var or http_headers for auth.

codex mcp add context7 -- npx -y @upstash/context7-mcp

Register a stdio server; everything after -- is the launch command

Try it: MCP Config GeneratorFrom the docs, not run by us
codex mcp add api --env TOKEN=abc -- node server.js

Pass environment variables to a stdio server

From the docs, not run by us
codex mcp add example --url https://mcp.example.com --oauth-client-id my-client

Register a remote streamable HTTP server with OAuth

From the docs, not run by us
codex mcp list

Print the servers Codex knows about

From the docs, not run by us
codex mcp login <server-name>

Run the OAuth sign-in for a remote server

From the docs, not run by us
[mcp_servers.context7] command = "npx" args = ["-y", "@upstash/context7-mcp"]

The same stdio server written by hand in config.toml

Try it: TOML ↔ JSON ConverterFrom the docs, not run by us
startup_timeout_sec = 20

Give a slow server longer than the 10 second default to start; tool_timeout_sec defaults to 60

From the docs, not run by us
enabled_tools = ["search"]

Expose only the listed tools from a server; disabled_tools does the reverse

From the docs, not run by us

Worked example: Let Codex fix a test in a sandbox, then review the change

Start in your repository with the sandbox limited to the project and approvals on:

cd ~/src/billing
codex -s workspace-write -a on-request

Inside the TUI, run /status first. The panel should name workspace-write and on-request; if it shows danger-full-access, a profile or config.toml is overriding you, so quit and check ~/.codex/config.toml.

Then ask for the work and review it before you commit:

The test in tests/invoice.test.ts fails on rounding. Find the cause and fix it.
/diff
/review

Codex can edit files inside the repo without asking, but a command that needs the network or a path outside the project triggers an approval prompt. /diff shows exactly which files changed, and /review gives you a second pass that often catches an edge case the first attempt missed. Nothing is committed for you, so you still decide what goes into Git.

Common mistakes

  • Running --yolo on your laptop to stop the approval prompts

    Use -s workspace-write -a on-request, or never approvals inside the sandbox, and save full bypass for disposable containers.

  • Expecting .codex/config.toml in a fresh clone to apply straight away

    Project config loads only in trusted folders; trust the project when Codex asks, or put the setting in ~/.codex/config.toml.

  • Adding a [profiles.work] table to config.toml

    Create a separate work.config.toml in the Codex home folder and launch with --profile work.

  • Writing a huge AGENTS.md and wondering why the end is ignored

    Keep it under the 32 KiB project_doc_max_bytes cap or split guidance into folder-level AGENTS.md files.

  • Following old guides that use codex mcp-server or the untrusted approval policy

    Both are gone; use codex mcp add to register servers and pick on-request or never for approvals.