OpenAI Codex CLI Commands

Complete OpenAI Codex CLI commands reference — 114 commands across 16 categories. Quick reference cheat sheet for Cross-platform.

Codex CLI is OpenAI's terminal coding agent, and this page is its command-line surface: the global flags that shape a session, the subcommands, and the per-command options as the current release prints them in --help. The slash commands and prompt conventions used inside the TUI live on the prompts page; this one is about how you start Codex and how you run it unattended.

Looking for slash commands? They moved to the new Codex CLI prompt commands reference.

Global Flags (20)

ShortcutAction
--add-dirGrant additional directories write access alongside the main workspace. Repeat for multiple
--ask-for-approval, -aControl when Codex pauses for human approval before running a command
--cd, -CSet the working directory for the agent before it starts processing your request
--config, -cOverride configuration values. Values parse as TOML if possible; otherwise the literal string
--dangerously-bypass-approvals-and-sandbox, --yoloRun every command without approvals or sandboxing. Only use inside an externally hardened
--dangerously-bypass-hook-trustRun enabled hooks without requiring persisted hook trust for this invocation. Intended only
--disableForce-disable a feature flag (translates to -c features.<name>=false). Repeatable
--enableForce-enable a feature flag (translates to -c features.<name>=true). Repeatable
--image, -iAttach one or more image files to the initial prompt. Separate multiple paths with commas
--local-providerChoose the local provider used with --oss, overriding oss_provider for this run
--model, -mOverride the model set in configuration (for example gpt-5.4)
--no-alt-screenDisable alternate screen mode for the TUI (overrides tui.alternate_screen for this run)
--ossUse a local open source model provider. Codex uses --local-provider, your configured
--profile, -pLayer $CODEX_HOME/profile-name.config.toml on top of the base user config
--remoteConnect to a remote app-server endpoint over WebSocket or a Unix socket. Supported for codex
--remote-auth-token-envRead a bearer token from this environment variable and send it when connecting with --remote.
--sandbox, -sSelect the sandbox policy for model-generated shell commands
--searchEnable live web search (sets web_search = "live" instead of the default "cached")
--strict-configError when config.toml contains fields this Codex version does not recognize. Supported
PROMPTOptional text instruction to start the session. Omit to launch the TUI without a pre-filled

Commands (28)

ShortcutAction
codexLaunch the terminal UI. Accepts the global flags above plus an optional prompt or image
codex appLaunch the ChatGPT desktop app on macOS or Windows. On macOS, Codex can open a workspace path
codex app-serverLaunch the Codex app server for local development or debugging over stdio, WebSocket, or a Unix
codex applyApply the latest diff generated by a Codex cloud chat to your local working tree. Alias: codex
codex archiveArchive a saved interactive session by session ID or session name
codex cloudBrowse or execute Codex cloud chats from the terminal without opening the TUI. Alias: codex
codex completionGenerate shell completion scripts for Bash, Zsh, Fish, or PowerShell
codex debug app-server send-message-v2Debug app-server by sending a single V2 message through the built-in test client
codex debug modelsPrint the raw model catalog Codex sees, including an option to inspect only the bundled catalog
codex debug prompt-inputRender the model-visible prompt input list as JSON, optionally with a prompt and images
codex deletePermanently delete a saved interactive session by session ID or session name
codex doctorGenerate a diagnostic report for local installation, config, auth, runtime, Git, terminal
codex execRun Codex non-interactively. Alias: codex e. Stream results to stdout or JSONL and optionally
codex execpolicyEvaluate execpolicy rule files and see whether a command would be allowed, prompted, or blocked
codex featuresList feature flags and persistently enable or disable them in config.toml
codex forkFork a previous interactive session into a new chat, preserving the original transcript
codex loginAuthenticate Codex using ChatGPT OAuth, device auth, an API key, or an access token piped over
codex logoutRemove stored authentication credentials
codex mcpManage Model Context Protocol servers (list, add, remove, authenticate)
codex mcp-serverRun Codex itself as an MCP server over stdio. Useful when another agent consumes Codex
codex pluginInstall, list, and remove plugins from configured marketplace sources
codex plugin marketplaceAdd, list, upgrade, or remove plugin marketplaces from Git or local sources
codex remote-controlRun or manage remote control for the local app-server, or create a short-lived pairing code
codex resumeContinue a previous interactive session by ID or resume the most recent chat
codex reviewRun a non-interactive review of uncommitted changes, a base branch diff, a commit, or custom
codex sandboxRun arbitrary commands inside Codex-provided macOS, Linux, or Windows sandboxes
codex unarchiveRestore an archived interactive session by session ID or session name
codex updateCheck for and apply a Codex CLI update when the installed release supports self-update

