跳转到内容

Command line options

此页面本次翻译失败,暂时显示官方英文。 失败已记录在同步报告中,不会展示过期或中英混杂的译文。请访问官方原文核对。

For the complete documentation index, see llms.txt. Markdown versions of documentation pages are available by appending .md to the page URL.

This page catalogs every documented Codex CLI command and flag. Use the interactive tables to search by key or description. Each section shows the option’s maturity and flags deprecated options and risky combinations.

The CLI inherits most defaults from ~/.codex/config.toml. Any -c key=value overrides you pass at the command line take precedence for that invocation. See Config basics for more information.

Choose a model available to your signed-in account or workspace. See GPT-6.1 Sol availability before using it with --model.

These options apply to the base codex command. Most propagate to commands; see the notes above or the relevant command help for exceptions. For propagated flags, follow the relevant command help. For example, codex exec --oss ... applies --oss to exec.

The Maturity column uses feature maturity labels such as Experimental, Beta, Stable, and Deprecated. See Feature Maturity for how to interpret these labels.

Running codex with no subcommand launches the interactive terminal UI (TUI). The agent accepts the global flags above plus image attachments. Web search defaults to cached mode; use --search to switch to live browsing. For low-friction local work, use --sandbox workspace-write --ask-for-approval on-request.

Use --remote ws://host:port or --remote wss://host:port to connect the TUI to an app server started with codex app-server --listen ws://IP:PORT. For a local Unix socket, use --remote unix:// for the default socket or --remote unix://PATH for an explicit path. Add --remote-auth-token-env when the server requires a bearer token for WebSocket authentication.

Open the command center to browse chats and switch between agents on a shared server. Use --remote to connect to a remote server and --cd to set the directory for new remote tasks. codex agents doesn’t support --no-daemon.

Queue a text message for an existing session:

Terminal window
codex queue --thread --message "Run the remaining checks"

--thread accepts a UUID or exact session name. Use a UUID when sessions share the same name. The command also accepts --remote and --remote-auth-token-env; image attachments aren’t supported.

Launch the Codex app server locally. This is primarily for development and debugging and may change without notice.

codex app-server --listen stdio:// keeps the default JSONL-over-stdio behavior, and codex app-server --stdio is an alias for that transport. --listen ws://IP:PORT enables WebSocket transport for app-server clients. The server accepts ws:// listen URLs; use TLS termination or a secure proxy when clients connect with wss://. Use --listen unix:// to accept WebSocket handshakes on Codex’s default Unix socket, or --listen unix:///absolute/path.sock to choose a socket path. If you generate schemas for client bindings, add --experimental to include gated fields and methods.

Add --code-mode-host wss://code-mode.example.com/host to connect app-server to a remote Code Mode host instead of starting a local host. This outbound connection is separate from --listen and shared by every thread in the app-server process. Use ws:// only for a localhost or SSH-forwarded host.

Run codex remote-control to start remote control through the managed background server when eligible, with a foreground fallback. Use codex remote-control --no-daemon to run in the foreground explicitly. Use codex remote-control start to start the local app-server daemon with remote control enabled, and codex remote-control stop to stop it. Managed remote-control clients and SSH remote workflows use these commands; they aren’t a replacement for codex app-server --listen when you’re building a local protocol client.

After the daemon is running, use codex remote-control pair to create and print a short-lived manual pairing code. Add --json to any remote-control command for machine-readable output. For pair, the JSON response includes pairingCode, manualPairingCode, environmentId, and expiresAt. --no-daemon applies only to the bare remote-control command; don’t combine it with start, stop, or pair.

Launch the ChatGPT desktop app from the terminal on macOS or Windows. On macOS, Codex can open a specific workspace path; on Windows, Codex prints the path to open.

codex app opens an installed ChatGPT desktop app, or starts the installer when the app is missing. On macOS, Codex opens the provided workspace path; on Windows, it prints the path to open after installation.

Send one message through app-server’s V2 thread/turn flow using the built-in app-server test client.

This debug flow initializes with experimentalApi: true, starts a thread, sends a turn, and streams server notifications. Use it to reproduce and inspect app-server protocol behavior locally.

Print the raw model catalog Codex sees as JSON.

Use --bundled when you want to inspect only the catalog bundled with the current binary, without refreshing from the remote models endpoint.

Render the exact model-visible prompt input list as JSON. Use this when debugging instruction discovery, session context, or prompt construction.

Apply the most recent diff from a Codex cloud chat to your local repository. You must authenticate and have access to the chat.

Codex prints the patched files and exits non-zero if git apply fails (for example, due to conflicts).

Run a code review non-interactively. Choose exactly one review target, or pass custom review instructions as a prompt.

--uncommitted, --base, --commit, and a custom PROMPT conflict with one another. Use --title only with --commit.

Archive or restore a saved interactive session by session ID or session name. Use these commands when you want to clean up the session picker without deleting the transcript. Session IDs take precedence over session names.

Terminal window
codex archive
codex unarchive

Permanently delete a saved interactive session by session ID or session name. Use this only when you want to remove the transcript instead of hiding it from active session lists.

Terminal window
codex delete
codex delete --force

Use --force only with a session UUID. Named sessions still require confirmation so Codex doesn’t delete a repeated or ambiguous name without a prompt.

Interact with Codex cloud chats from the terminal. The default command opens an interactive picker; codex cloud exec submits a task directly, and codex cloud list returns recent chats for scripting or quick inspection.

Authentication follows the same credentials as the main CLI. Codex exits non-zero if the task submission fails.

List recent cloud chats with optional filtering and pagination.

