OpenAI Codex Commands Cheat Sheet (2026)

Codex commands cheat sheet for developers: CLI commands, slash commands, flags, config keys, environment variables, sandbox settings, MCP, and real workflows.

Codex CLI is OpenAI’s local coding agent for the terminal. It can inspect a repository, edit files, run commands, review changes, and continue previous work through saved sessions.

This cheat sheet is for developers who use Codex from a shell, a terminal UI, or automation scripts. It separates shell commands, interactive slash commands, CLI flags, configuration keys, environment variables, and experimental features so each command is used in the right place.

Use the tables as a working reference. Start with the stable commands, then add flags, sandbox settings, MCP servers, and non-interactive workflows as your usage gets more advanced.

Last audited: May 06, 2026

Quick Classification

TypeWhere it is usedExampleNotes
CLI commandYour shellcodex exec "Fix failing tests"Runs from a terminal prompt.
CLI flagAfter codex or a subcommandcodex --model gpt-5.5Changes one invocation.
Slash commandInside the interactive Codex TUI/statusOnly works after codex opens the TUI.
Config key~/.codex/config.tomlsandbox_mode = "workspace-write"Persists defaults.
Environment variableShell environmentCODEX_CA_CERTIFICATE=/path/ca.pemUsed for auth, providers, TLS, or logging.
Experimental commandShell or TUIcodex mcp-serverOfficially documented but may change.
Deprecated command or flagShell or TUI--full-autoKeep out of new workflows.

Installation and Authentication

CommandWhat it doesNotes
npm install -g @openai/codexInstalls Codex CLI with npm.Official install path. Requires a Node/npm environment.
brew install --cask codexInstalls Codex CLI with Homebrew.Official macOS install path.
codexStarts Codex in interactive terminal UI mode.Stable. Run from the project root for repository-aware work.
codex loginStarts the default ChatGPT sign-in flow.Stable. Opens a browser when possible.
codex login --device-authUses device-code authentication.Beta-style fallback for headless or remote environments.
printenv OPENAI_API_KEY | codex login --with-api-keySigns in with an API key from stdin.Stable. Recommended by the docs for programmatic CLI workflows.
codex login statusPrints the active authentication mode.Stable. Exits with status 0 when logged in. Useful in scripts.
codex logoutRemoves stored Codex credentials.Stable. Clears both API-key and ChatGPT auth.
codex updateChecks for and applies an update when the installed release supports self-update.Stable. Debug builds may not support self-update.

Session and Conversation Commands

CommandWhat it doesNotes
codexOpens a new interactive session.Stable. Accepts global flags and an optional prompt.
codex "Explain this codebase"Opens the TUI with an initial prompt.Stable. Useful for starting work with context.
codex resumeOpens a picker for previous sessions.Stable. Scoped to the current working directory by default.
codex resume --lastResumes the most recent session for the current directory.Stable. Add --all to ignore the directory filter.
codex resume --allShows sessions beyond the current directory.Stable. Useful when work moved directories.
codex resume <SESSION_ID>Resumes a specific saved session.Stable. Session IDs appear in /status and local session files.
codex resume --include-non-interactiveIncludes non-interactive sessions in the resume picker and --last selection.Stable in the current local CLI help.
codex forkForks a previous interactive session into a new thread.Stable. Good for trying a different approach without changing the original transcript.
codex fork --lastForks the most recent saved session.Stable. Add --all to include sessions from other directories.
codex exec resume --last "Continue the fix"Resumes a non-interactive session and sends a follow-up prompt.Stable. Use for automation or CI-style continuations.
codex exec resume <SESSION_ID> "Implement the plan"Resumes a specific non-interactive run.Stable. Accepts optional follow-up text.

Interactive Slash Commands for Sessions

