AI agents

Codex CLI

Codex CLI terminal commands

CLI commands vs slash commands. Commands on this page are typed in your terminal — they invoke the codex binary itself (e.g. codex exec "fix the tests"). Slash commands like /compact are typed inside the interactive TUI’s composer and control the live session (see Codex CLI slash commands). The two layers overlap in name sometimes (codex review vs /review) but they are different things.

Interactive UI

codex

codex [PROMPT]

Launches the interactive terminal UI. Accepts global flags plus an optional prompt and image attachments (-i). Web search defaults to cached mode; --search switches to live. A suggested low-friction local combo:

codex --sandbox workspace-write --ask-for-approval on-request

Non-interactive runs

codex exec (alias codex e)

codex exec [FLAGS] [PROMPT]
codex exec "Fix the failing test in src/auth"          # one-shot
echo "Summarize this diff" | git diff | codex exec -  # prompt from stdin
codex exec --json -o result.txt "Find unused exports"    # CI-friendly

The non-interactive/scripted mode. Key behaviors:

  • Streams progress to stderr; prints only the final agent message to stdout.
  • PROMPT may be - to read the prompt from stdin. If stdin is piped and a prompt argument is given, the argument is the instruction and the piped content is additional context.
  • Default sandbox is read-only.
  • Requires a Git repo by default; override with --skip-git-repo-check.
  • Useful flags: --json (newline-delimited JSON events), -o/--output-last-message <path>, --output-schema <path> (JSON Schema for the final response), --color always|never|auto, --ephemeral (don’t persist rollout files).

Continue a non-interactive session:

codex exec resume [SESSION_ID] [--last] [--all] [PROMPT]

--last picks the most recent session from the current directory; --all searches sessions from any directory.

Session management

codex resume

codex resume                 # open the session picker
codex resume --last          # most recent session in this directory
codex resume <SESSION_ID>    # by ID or name
codex resume --all           # include sessions from other directories
codex resume --include-non-interactive

Continues an interactive session. If the current directory differs from the session’s saved directory, Codex asks which to use (controlled by tui.resume_cwd; an explicit --cd wins). Accepts the same global flags as codex.

codex fork

codex fork [SESSION_ID] [--last] [--all]

Forks a previous interactive session into a new chat, preserving the original transcript.

codex archive / codex unarchive / codex delete

codex archive <SESSION>      # hide a saved session (ID or name; IDs take precedence)
codex unarchive <SESSION>    # restore it
codex delete <SESSION>       # permanently delete
codex delete --force <UUID>  # skip confirmation; only with a session UUID

Authentication

codex login

codex login                                       # browser-based ChatGPT OAuth (default)
codex login --device-auth                         # device-code flow
printenv OPENAI_API_KEY | codex login --with-api-key
codex login --with-access-token                   # access token from stdin
codex login status                                # print auth mode; exits 0 when logged in

codex logout

Removes saved credentials for both API key and ChatGPT auth. No flags.

MCP

codex mcp

Manages MCP server entries stored in ~/.codex/config.toml:

codex mcp list [--json]
codex mcp get <name> [--json]
codex mcp add <name> [--env KEY=VALUE ...] -- <command...>     # stdio server
codex mcp add <name> --url <https://...> [--bearer-token-env-var ENV_VAR]
codex mcp login <name>     # OAuth login (streamable HTTP servers only)
codex mcp logout <name>
codex mcp remove <name>

See Codex CLI and MCP servers for a walkthrough.

codex mcp-server

Runs Codex itself as an MCP server over stdio so other tools can connect. Exits when the downstream client closes the connection.

Code review

codex review

codex review --uncommitted                  # staged + unstaged + untracked changes
codex review --base main                    # diff against a branch
codex review --commit <SHA> --title "..."
codex review "Review the retry logic"       # custom prompt (- reads from stdin)

Non-interactive code review. Exactly one target (or a custom prompt); targets conflict with one another. Review does not modify the working tree. For interactive review inside the TUI, use /review.

Cloud tasks

codex apply (alias codex a)

codex apply <TASK_ID>

Applies the most recent diff from a Codex cloud chat to the local working tree (requires auth and access to the chat). Exits non-zero if git apply fails. Note: this is not a generic patch helper — it is cloud-task oriented.

codex cloud (alias codex cloud-tasks, experimental)

codex cloud                                          # interactive picker
codex cloud exec --env <ENV_ID> [--attempts 1-4] [QUERY]
codex cloud list [--env ENV_ID] [--limit 1-20] [--cursor] [--json]

Browse and execute Codex cloud chats from the terminal without the TUI.

Shell integration and diagnostics

codex completion

codex completion <bash|zsh|fish|power-shell|elvish>
codex completion zsh > "${fpath[1]}/_codex"

Prints a shell completion script to stdout.

codex doctor

codex doctor [--all] [--ascii] [--json] [--no-color] [--summary]

Diagnostic report covering install, config, auth, runtime, Git, terminal, app-server, and threads. First thing to run when something is broken.

codex features

codex features list
codex features enable <feature>
codex features disable <feature>

Manages feature flags persisted in $CODEX_HOME/config.toml.

codex plugin

codex plugin add|list|remove
codex plugin marketplace add|list|remove|upgrade

Installs plugins from marketplaces — GitHub shorthand owner/repo[@ref], Git URLs, or local directories (--ref, --sparse). Plugins can distribute skills and MCP servers; see Codex CLI skills.

Sandbox and policy testing

codex sandbox

codex sandbox macos|linux|windows [--permission-profile NAME] [-- COMMAND...]

Runs a command under the OS sandbox Codex uses internally — useful for testing what an agent run will be allowed to do. Aliases: codex debug, codex sandbox seatbelt, codex sandbox landlock.

codex execpolicy check (experimental/preview)

codex execpolicy check --rules <file> [-r ...] [--pretty] -- <COMMAND...>

Tests execpolicy .rules files against a command; emits JSON with the strictest decision.

Miscellaneous

CommandPurposeMaturity
codex app [PATH]Launch the ChatGPT desktop app (macOS/Windows)Stable
codex app-serverLocal app server for development/debugging (--listen, --stdio, WS auth flags)Experimental
codex remote-controlRun/manage remote control for a local app-server (start/stop/pair, --json)Experimental
codex debug app-server send-message-v2, codex debug models [--bundled], codex debug prompt-inputDebugging helpersExperimental
codex updateSelf-update when the installed release supports itStable

The CLI overview table marks one command as deprecated, but its name could not be captured from the official docs — ? Unable to verify.


Last verified: 2026-09-07

Official sources:

AI coding tools evolve quickly. If you find outdated information, please open an issue or pull request.