codex app-server (10)

ShortcutAction
--analytics-default-enabledDefaults analytics to enabled for first-party app-server clients unless the user opts out
--listenTransport listener URL. Use stdio:// for JSONL, ws://IP:PORT for a TCP WebSocket endpoint
--stdioUse stdio transport. Equivalent to --listen stdio:// and mutually exclusive with --listen
--ws-audienceExpected aud claim for signed bearer tokens. Requires --ws-auth signed-bearer-token
--ws-authAuthentication mode for app-server WebSocket clients. If omitted, WebSocket auth is disabled
--ws-issuerExpected iss claim for signed bearer tokens. Requires --ws-auth signed-bearer-token
--ws-max-clock-skew-secondsClock skew allowance when validating signed bearer token exp and nbf claims. Requires --ws-auth
--ws-shared-secret-fileFile containing the HMAC shared secret used to validate signed JWT bearer tokens. Required
--ws-token-fileFile containing the shared capability token. Use with --ws-auth capability-token unless you
--ws-token-sha256Expected SHA-256 digest for capability-token authentication. Use instead of --ws-token-file

codex app (2)

ShortcutAction
--download-urlAdvanced override for the ChatGPT desktop app installer URL used during install
PATHWorkspace path for the ChatGPT desktop app. On macOS, Codex opens this path; on Windows, Codex

codex review (4)

ShortcutAction
--baseReview changes against the specified base branch
--commitReview the changes introduced by the specified commit
--titleSet the commit title shown in the review summary. Requires --commit
--uncommittedReview staged, unstaged, and untracked changes

codex cloud (3)

ShortcutAction
--attemptsNumber of assistant attempts (best-of-N) Codex cloud should run
--envTarget Codex cloud environment identifier (required). Use codex cloud to list options
QUERYTask prompt. If omitted, Codex prompts interactively for details

codex cloud list (3)

ShortcutAction
--cursorPagination cursor returned by a previous request
--jsonEmit machine-readable JSON instead of plain text
--limitMaximum number of tasks to return

codex doctor (4)

ShortcutAction
--allExpand long lists in the detailed human-readable report
--asciiUse ASCII status labels and separators in human-readable output
--no-colorDisable ANSI color in human-readable output
--summaryShow grouped check rows and the final count summary only

codex exec (12)

ShortcutAction
--colorControl ANSI color in stdout
--ephemeralRun without persisting session rollout files to disk
--full-autoDeprecated compatibility flag. Prefer --sandbox workspace-write; Codex prints a warning when
--ignore-rulesDo not load user or project execpolicy .rules files for this run
--ignore-user-configDo not load $CODEX_HOME/config.toml. Authentication still uses CODEX_HOME
--json, --experimental-jsonPrint newline-delimited JSON events instead of formatted text
--output-last-message, -oWrite the assistant's final message to a file. Useful for downstream scripting
--output-schemaJSON Schema file describing the expected final response shape. Codex validates tool output
--skip-git-repo-checkAllow running outside a Git repository (useful for one-off directories)
-c, --configInline configuration override for the non-interactive run (repeatable)
--lastResume the most recent chat from the current working directory
SESSION_IDResume the specified session. Omit and use --last to continue the most recent session

codex execpolicy (3)

ShortcutAction
--prettyPretty-print the JSON result
--rules, -rPath to an execpolicy rule file to evaluate. Provide multiple flags to combine rules across
COMMAND...Command to be checked against the specified policies

codex login (3)

ShortcutAction
--device-authUse OAuth device code flow instead of launching a browser window
--with-access-tokenRead an access token from stdin
--with-api-keyRead an API key from stdin (for example printenv OPENAI_API_KEY | codex login --with-api-key)

codex mcp (6)