CommandWhat it doesNotes
/newStarts a new conversation inside the current CLI session.Official slash command. Does not clear the visible terminal first.
/clearClears the terminal and starts a fresh chat.Official slash command. Different from Ctrl+L, which only clears the screen.
/resumeOpens a saved-session picker.Official slash command. Use inside the TUI.
/forkForks the current conversation into a new thread.Official slash command. Keeps the original transcript intact.
/sideStarts an ephemeral side conversation.Official slash command. Useful for focused checks that should not disrupt the main thread.
/compactSummarizes earlier conversation to free context.Official slash command. Use after long sessions.
/copyCopies the latest completed Codex output.Official slash command. Ctrl+O is the shortcut.
/exitExits the CLI.Official slash command. Alias of /quit.
/quitExits the CLI.Official slash command. Alias of /exit.
/logoutSigns out of Codex from inside the TUI.Official slash command.
/feedbackOpens feedback flow from inside the TUI.Official slash command.

Project and Workspace Commands

CommandWhat it doesNotes
codex --cd <path>Starts Codex in a specific working directory.Global stable flag. Also available as -C.
codex --add-dir <path>Grants access to an additional directory.Global stable flag. Repeat for more paths. Prefer this over full sandbox bypass.
codex --image screenshot.png "Fix this UI"Attaches an image to the initial prompt.Global stable flag. Also available as -i.
codex appOpens Codex Desktop from the terminal.Stable on macOS and Windows.
codex app <PATH>Opens a workspace path in Codex Desktop.Stable. macOS opens the path; Windows prints the path to open.
codex completion zshPrints shell completions.Stable. Supports bash, zsh, fish, powershell, and elvish.
codex --no-alt-screenRuns the TUI without alternate-screen mode.Stable flag. Useful when terminal capture or scrollback matters.
codex app --download-urlPrints the Codex Desktop download URL.Listed in current official command reference.

Interactive Workspace Slash Commands

CommandWhat it doesNotes
/mention src/file.tsAttaches a file or folder to the conversation.Official slash command. Helps Codex focus on specific paths.
/initGenerates an AGENTS.md scaffold.Official slash command. Review and edit before committing.
/diffShows the Git diff, including untracked files.Official slash command. Use before committing or asking for review.
/statusDisplays active model, approval policy, writable roots, token usage, and session details.Official slash command. Good first diagnostic command.
/debug-configPrints config layer and policy diagnostics.Official slash command. Use when settings do not behave as expected.
/statuslineConfigures TUI footer fields.Official slash command. Persists to tui.status_line.
/titleConfigures terminal title fields.Official slash command. Persists to tui.terminal_title.
/keymapRemaps TUI keyboard shortcuts.Official slash command. Persists to tui.keymap.
/agentCreates, switches, lists, or manages delegated agents when the feature is available.Official slash command. Feature-dependent.
/psLists background terminals or running tasks when background execution is available.Official slash command. Feature-dependent.
/stopStops running tasks when background execution is available.Official slash command. Feature-dependent.

Code Editing and Review Commands

CommandWhat it doesNotes
codex "Review this repo for bugs"Starts an interactive review-oriented session.Stable. This is a prompt, not a special subcommand.
codex exec "Run the test suite and fix failures"Runs Codex non-interactively until it finishes.Stable. Good for scripted repair tasks.
codex reviewRuns a code review non-interactively.Stable in current local CLI help. Prefer it for review-only automation.
codex review --uncommittedReviews staged, unstaged, and untracked changes.Stable in current local CLI help.
codex review --base mainReviews changes against a base branch.Stable in current local CLI help.
codex review --commit <SHA>Reviews the changes introduced by one commit.Stable in current local CLI help.
codex exec --output-last-message result.md "Summarize the changes"Writes the final assistant message to a file.Stable. Useful for automation output.
codex exec --output-schema schema.json "Return a JSON report"Validates the final output against a JSON Schema.Stable. Use when downstream tools need structured output.
codex apply <TASK_ID>Applies the latest diff from a Codex Cloud task.Stable. Requires authentication and access to the task. Alias: codex a.
/reviewReviews the current working tree.Official slash command. Focuses on behavior changes, bugs, and missing tests.
/diffShows current file changes.Official slash command. Use after edits and before commits.
codex exec reviewRuns a code review through the codex exec command tree.Stable in current local CLI help. Similar review flags are available under codex review.
codex review --title "Title"Sets an optional title in the review summary.Stable in current local CLI help.

