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: June 15, 2026

Quick Classification

TypeWhere to use it
CLI commandType in your shell, such as codex exec "Fix failing tests".
Slash commandType inside the interactive Codex TUI, such as /status.
TUI shortcutType inside the TUI composer, such as @.
CLI flagAdd after codex or a subcommand, such as --model.
Config keySave in ~/.codex/config.toml.
Environment variableSet in the shell before running Codex.
Integration APIUse through app-server or another integration client.

CLI Commands

Use these from a terminal prompt before or instead of opening the interactive TUI.

CommandUse
npm install -g @openai/codexInstall Codex CLI with npm.
brew install --cask codexInstall Codex CLI with Homebrew on macOS.
codexOpen the interactive TUI in the current project.
codex "Explain this codebase"Open the TUI with an initial prompt.
codex loginStart the default ChatGPT sign-in flow.
codex login --device-authUse device-code auth for headless or remote environments.
printenv OPENAI_API_KEY | codex login --with-api-keySign in with an API key from stdin.
codex login statusCheck the active authentication mode.
codex logoutRemove stored Codex credentials.
codex updateApply an update when the installed build supports self-update.
codex resumeOpen a picker for saved sessions.
codex resume --lastResume the most recent saved session.
codex resume <SESSION_ID>Resume a specific saved session.
codex forkFork a previous session into a new thread.
codex archiveArchive a saved session.
codex unarchiveRestore an archived session.
codex deletePermanently delete a saved session after confirmation.
codex exec "Task"Run a non-interactive task.
codex exec -Read the prompt from stdin.
codex exec resume --last "Task"Continue the last non-interactive run.
codex reviewRun a non-interactive code review.
codex apply <TASK_ID>Apply the latest diff from a Codex Cloud task.
codex doctorCreate a local diagnostic report.
codex appOpen Codex Desktop from the terminal.
codex app <PATH>Open a workspace path in Codex Desktop.
codex app --download-urlPrint the Codex Desktop download URL.
codex completion zshPrint shell completions for a supported shell.

Cloud, MCP, and Plugin CLI Commands

CommandUse
codex cloudOpen a Codex Cloud task picker.
codex cloud list --jsonList recent cloud tasks as JSON.
codex cloud status <TASK_ID>Show a cloud task status.
codex cloud diff <TASK_ID>Show a cloud task diff.
codex cloud apply <TASK_ID>Apply a cloud task diff locally.
codex mcp listList configured MCP servers.
codex mcp get <name>Show one MCP server configuration.
codex mcp add <name> -- <command...>Add a stdio MCP server.
codex mcp add <name> --url https://...Add a streamable HTTP MCP server.
codex mcp login <name>Start OAuth login for an MCP server.
codex mcp logout <name>Remove stored MCP OAuth credentials.
codex mcp remove <name>Delete an MCP server definition.
codex mcp-serverRun Codex itself as an MCP server.
codex plugin list --jsonList installed plugins as JSON.
codex plugin add --jsonAdd a plugin with structured output.
codex plugin remove --jsonRemove a plugin with structured output.
codex plugin marketplace list --jsonList marketplace sources as JSON.
codex plugin marketplace add <source>Add a plugin marketplace.
codex plugin marketplace remove <name>Remove a plugin marketplace.
codex plugin marketplace upgrade [name]Refresh Git-backed plugin marketplaces.

TUI Shortcuts

These are typed inside the TUI composer but are not slash commands.

ShortcutUse
@Open the unified mentions menu for files, plugins, and skills.

Slash Commands

Use these only after codex opens the interactive TUI.

Slash commandUse
/statusCheck model, approval mode, roots, token use, and session details.
/usageView daily, weekly, and cumulative account token activity.
/newStart a new conversation.
/clearClear the terminal and start fresh.
/resumeOpen the saved-session picker.
/forkFork the current conversation.
/archiveArchive the current session.
/deletePermanently delete the current session after confirmation.
/sideStart a temporary side conversation.
/compactSummarize earlier turns to reduce context use.
/copyCopy the latest completed response.
/importImport selected data from Claude Code.
/diffShow current working tree changes.
/reviewReview current changes for bugs and regressions.
/permissionsChange approval behavior.
/sandbox-add-read-dir C:\absolute\pathGrant sandbox read access to another Windows directory.
/mention src/file.tsAttach a file or folder to the conversation.
/initCreate an AGENTS.md scaffold.
/modelChoose model and reasoning effort.
/fast on, /fast off, /fast statusControl Fast mode when supported.
/planSwitch to plan mode.
/goalSet or view a long-running goal.
/personalityChange response style when supported.
/experimentalToggle experimental features.
/mcpList MCP tools in the current session.
/appsBrowse apps and connectors.
/pluginsBrowse installed and discoverable plugins.
/appHand off the current CLI thread to Codex Desktop.
/statuslineConfigure TUI footer fields.
/titleConfigure terminal title fields.
/keymapRemap TUI keyboard shortcuts.
/agentManage delegated agents when available.
/psList background terminals or running tasks.
/stopStop a running task.
/exit or /quitExit the TUI.
/logoutSign out from inside the TUI.
/feedbackOpen the feedback flow.
/approvalsLegacy alias. Prefer /permissions.
/cleanAlias for /stop.

CLI Flags

Add these to codex, codex exec, or another subcommand when the command supports them.