Plain-text output prints a task URL followed by status details. Use --json for automation. The JSON payload contains a tasks array plus an optional cursor value. Each task includes id, url, title, status, updated_at, environment_id, environment_label, summary, is_review, and attempt_total.

Generate shell completion scripts and redirect the output to the appropriate location, for example codex completion zsh > "${fpath[1]}/_codex".

Generate a local diagnostic report before filing a support issue or while investigating a broken Codex installation. The report checks installation, configuration, authentication, runtime, Git, terminal, app-server, and thread inventory health.

Manage feature flags stored in $CODEX_HOME/config.toml. The enable and disable commands persist changes so they apply to future sessions. The features subcommand doesn’t accept --profile.

Use codex exec (or the short form codex e) for scripted or CI-style runs that should finish without human interaction.

Codex writes formatted output by default. Add --json to receive newline-delimited JSON events (one per state change). The optional resume subcommand lets you continue non-interactive tasks. Use --last to pick the most recent session from the current working directory, or add --all to search across all sessions:

Use codex exec fork [PROMPT] to copy a saved session into a new session. The session argument accepts a UUID or name. With no prompt, Codex creates the fork without starting a turn. Pass - as the prompt to read it from stdin, or add --image to attach images.

A prompt is required when using images, --output-schema, --output-last-message, or --ephemeral.

Add --worktree to a new or forked run to create a managed Git worktree:

Terminal window
codex exec --worktree "implement the next step"
codex exec fork --worktree "try an alternative approach"

--worktree requires local execution. Don’t combine it with resume, review, --ephemeral, or --ignore-user-config.

Check execpolicy rule files before you save them. codex execpolicy check accepts one or more --rules flags (for example, files under ~/.codex/rules) and emits JSON showing the strictest decision and any matching rules. Add --pretty to format the output. The execpolicy command is currently in preview.

Authenticate the CLI with a ChatGPT account, API key, or access token. With no flags, Codex opens a browser for the ChatGPT OAuth flow.

codex login status exits with 0 when credentials are present, which is helpful in automation scripts.

Remove saved credentials for both API key and ChatGPT authentication. This command has no flags.

Manage Model Context Protocol server entries stored in ~/.codex/config.toml.

The add subcommand supports both stdio and streamable HTTP transports:

OAuth actions (login, logout) only work with streamable HTTP servers (and only when the server supports OAuth).

Install, list, and remove plugins from configured marketplaces.

codex plugin add --json prints pluginId, name, marketplaceName, version, installedPath, and authPolicy. codex plugin list --json prints installed and available arrays. Entries include pluginId, name, marketplaceName, version, installed, enabled, source, installPolicy, authPolicy, and, when available, marketplaceSource with the configured marketplace source type and value. codex plugin remove --json prints pluginId, name, and marketplaceName.

Manage plugin marketplace sources that Codex can browse and install from.

codex plugin marketplace add accepts GitHub shorthand such as owner/repo or owner/repo@ref, HTTP or HTTPS Git URLs, SSH Git URLs, and local marketplace root directories. Use --ref to pin a Git ref, and repeat --sparse PATH to use a sparse checkout for Git-backed marketplace repositories.

codex plugin marketplace list prints in-scope marketplace names and roots, including implicitly discovered default marketplaces and configured marketplace snapshots.

Add --json to marketplace add, list, upgrade, or remove commands for automation-friendly output. Marketplace add JSON includes marketplaceName, installedRoot, and alreadyAdded; list JSON includes a marketplaces array with name, root, and optional marketplaceSource; upgrade JSON includes selectedMarketplaces, upgradedRoots, and errors; remove JSON includes marketplaceName and installedRoot.

The codex mcp-server command and standalone codex-mcp-server binary have been removed. Use the Codex app server instead.

Continue an interactive session by ID or resume the most recent chat. codex resume scopes --last to the current working directory unless you pass --all. It accepts model and sandbox overrides, but not --worktree.

If the current working directory differs from the session’s saved directory, Codex asks which directory to use. Set tui.resume_cwd to "current" or "session" to reuse that choice without a prompt. An explicit --cd (-C) override takes precedence over tui.resume_cwd.

Fork a previous interactive session into a new chat. By default, codex fork opens the session picker; add --last to fork your most recent session instead.

When the current and saved session directories differ, codex fork uses the same working-directory prompt and tui.resume_cwd setting as codex resume.

To fork into a managed Git worktree, run codex fork --worktree. This requires an explicit session ID and local execution; it doesn’t support --last or the session picker.

Use the sandbox helper to run a command under the same policies Codex uses internally.

Check for and apply a Codex CLI update when the installed release supports self-update. Debug builds print a message telling you to install a release build instead.

  • Use --sandbox workspace-write for unattended local work that can stay inside the workspace, and avoid --dangerously-bypass-approvals-and-sandbox unless you are inside a dedicated sandbox VM.
  • When you need to grant Codex write access to more directories, prefer --add-dir rather than forcing --sandbox danger-full-access.
  • Pair --json with --output-last-message in CI to capture machine-readable progress and a final natural-language summary.
  • Type @ to search for a file in the workspace and add its path to the prompt.
  • Press Up or Down to restore draft history.
  • Press Ctrl+R to search prompt history, then press Enter to use a match or Escape to cancel.
  • Press Ctrl+O or run /copy to copy the latest completed Codex output.
  • Prefix a line with ! to run a local shell command under the current approval and sandbox settings.
  • Press Tab while Codex is working to queue a follow-up prompt, slash command, or shell command for the next turn.
  • Press Enter while Codex is working to inject new instructions into the current turn.
  • Press Escape twice with an empty composer to edit the previous user message and fork the chat from that point.
  • Press Ctrl+C or run /exit to close the session.