Model, Reasoning, and Mode Controls

CommandWhat it doesNotes
codex --model <model>Overrides the model for an interactive session.Stable flag. Also available as -m.
codex exec --model <model> "Task"Overrides the model for a non-interactive run.Stable flag.
codex --profile <name>Loads a named config profile.Stable flag. Also available as -p.
codex exec --profile <name> "Task"Uses a profile for an automation run.Stable flag.
codex --ossUses the local open source provider.Stable flag. Requires a running Ollama instance and OSS provider setup.
codex features listLists feature flags and their effective state.Stable command.
codex features enable <feature>Persistently enables a feature flag.Stable command. Writes to config.toml.
codex features disable <feature>Persistently disables a feature flag.Stable command. Writes to config.toml.
/modelChooses the active model and reasoning effort when available.Official slash command. TUI-only.
/fast onEnables Fast mode for supported models.Official slash command. Availability depends on sign-in method and model support.
/fast offDisables Fast mode.Official slash command.
/fast statusShows current Fast mode state.Official slash command.
/planSwitches to plan mode and optionally sends a planning prompt.Official slash command. Unavailable while a task is already running.
/personalityChanges communication style.Official slash command. Supports friendly, pragmatic, and none when the active model supports it.
/experimentalToggles experimental features.Official slash command. Restart may be required.

Useful Model Config Keys

CommandWhat it doesNotes
model = "gpt-5.5"Sets the default model.Config key, not a command. Model availability changes by account and release.
model_reasoning_effort = "medium"Sets default reasoning effort.Config key. Supported values include minimal, low, medium, high, and xhigh; model support varies.
model_reasoning_summary = "auto"Controls reasoning summary detail.Config key. Supports auto, concise, detailed, and none.
model_verbosity = "medium"Sets GPT-5 Responses API verbosity.Config key. Supports low, medium, and high.
model_provider = "openai"Selects the model provider.Config key. Built-in provider IDs include openai, ollama, and lmstudio.
oss_provider = "ollama"Sets the default local provider for --oss.Config key. Supports lmstudio and ollama.
review_model = "<model>"Sets the model used by /review.Config key. Defaults to the active session model when unset.
profiles.<name>.plan_mode_reasoning_effort = "high"Sets reasoning for plan mode in a profile.Config key. Useful for a planning-heavy profile.

Permissions, Sandbox, and Safety

CommandWhat it doesNotes
codex --sandbox read-onlyRuns with read-only sandbox policy.Stable flag. Good for audit or explanation tasks.
codex --sandbox workspace-writeAllows writes inside the workspace.Stable flag. Common for local development.
codex --sandbox danger-full-accessDisables Codex sandbox restrictions.Stable flag but risky. Use only inside an isolated environment.
codex --ask-for-approval untrustedControls when Codex asks before running commands.Stable flag.
codex --ask-for-approval on-requestLets Codex ask when it needs higher-permission action.Stable flag. Recommended for interactive local work.
codex --ask-for-approval neverPrevents approval prompts.Stable flag. Useful for non-interactive runs only when paired with a safe sandbox.
codex --dangerously-bypass-approvals-and-sandboxRuns without approvals or sandboxing.Stable flag but dangerous. Same risk profile as --yolo.
codex --yoloAlias for bypassing approvals and sandboxing.Stable alias, but unsafe outside a hardened container or VM.
codex sandbox macos -- <COMMAND>Runs a command under the macOS sandbox helper.Experimental. Uses macOS Seatbelt.
codex sandbox linux -- <COMMAND>Runs a command under the Linux sandbox helper.Experimental. Uses Landlock and seccomp.
codex sandbox windows -- <COMMAND>Runs a command under the Windows sandbox helper.Experimental.
codex execpolicy check --rules rules.json -- <COMMAND>Tests execpolicy rules against a command.Experimental preview. Emits JSON.
/permissionsChanges approval behavior during an interactive session.Official slash command. TUI-only.
/sandbox-add-read-dir C:\absolute\pathGrants sandbox read access to another directory.Official slash command, Windows only.

