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 | shInstall or update the native binary on macOS and Linux with the official script
npm install -g @openai/codexInstall the CLI globally through npm instead of the script
brew install --cask codexInstall the Homebrew cask on macOS
powershell -ExecutionPolicy ByPass -c "irm https://chatgpt.com/codex/install.ps1 | iex"Install on Windows from PowerShell
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.
codexOpen the interactive terminal UI in the current folder
codex exec "fix the failing test"Run one task non-interactively, for scripts and CI
codex resumePick up a saved session instead of starting from nothing
codex loginSign in with your ChatGPT account or an API key; codex logout clears it
codex -m <model>Choose the model for this run (--model)
codex -s workspace-writeSet the sandbox: read-only, workspace-write or danger-full-access (--sandbox)
codex -a on-requestSet when Codex asks first: on-request or never (--ask-for-approval)
codex -C ../apiStart with a different working directory (--cd)
codex --add-dir ../sharedGive the agent write access to an extra folder; repeat for more
codex -i screenshot.pngAttach an image to the first prompt (--image)
codex --searchTurn on live web search for the session
codex -p workLoad a named profile file from the Codex home folder (--profile)
codex -c model="gpt-6.1-sol"Override one config.toml key for this run only (--config key=value)
/initWrite a starter AGENTS.md for the repository
/statusShow the model, sandbox and approval settings of the session
/permissionsChange what Codex may do without asking, mid-session
/modelSwitch model and reasoning effort
/reviewAsk Codex to review your uncommitted changes for problems
/diffShow the Git diff of what has changed
/compactSummarise the conversation so far to free context tokens
/planSwitch into plan mode before any edits
/mcpList the MCP servers and tools loaded in this session
/newStart a fresh chat without leaving the CLI
/forkBranch the current chat so you can try another approach
/mentionAttach a file to the conversation
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.tomlUser-level config; .codex/config.toml in a repo applies only to trusted projects
model = "gpt-6.1-sol"Default model when you don't pass -m
approval_policy = "on-request"Ask before going outside the sandbox; never disables prompts
sandbox_mode = "workspace-write"Default sandbox: read-only, workspace-write or danger-full-access
web_search = "cached"Web search mode: disabled, cached, indexed or live
[sandbox_workspace_write]
writable_roots = ["../shared"]Extra folders the workspace-write sandbox may write to
project_doc_max_bytes = 32768Raise or lower the AGENTS.md size cap (32 KiB by default)
project_doc_fallback_filenames = ["CLAUDE.md"]Other instruction file names to read when a folder has no AGENTS.md
Codex reads at most one file per directory and skips empty ones. The combined text is built once per run.
~/.codex/AGENTS.mdPersonal instructions applied to every repository
AGENTS.override.mdTakes the place of AGENTS.md in the same folder when both exist
<repo>/AGENTS.md ... <cwd>/AGENTS.mdFiles from the repo root down to your folder are joined, so the closest one wins on conflicts
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-mcpRegister a stdio server; everything after -- is the launch command
codex mcp add api --env TOKEN=abc -- node server.jsPass environment variables to a stdio server
codex mcp add example --url https://mcp.example.com --oauth-client-id my-clientRegister a remote streamable HTTP server with OAuth
codex mcp listPrint the servers Codex knows about
codex mcp login <server-name>Run the OAuth sign-in for a remote server
[mcp_servers.context7]
command = "npx"
args = ["-y", "@upstash/context7-mcp"]The same stdio server written by hand in config.toml
startup_timeout_sec = 20Give a slow server longer than the 10 second default to start; tool_timeout_sec defaults to 60
enabled_tools = ["search"]Expose only the listed tools from a server; disabled_tools does the reverse
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
--yoloon your laptop to stop the approval promptsUse
-s workspace-write -a on-request, orneverapprovals inside the sandbox, and save full bypass for disposable containers.Expecting
.codex/config.tomlin a fresh clone to apply straight awayProject 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.tomlCreate a separate
work.config.tomlin 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_bytescap or split guidance into folder-level AGENTS.md files.Following old guides that use
codex mcp-serveror theuntrustedapproval policyBoth are gone; use
codex mcp addto register servers and pickon-requestorneverfor approvals.
Related cheat sheets
Sources
- https://learn.chatgpt.com/docs/codex/cli
- https://learn.chatgpt.com/docs/developer-commands?surface=cli
- https://learn.chatgpt.com/docs/config-file/config-reference
- https://learn.chatgpt.com/docs/agent-configuration/agents-md
- https://learn.chatgpt.com/docs/extend/mcp?surface=cli
- https://learn.chatgpt.com/docs/sandboxing
- https://learn.chatgpt.com/docs/changelog
- https://github.com/openai/codex/releases
How we research: where our facts come from, how often we re-check them, and why no one can pay for a review or a verdict.