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
相关推荐
那年那棵树21 小时前
基于WebGis的人生如旅地图系统
前端·arcgis·vue·课程设计
梅如你2 天前
全国逐年 1KM 分辨率 NDVI 植被指数数据集(2000-2024)
arcgis·gis·遥感
const_qiu3 天前
第二章 2.4:搭建 Monorepo 骨架 + 共享包 @autix/contracts
java·人工智能·arcgis
地图小课堂4 天前
Bigemap Pro 教程|如何打开Arcgis文件格式(shp、gdb、gdbtable、mdb)
arcgis
广州浮点FLOATLIC4 天前
ArcGIS Pro 批处理失败,怎样判断是脚本报错还是许可条件不满足?
arcgis·许可管理·许可证管理·许可监控
hsg776 天前
简述:ArcGIS Pro新建地图底图加载慢,选项设置方法
arcgis·建库
hsg776 天前
简述:修改ArcGIS Pro:选项-应用程序-显示-本地缓存
arcgis·建库
VX130715441228 天前
测绘资质延续申请申报材料常见退件问题及解答
搜索引擎·arcgis·全文检索
非科班Java出身GISer8 天前
ArcGIS JS 基础教程(41):Popup 弹出窗
arcgis·arcgis js 弹出框·arcgis js 气泡框·arcgis js 信息框·arcgis 弹出框·arcgis 气泡框·arcgis 信息框
喆星时瑜17 天前
ArcGIS Pro 基础制图教程
arcgis·arcgis pro·地图制图·arcgis pro 制图