Useful Safety Config Keys

CommandWhat it doesNotes
sandbox_mode = "workspace-write"Persists the sandbox policy.Config key. Values: read-only, workspace-write, danger-full-access.
sandbox_workspace_write.writable_roots = ["/path"]Adds writable roots in workspace-write mode.Config key. Prefer narrow roots over full access.
sandbox_workspace_write.network_access = trueAllows outbound network in workspace-write mode.Config key. Keep disabled unless the task needs network access.
approval_policy = "on-request"Persists approval behavior.Config key. on-failure is deprecated; use on-request or never.
approval_policy.granular.sandbox_approval = trueAllows sandbox escalation prompts.Config key. Part of granular approvals.
history.persistence = "none"Stops transcript persistence.Config key. Useful for sensitive one-off work.
hide_agent_reasoning = trueHides reasoning events in TUI and codex exec output.Config key. Does not change model behavior.

Git and PR Workflows

CommandWhat it doesNotes
/diffShows all working tree changes Codex can see.Official slash command. Includes untracked files.
/reviewReviews current working tree changes.Official slash command. Use before creating a PR.
codex reviewRuns a non-interactive code review from the shell.Stable in current local CLI help.
codex apply <TASK_ID>Applies a Codex Cloud task diff locally.Stable. Uses git apply and exits non-zero on conflicts.
codex cloudOpens an interactive cloud-task picker.Experimental. Requires Codex Cloud access.
codex cloud list --jsonLists recent cloud tasks as JSON.Experimental. Useful for scripts.
codex cloud list --env <ENV_ID> --limit 10 --jsonLists cloud tasks for one environment.Experimental. Supports pagination with --cursor.
codex cloud exec --env <ENV_ID> "Task"Submits a cloud task directly.Experimental. Requires a target Codex Cloud environment.
codex cloud exec --env <ENV_ID> --branch <BRANCH> --attempts 2 "Task"Submits a cloud task on a branch with multiple attempts.Experimental. --attempts is best-of-N style.
codex cloud status <TASK_ID>Shows the status of a Codex Cloud task.Experimental.
codex cloud diff <TASK_ID>Shows the unified diff for a cloud task.Experimental. Add --attempt <N> when needed.
codex cloud apply <TASK_ID>Applies a cloud task diff locally.Experimental. Add --attempt <N> when needed.

Codex does not replace git. Keep normal Git commands in the workflow:

git status
git diff
codex
git add .
git commit -m "Fix parser edge case"

Use Codex to inspect, edit, test, and review; use Git to stage, commit, branch, push, and open pull requests.

MCP, Integrations, and Tools