ShortcutAction
listList configured MCP servers. Add --json for machine-readable output
--bearer-token-env-varEnvironment variable whose value is sent as a bearer token when connecting to a streamable HTTP
--env KEY=VALUEEnvironment variable assignments applied when launching a stdio server
--oauth-client-idOAuth client identifier for a streamable HTTP MCP server. Requires --url
--oauth-resourceOAuth resource parameter to include during login for a streamable HTTP MCP server. Requires
--urlRegister a streamable HTTP server instead of stdio. Mutually exclusive with COMMAND

Sandbox (4)

ShortcutAction
--allow-unix-socketAllow the sandboxed command to bind or connect Unix sockets rooted at this path. Repeat
--include-managed-configInclude managed requirements while resolving an explicit permissions profile. Requires
--log-denialsCapture macOS sandbox denials with log stream while the command runs and print them after exit
--permission-profile, -PApply a named permissions profile from the active configuration stack

Extension Commands (6)

ShortcutAction
chatgpt.addToThreadAdd selected text range as context for the current chat
chatgpt.addFileToThreadAdd the entire file as context for the current chat
chatgpt.newChatCreate a new chat
chatgpt.newCodexPanelCreate a new Codex panel
chatgpt.openCommandMenuOpen the Codex command menu
chatgpt.openSidebarOpen the Codex sidebar panel

Additional Commands (6)

ShortcutAction
EscStop response
Up / DownBrowse history
TabAutocomplete
Ctrl + CCancel
Ctrl + LClear screen
Ctrl + DExit
📄 View Printable Cheat Sheet — Download as PDF or print · 🧩 Combine with other tools

Related Shortcut Pages

Claude Code Aider Cursor AI GitHub Copilot Gemini CLI Warp Terminal

Search 18,500+ shortcuts across 268 platforms

Explore All Platforms Practice Shortcuts

Starting a session

codex alone opens the terminal UI in the current directory; give it a prompt as an argument to skip the first question. --model, -m overrides the configured model for one run, --cd, -C sets the working directory, and --add-dir grants write access to a second directory such as a shared library next to the app. --profile, -p layers a named config file over the base one, which is how a team keeps separate settings for reviewing versus generating. --image, -i attaches screenshots to the first prompt, useful for "make it look like this".

Approval and the sandbox

--ask-for-approval, -a sets when Codex stops for confirmation before running a command, and --permission-profile, -P applies a named sandbox profile from the configuration. --dangerously-bypass-approvals-and-sandbox, --yolo removes both — the flag name is long on purpose, and it belongs only inside a container or a throwaway VM. codex execpolicy evaluates a rule file against a command to show whether it would be allowed, prompted or blocked, which is the way to test a policy before trusting it. --log-denials on macOS prints what the sandbox blocked after a command exits.

Running unattended and reviewing

codex exec runs one prompt non-interactively for scripts and CI, streaming to stdout; add --json, --experimental-json for newline-delimited events, --output-last-message, -o to write the final answer to a file, and --output-schema to validate it against a JSON Schema. --last resumes the most recent session and --ephemeral leaves no session files behind. codex review reviews changes — --uncommitted for the working tree, --base against a branch, --commit for one commit — and prints findings without editing. codex doctor diagnoses install, auth and Git problems, and codex mcp registers tool servers.

Frequently asked questions

What is the difference between codex and codex exec?

codex opens the interactive TUI. codex exec runs a single prompt to completion without a UI, for scripts and CI.

How do I stop Codex asking for approval?

Lower the approval mode with -a, or use a permission profile with -P. --yolo disables approvals and the sandbox entirely and should only run inside a hardened container.

How do I resume yesterday's session?

codex exec --last resumes the most recent session in the current directory; pass a SESSION_ID to resume a specific one.

How do I get structured output from a run?

Use codex exec with --json for event streams, or --output-schema with a JSON Schema file to validate the final message.

🤖 Ask AI about OpenAI Codex CLI shortcuts

Open your assistant with this page preloaded as the source — great for follow-up questions like "which of these work in other apps?"

ChatGPT Claude Perplexity Gemini Grok
📜 Every shortcut on this page is taken from the official OpenAI Codex CLI documentation — developers.openai.com
🔧 Spotted an error or a missing shortcut? Suggest an edit on GitHub — every accepted fix goes live on this page, the API and the CLI.