FlagUse
--add-dir <path>Grant access to another directory.
--ask-for-approval, -a <policy>Set approval behavior for one run.
--cd, -C <path>Set the working directory.
--config, -c key=valueOverride config for one invocation.
--dangerously-bypass-approvals-and-sandboxDisable approvals and sandboxing.
--yoloAlias for bypassing approvals and sandboxing.
--disable <feature>Disable a feature flag for one run.
--enable <feature>Enable a feature flag for one run.
--image, -i <path>Attach an image to the first prompt.
--help, -hPrint help.
--version, -VPrint the installed CLI version.
--model, -m <model>Override the configured model.
--no-alt-screenDisable alternate-screen TUI mode.
--ossUse a local open source provider.
--local-provider <provider>Select a local OSS provider.
--profile, -p <name>Load a config profile.
--remote <ws://host:port>Connect the TUI to a remote app server.
--remote-auth-token-env <ENV_VAR>Send a bearer token for remote TUI auth.
--sandbox, -s <mode>Set sandbox policy.
--searchEnable live web search.
--jsonPrint newline-delimited JSON events for codex exec.
--ephemeralAvoid saving session rollout files.
--skip-git-repo-checkRun outside a Git repository.
--ignore-user-configIgnore user config for one run.
--ignore-rulesSkip user and project execpolicy rules.
--color neverControl ANSI color output.
--output-last-message out.mdSave the final response to a file.
--output-schema schema.jsonValidate the final response against a JSON Schema.
--full-autoDeprecated shortcut. Prefer explicit sandbox and approval flags.
--experimental-jsonLegacy alias for --json.

Config Keys

Put these in ~/.codex/config.toml when you want persistent defaults.

Config keyUse
model = "gpt-5.5"Set the default model.
model_reasoning_effort = "medium"Set default reasoning effort.
model_reasoning_summary = "auto"Control reasoning summary detail.
model_verbosity = "medium"Set GPT-5 Responses API verbosity.
model_provider = "openai"Select the model provider.
oss_provider = "ollama"Set the provider used by --oss.
review_model = "<model>"Set the model used by /review.
sandbox_mode = "workspace-write"Persist the sandbox policy.
sandbox_workspace_write.writable_roots = ["/path"]Add writable roots in workspace-write mode.
sandbox_workspace_write.network_access = trueAllow outbound network in workspace-write mode.
approval_policy = "on-request"Persist approval behavior.
history.persistence = "none"Stop transcript persistence.
hide_agent_reasoning = trueHide reasoning events in TUI and exec output.
mcp_servers.<id>.command = "node"Define a stdio MCP launcher command.
mcp_servers.<id>.args = ["server.js"]Define stdio MCP launcher arguments.
mcp_servers.<id>.env = { KEY = "VALUE" }Set environment variables for a stdio MCP server.
mcp_servers.<id>.bearer_token_env_var = "TOKEN_ENV"Read an HTTP bearer token from an environment variable.
mcp_servers.<id>.enabled = falseDisable a server without deleting it.
mcp_servers.<id>.enabled_tools = ["tool_name"]Allow only selected MCP tools.
mcp_servers.<id>.disabled_tools = ["tool_name"]Block selected MCP tools.
Hooks in config.tomlRun lifecycle hooks.

Environment Variables

VariableUse
OPENAI_API_KEYStore an OpenAI API key for API-key auth flows.
CODEX_API_KEYRegister remote execution setup for approved OpenAI hosts.
CODEX_HOMEChange where Codex stores config, auth, logs, and sessions.
CODEX_NON_INTERACTIVE=1Run supported install scripts without prompts.
CODEX_CA_CERTIFICATEPoint Codex at a custom CA bundle.
SSL_CERT_FILEFallback custom CA bundle path.
RUST_LOGControl Rust logging verbosity.
CODEX_REMOTE_AUTH_TOKENExample bearer-token variable for remote TUI auth.
Custom provider env_keySupply a provider-specific API key.

Experimental CLI Commands

CommandUse
codex app-serverRun the Codex app server for local integration work.
codex app-server --stdioLaunch app-server in stdio mode.
codex remote-controlStart or manage a remotely controllable app-server.
codex execpolicyTest execpolicy rules.
codex sandbox macos -- <COMMAND>Run a command under the macOS sandbox helper.
codex sandbox linux -- <COMMAND>Run a command under the Linux sandbox helper.
codex sandbox windows -- <COMMAND>Run a command under the Windows sandbox helper.
codex sandbox setup --elevatedProvision supported Windows sandbox requirements.
codex --upgradeOlder update command. Prefer codex update.
codex debug seatbeltLegacy alias. Prefer codex sandbox macos.
codex debug landlockLegacy alias. Prefer codex sandbox linux.

App Server Integration APIs

Integration APIUse
app-server thread/deleteDelete a thread through app-server integration.

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.

Set a Long-Running Goal

codex features enable goals
codex
/goal ship the parser refactor without changing public behavior

Use this when a long task needs a persistent target that Codex can track across the session. The feature is experimental and requires features.goals.

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 and recent changelog entries list many slash commands, including /status, /usage, /model, /permissions, /compact, /diff, /review, /resume, /new, /import, /delete, and /goal. They work inside the interactive TUI, not directly from the shell. Some slash commands, including /goal, are experimental or feature-gated.

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. Recent releases also added encrypted local storage for CLI and MCP OAuth credentials.

Command Verification Notes

Use the official OpenAI Codex CLI documentation as the primary source for command availability. Local codex --help output is useful for checking the installed version, but it can lag behind the latest CLI release or differ from Codex Desktop behavior.

When the official docs and local help differ, mark the command as official but version-dependent, then include the feature flag, platform, or release condition that controls access.

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!