CommandWhat it doesNotes
codex mcp listLists configured MCP servers.Experimental. Add --json for machine-readable output.
codex mcp get <name>Shows one MCP server configuration.Experimental. Add --json for raw config.
codex mcp add <name> -- <command...>Adds a stdio MCP server launcher.Experimental. The command after -- starts the server.
codex mcp add <name> --url https://...Adds a streamable HTTP MCP server.Experimental. Mutually exclusive with a stdio command.
codex mcp add <name> --env KEY=VALUE -- <command...>Passes environment variables to a stdio MCP server.Experimental. Repeat --env as needed.
codex mcp add <name> --url https://... --bearer-token-env-var TOKEN_ENVUses an environment variable as an HTTP bearer token.Experimental. Keep token values out of config.
codex mcp login <name>Starts OAuth login for a streamable HTTP MCP server.Experimental. Only works when the server supports OAuth.
codex mcp login <name> --scopes scope1,scope2Requests explicit OAuth scopes for an MCP server.Experimental. Current local CLI help lists comma-separated scopes.
codex mcp logout <name>Removes stored OAuth credentials for an MCP server.Experimental.
codex mcp remove <name>Deletes a stored MCP server definition.Experimental.
codex mcp-serverRuns Codex itself as an MCP server over stdio.Experimental. Used when another MCP client consumes Codex.
/mcpLists MCP tools available in the current TUI session.Official slash command. Add verbose for server details.
/appsBrowses apps/connectors and inserts them into a prompt.Official slash command. App availability depends on installed connectors.
/pluginsBrowses installed and discoverable plugins.Official slash command. Plugin availability depends on local setup.
codex plugin marketplace add <source>Adds a plugin marketplace.Experimental. Accepts GitHub shorthand, Git URLs, SSH Git URLs, or local marketplace roots.
codex plugin marketplace add <source> --ref <ref>Adds a marketplace at a specific Git ref.Experimental. Official docs list --ref for Git-backed sources.
codex plugin marketplace add <source> --sparse <path>Adds a marketplace from a sparse Git subdirectory.Experimental. Useful for monorepo marketplace roots.
codex plugin marketplace remove <marketplace-name>Removes a configured plugin marketplace.Experimental.
codex plugin marketplace upgrade [marketplace-name]Refreshes one or all Git-backed plugin marketplaces.Experimental.

MCP Config Keys

CommandWhat it doesNotes
mcp_servers.<id>.command = "node"Defines a stdio MCP launcher command.Config key. Use codex mcp add when possible.
mcp_servers.<id>.args = ["server.js"]Defines stdio MCP launcher arguments.Config key.
mcp_servers.<id>.env = { KEY = "VALUE" }Sets environment variables for a stdio server.Config key. Avoid storing secrets directly.
mcp_servers.<id>.bearer_token_env_var = "TOKEN_ENV"Reads an HTTP bearer token from the environment.Config key. Better than hard-coding tokens.
mcp_servers.<id>.enabled = falseDisables a server without deleting it.Config key.
mcp_servers.<id>.enabled_tools = ["tool_name"]Allows only selected tools.Config key. Useful for least-privilege tool access.
mcp_servers.<id>.disabled_tools = ["tool_name"]Blocks selected tools.Config key. Applied after enabled_tools.

CLI Flags

CommandWhat it doesNotes
--add-dir <path>Grants access to another directory.Global flag. Repeatable.
--ask-for-approval, -a <policy>Sets approval behavior.Values: untrusted, on-request, never. on-failure is deprecated.
--cd, -C <path>Sets working directory before the task starts.Global flag.
--config, -c key=valueOverrides config for one invocation.Values parse as TOML when possible; otherwise Codex treats the value as a literal string.
--dangerously-bypass-approvals-and-sandboxDisables approvals and sandboxing.Dangerous. Use only inside an external sandbox.
--yoloAlias for bypassing approvals and sandboxing.Dangerous alias.
--disable <feature>Disables a feature flag for this run.Repeatable. Equivalent to -c features.<name>=false.
--enable <feature>Enables a feature flag for this run.Repeatable. Equivalent to -c features.<name>=true.
--image, -i <path[,path...]>Attaches images to the first prompt.Repeatable.
--help, -hPrints help.Global flag. Use subcommand help for narrower output.
--version, -VPrints installed Codex CLI version.Global flag. Useful when checking docs against local behavior.
--model, -m <model>Overrides the configured model.Global flag.
--no-alt-screenDisables alternate-screen TUI mode.Global flag.
--ossUses a local open source provider.Requires local provider setup.
--local-provider <provider>Selects a local OSS provider.Current local help lists lmstudio and ollama. Usually paired with --oss.
--profile, -p <name>Loads a config profile.Global flag.
--remote <ws://host:port>Connects TUI to a remote app server.Supported for codex, codex resume, and codex fork.
--remote-auth-token-env <ENV_VAR>Sends a bearer token for remote TUI auth.Requires --remote. Token rules differ for ws:// and wss://.
--sandbox, -s <mode>Sets sandbox policy.Values: read-only, workspace-write, danger-full-access.
--searchEnables live web search.Sets web_search = "live" instead of default cached mode.

