Codex CLI使用记录

Codex CLI是什么

Codex CLI是OpenAI推出的官方原生终端AI编程工具,基于Rust构建,开源免费,可直接在你的终端中完成代码生成 、重构、BUG修复、项目分析、文档生成等全流程开发操作,支持几乎所有主流编程语言与开发场景。

安装前环境预检

安装前请先执行以下2条命令,确认你的环境符合要求,避免后续安装失败:

bash 复制代码
# 检查Node.js版本,需输出v20.0.0及以上版本
node --version

# 检查npm版本,需输出v10.0.0及以上版本
npm --version

安装命令

bash 复制代码
npm i -g @openai/codex
-- 终端输出
added 2 packages in 12s
npm notice
npm notice New major version of npm available! 10.8.2 -> 12.0.2
npm notice Changelog: https://github.com/npm/cli/releases/tag/v12.0.2
npm notice To update run: npm install -g npm@12.0.2
npm notice

查询版本

bash 复制代码
codex --version
-- 终端输出
codex-cli 0.153.4

获取帮助(功能验证)

bash 复制代码
codex --help
-- 终端输出
Codex CLI

If no subcommand is specified, options will be forwarded to the interactive CLI.

Usage: codex [OPTIONS] [PROMPT]
       codex [OPTIONS] <COMMAND> [ARGS]

Commands:
  agents            Browse all agent sessions on the shared local app-server daemon
  exec              Run Codex non-interactively [aliases: e]
  review            Run a code review non-interactively
  login             Manage login
  logout            Remove stored authentication credentials
  mcp               Manage external MCP servers for Codex
  plugin            Manage Codex plugins
  mcp-server        Start Codex as an MCP server (stdio)
  app-server        [experimental] Run the app server or related tooling
  remote-control    [experimental] Manage the app-server daemon with remote control enabled
  app               Launch the Desktop app (opens the app installer if missing)
  completion        Generate shell completion scripts
  update            Update Codex to the latest version
  doctor            Diagnose local Codex installation, config, auth, and runtime health
  sandbox           Run commands within a Codex-provided sandbox
  debug             Debugging tools
  apply             Apply the latest diff produced by Codex agent as a `git apply` to your local working tree [aliases:
                    a]
  resume            Resume a previous interactive session (picker by default; use --last to continue the most recent)
  queue             Queue a message for an existing session
  archive           Archive a saved session by id or session name
  delete            Permanently delete a saved session by id or session name
  migrate-rollouts  Inspect or migrate legacy local sessions to paginated thread history
  unarchive         Unarchive a saved session by id or session name
  fork              Fork a previous interactive session (picker by default; use --last to fork the most recent)
  cloud             [EXPERIMENTAL] Browse tasks from Codex Cloud and apply changes locally
  exec-server       [EXPERIMENTAL] Run the standalone exec-server service
  features          Inspect feature flags
  help              Print this message or the help of the given subcommand(s)

Arguments:
  [PROMPT]
          Optional user prompt to start the session

Options:
  -c, --config <key=value>
          Override a configuration value that would otherwise be loaded from `~/.codex/config.toml`. Use a dotted path
          (`foo.bar.baz`) to override nested values. The `value` portion is parsed as TOML. If it fails to parse as
          TOML, the raw string is used as a literal.

          Examples: - `-c model="o3"` - `-c 'sandbox_permissions=["disk-full-read-access"]'` - `-c
          shell_environment_policy.inherit=all`

      --enable <FEATURE>
          Enable a feature (repeatable). Equivalent to `-c features.<name>=true`

      --disable <FEATURE>
          Disable a feature (repeatable). Equivalent to `-c features.<name>=false`

      --remote <ADDR>
          Connect the TUI to a remote app server endpoint.

          Accepted forms: `ws://host:port`, `wss://host:port`, `unix://`, or `unix://PATH`.

      --remote-auth-token-env <ENV_VAR>
          Name of the environment variable containing the bearer token to send to a remote app server websocket

      --strict-config
          Error out when config.toml contains fields that are not recognized by this version of Codex

  -i, --image <FILE>...
          Optional image(s) to attach to the initial prompt

  -m, --model <MODEL>
          Model the agent should use

      --oss
          Use open-source provider

      --local-provider <OSS_PROVIDER>
          Specify which local provider to use (lmstudio or ollama). If not specified with --oss, will use config default
          or show selection

  -p, --profile <CONFIG_PROFILE_V2>
          Layer $CODEX_HOME/<name>.config.toml on top of the base user config

  -s, --sandbox <SANDBOX_MODE>
          Select the sandbox policy to use when executing model-generated shell commands

          [possible values: read-only, workspace-write, danger-full-access]

      --approve-for-me
          Route approval requests through automatic review using the workspace-write sandbox

      --dangerously-bypass-approvals-and-sandbox
          Skip all confirmation prompts and execute commands without sandboxing. EXTREMELY DANGEROUS. Intended solely
          for running in environments that are externally sandboxed

      --dangerously-bypass-hook-trust
          Run enabled hooks without requiring persisted hook trust for this invocation. DANGEROUS. Intended only for
          automation that already vets hook sources

  -C, --cd <DIR>
          Tell the agent to use the specified directory as its working root

      --add-dir <DIR>
          Additional directories that should be writable alongside the primary workspace

  -a, --ask-for-approval <APPROVAL_POLICY>
          Configure when the model requires human approval before executing a command

          Possible values:
          - on-request: The model decides when to ask the user for approval
          - never:      Never ask for user approval Execution failures are immediately returned to the model

      --search
          Enable live web search. When enabled, the native Responses `web_search` tool is available to the model (no
          per‑call approval)

      --no-alt-screen
          Disable alternate screen mode

          Runs the TUI in inline mode, preserving terminal scrollback history.

  -h, --help
          Print help (see a summary with '-h')

  -V, --version
          Print version
相关推荐
2601_962381582 天前
ArcGIS+Python+AI赋能高标准农田建设项目审计提质增效
python·arcgis·ai·高标准农田审计·大数据审计
飞鹰@四海2 天前
Claude Code 报「与 Windows 版本不兼容」——完整排查与修复指南
arcgis
非科班Java出身GISer4 天前
ArcGIS JS 基础教程(30):体元系列 - VoxelSlice 体元切片
arcgis·arcgis js 体元图层·arcgis js 体元·arcgis 体元图层·arcgis js 体元切片·arcgis 体元切片·arcgis 体元
玩大数据的龙威4 天前
农经权二轮延包—全面取代人工公示图生成
python·arcgis
非科班Java出身GISer7 天前
ArcGIS JS 基础教程(30):体元系列 - 体元切片 VoxelSlice
arcgis·arcgis 体元图层·arcgis js 体元切片·arcgis 体元切片·arcgis slice·voxelslice·体元切片
非科班Java出身GISer10 天前
ArcGIS JS 基础教程(30):体元系列 - VoxelLayer 体元图层
arcgis·arcgis js 体元图层·arcgis js 体元·arcgis js 体素·arcgis js 体素图层·arcgis 体元图层·arcgis 体素图层
非科班Java出身GISer13 天前
ArcGIS JS 基础教程(29):CSVLayer 表格点位图层
arcgis·arcgis js·arcgis js csv图层·arcgis js scv·arcgis csv 图层
CAE32014 天前
ArcGIS DEM水文分析与山洪风险评估
arcgis·dem·流域提取
你是一个铁憨憨17 天前
从 GIS 到 Spatial Agent:MCP 如何重新定义 GIS 的 AI 入口
arcgis·ai·agent·mcp·spatial