Non-Interactive Mode

CommandWhat it doesNotes
codex exec "Task"Runs Codex without opening the TUI.Stable. Alias: codex e.
codex exec -Reads the prompt from stdin.Stable. Good for generated prompts.
codex exec review --base mainRuns a non-interactive review through codex exec.Stable in current local CLI help. Supports review flags such as --base, --commit, and --uncommitted.
codex exec --json "Task"Prints newline-delimited JSON events.Stable. --experimental-json remains an alias.
codex exec --ephemeral "Task"Avoids persisting session rollout files.Stable. Useful for short-lived automation.
codex exec --skip-git-repo-check "Task"Allows running outside a Git repository.Stable. Use for one-off directories.
codex exec --ignore-user-config "Task"Ignores $CODEX_HOME/config.toml.Stable. Authentication still uses CODEX_HOME.
codex exec --ignore-rules "Task"Skips user and project execpolicy .rules files.Stable. Use only when policy bypass is intentional.
codex exec --color never "Task"Controls ANSI color output.Stable. Values: always, never, auto.
codex exec --output-last-message out.md "Task"Writes the final response to a file.Stable. Useful in CI.
codex exec --output-schema schema.json "Task"Validates final response shape.Stable. Schema file must exist.

Environment Variables

CommandWhat it doesNotes
OPENAI_API_KEYHolds an OpenAI API key for API-key authentication flows.Environment variable. Pipe it to codex login --with-api-key; avoid committing it.
CODEX_HOMEChanges where Codex stores config, auth, logs, and sessions.Environment variable. Defaults to ~/.codex.
CODEX_CA_CERTIFICATEPoints Codex at a custom CA bundle.Environment variable. Falls back to SSL_CERT_FILE when unset.
SSL_CERT_FILEFallback custom CA bundle path.Environment variable used when CODEX_CA_CERTIFICATE is unset.
RUST_LOGControls Rust logging verbosity.Environment variable. Mentioned in the open-source repo docs; useful for debugging.
CODEX_REMOTE_AUTH_TOKENExample bearer-token variable for remote TUI auth.Environment variable name is arbitrary; pass it through --remote-auth-token-env.
mcp_servers.<id>.bearer_token_env_var targetSupplies a bearer token to an MCP HTTP server.Environment variable name is configured in config.toml.
Custom provider env_key targetSupplies a provider-specific API key.Environment variable name is chosen in model_providers.<id>.env_key.

Custom Commands and Automation

Codex supports automation mainly through codex exec, MCP, plugins, config profiles, hooks, and AGENTS.md. Do not treat prompts, aliases, or local shell scripts as official Codex commands unless the Codex docs list them.

CommandWhat it doesNotes
codex exec "Task"Runs a one-shot automation task.Stable. Best starting point for scripts and CI.
codex exec --json --output-last-message out.md "Task"Streams machine-readable progress and saves final prose.Stable. Practical CI pattern.
codex features enable <feature>Turns on a feature persistently.Stable command, but individual feature maturity varies.
codex plugin marketplace add <source>Adds plugin sources.Experimental. Official but not stable.
codex mcp add <name> -- <command...>Adds tool integrations through MCP.Experimental. Official but may change.
/initCreates an AGENTS.md instruction scaffold.Official slash command. Project-specific instructions are not commands.
Hooks in config.tomlRuns lifecycle hooks.Config feature, not a CLI command. Keep hook scripts small and auditable.

Community, Experimental, and Deprecated Items

CommandWhat it doesNotes
codex app-serverRuns the Codex app server for local development or debugging.Official experimental command. May change without notice.
codex cloudWorks with Codex Cloud tasks from the terminal.Official experimental command. Requires Codex Cloud access.
codex execpolicyTests execpolicy rules.Official experimental preview.
codex mcpManages MCP server entries.Official experimental command.
codex mcp-serverRuns Codex as an MCP server.Official experimental command.
codex sandboxRuns commands in Codex-provided sandboxes.Official experimental command.
codex plugin marketplaceManages plugin marketplace sources.Official experimental command.
/approvalsLegacy alias for approval controls.Still works according to docs, but no longer appears in the slash popup. Prefer /permissions.
/cleanAlias for /stop.Still available according to docs. Prefer /stop.
--full-autoCompatibility shortcut for sandboxed automatic execution.Official command reference marks it deprecated; current local help may describe it as a convenience alias. Prefer explicit --sandbox and approval flags in scripts.
--experimental-jsonAlias for --json in codex exec.Keep new scripts on --json.
codex --upgradeOlder help-center update command.Treat as outdated unless confirmed in the installed CLI. Current command reference documents codex update.
codex debug seatbeltLegacy alias for sandbox testing.Mentioned in repository docs as a legacy alias. Prefer codex sandbox macos.
codex debug landlockLegacy alias for sandbox testing.Mentioned in repository docs as a legacy alias. Prefer codex sandbox linux.

Real Workflows

Start a New Project

mkdir my-app
cd my-app
git init
codex --sandbox workspace-write --ask-for-approval on-request "Create a small starter app with tests"

Use this when Codex should create files but still ask before risky commands.

Explain an Existing Repository

cd existing-repo
codex --sandbox read-only "Explain the architecture and identify the main entry points"

Use read-only mode when you want analysis without edits.

Fix a Failing Test

cd repo
codex exec --sandbox workspace-write --ask-for-approval never "Run the relevant tests, fix the failure, and summarize the patch"

Use this for focused repair work in a trusted repository; keep the sandbox on.

Review a Pull Request Locally

git fetch origin
git checkout feature-branch
codex --sandbox read-only "Review the working tree for bugs, regressions, and missing tests"

Use Codex as a reviewer after checking out the branch.

Run a Non-Interactive Review

codex review --base main

Use this when you want a review report from the shell without opening the TUI.

Review Changes Inside the TUI

/diff
/review

Use this after Codex edits files and before staging a commit.

Refactor a Module

codex --sandbox workspace-write --ask-for-approval on-request "Refactor src/auth without changing public behavior. Run targeted tests."

Use this when edits are expected but command execution should remain visible.

Resume a Previous Task

codex resume --last

Use this when the prior interactive conversation already contains the plan and context.

Resume a Previous Non-Interactive Task

codex exec resume --last "Continue from the previous failure and finish the test fix"

Use this when an automation run stopped before the work was complete.

Fork a Session Before Trying a Riskier Approach

codex fork --last

Use this when one solution path should remain intact while another is explored.

Run Codex in Headless Mode

codex exec --json --output-last-message codex-result.md "Audit this package and report actionable issues"

Use this in CI or scripted environments that need structured progress and a final summary.

Run Outside a Git Repository

codex exec --skip-git-repo-check "Organize these loose scripts and explain the changes"

Use this only for one-off directories where Git history is not available.

Use a Specific Model for One Run

codex exec --model gpt-5.5 "Find the safest way to simplify this module"

Use a model override when a task needs a different cost, speed, or reasoning profile than your default.

Use a Profile for High-Control Work

codex --profile cautious --sandbox read-only "Audit the payment code for risky changes"

Use profiles to keep repeatable defaults for different work styles.

Keep Context Lean During Long Work

/status
/compact
/status

Use /compact after long exchanges so the session keeps key details without carrying every turn.

Add an MCP Server

codex mcp add docs -- node ./mcp-docs-server.js
codex mcp list

Use this when Codex needs a local tool or documentation server through MCP.

Add an HTTP MCP Server with a Token

export DOCS_MCP_TOKEN="..."
codex mcp add docs-http --url https://example.com/mcp --bearer-token-env-var DOCS_MCP_TOKEN

Use an environment variable for secrets instead of hard-coding tokens in config.

Check Sandbox Behavior

codex sandbox linux -- npm test

Use this when you need to reproduce how a command behaves under Codex’s sandbox on Linux.

Apply a Codex Cloud Patch

codex cloud list --json
codex apply <TASK_ID>
git diff

Use this when a cloud task produced a patch that should be tested locally.

Avoid Full Access When One Extra Directory Is Needed

codex --sandbox workspace-write --add-dir ../shared "Update this project and the shared package together"

Use --add-dir instead of disabling the sandbox.

Run With Temporary Output Only

codex exec --ephemeral "Inspect this generated output and summarize issues"

Use ephemeral mode when you do not want rollout files saved for a short task.

FAQs

What is Codex CLI?

Codex CLI is OpenAI’s terminal-based coding agent. It runs locally, reads and edits files in your workspace, runs commands according to your sandbox and approval settings, and can continue work across saved sessions.

How do Codex commands differ from prompts?

Commands change Codex behavior or launch a Codex mode. Prompts tell the agent what work to do. For example, codex exec is a command; "Fix the failing parser test" is a prompt.

Does Codex support slash commands?

Yes. Current Codex CLI docs list many slash commands, including /status, /model, /permissions, /compact, /diff, /review, /resume, and /new. They work inside the interactive TUI, not directly from the shell.

How do I run Codex non-interactively?

Use codex exec "Task" or its alias codex e "Task". Add --json for newline-delimited JSON events, --output-last-message to save the final response, and --sandbox workspace-write when Codex needs to edit files.

How do I control permissions or sandboxing?

Use --sandbox read-only, --sandbox workspace-write, or --sandbox danger-full-access for one run. Use --ask-for-approval on-request or --ask-for-approval never to control approval prompts. Persist defaults with sandbox_mode and approval_policy in ~/.codex/config.toml.

How do I resume a Codex session?

Use codex resume for an interactive picker, codex resume --last for the most recent session, or codex resume <SESSION_ID> for a specific session. For non-interactive runs, use codex exec resume --last "Follow-up task".

Can Codex work with GitHub or PRs?

Codex can review local working tree changes with /review, show diffs with /diff, and apply Codex Cloud task patches with codex apply <TASK_ID>. Normal Git and GitHub operations such as branching, staging, committing, pushing, and opening PRs still belong to Git, GitHub CLI, or GitHub integrations.

What is the difference between Codex and Claude Code?

Codex CLI is OpenAI’s coding agent and uses OpenAI authentication, models, configuration, sandboxing, MCP support, and TUI commands. Claude Code is Anthropic’s separate coding agent with its own command set, permission model, slash commands, configuration, and model family. Commands from one tool should not be assumed to exist in the other.

Is --full-auto still the best way to run autonomous edits?

Not for new scripts. The official command reference marks --full-auto deprecated, while the current local CLI help may still describe it as a convenience alias. Explicit --sandbox and approval flags are easier to audit and less likely to be misunderstood.

Is codex --upgrade current?

The older OpenAI Help Center article mentions codex --upgrade, but the current Codex CLI command reference documents codex update. Treat codex --upgrade as outdated unless codex --help on your installed version confirms it.

Where is Codex configuration stored?

Codex defaults to ~/.codex/config.toml, with logs, auth, and sessions under CODEX_HOME when that environment variable is set. Credentials are cached in ~/.codex/auth.json or an OS credential store depending on cli_auth_credentials_store.

Related Resources

Leave a Reply

Your email address will not be published. Required fields are marked *

Get the latest & top AI tools sent directly to your email.

Subscribe now to explore the latest & top AI tools and resources, all in one convenient newsletter. No spam, we promise!