在终端中检查、编辑和运行代码
Codex CLI
在终端中检查、编辑和运行代码
Section titled “在终端中检查、编辑和运行代码”无需离开终端,即可检查代码、进行更改、运行命令并自动执行可重复的工作。
$ codex
╭──────────────────────────────────────────────────╮│ >\_ OpenAI Codex ││ ││ model: gpt-5.6-sol medium/model to change ││ directory: ~/code │╰──────────────────────────────────────────────────╯
To get started, describe a task or try one of these commands:
/init - create an AGENTS.md file with instructions for Codex /status - show current session configuration /permissions - choose what Codex is allowed to do /model - choose what model and reasoning effort to use /review - review any changes and find issues
› Refactor the Dashboard component to React Hooks
100% context left · ? for shortcuts01
针对本地代码仓库开展工作
Section titled “针对本地代码仓库开展工作”让 Codex 检查文件、进行编辑,并运行计算机上已安装的工具。
02
选择适合任务的模型、推理力度、权限和命令。
03
使用脚本和 CI 进行编排
Section titled “使用脚本和 CI 进行编排”以交互方式使用 Codex,或在可重复的工作流和流水线中调用 codex exec。
快速入门
开始使用 Codex CLI
Section titled “开始使用 Codex CLI”安装 Codex、登录,并在项目目录中运行你的第一个任务。
-
安装 Codex
Section titled “安装 Codex”使用适用于 macOS 和 Linux 的独立安装程序安装 Codex CLI。
安装 Codex
Terminal window curl -fsSL https://chatgpt.com/codex/install.sh | sh更新 Codex
Terminal window curl -fsSL https://chatgpt.com/codex/install.sh | sh -
运行 Codex 并登录
Section titled “运行 Codex 并登录”打开项目目录并运行
codex。首次运行 Codex 时,请选择 Sign in with ChatGPT 或其他可用的登录方式。 -
开始第一个任务
Section titled “开始第一个任务”描述你想要完成的工作。例如,让 Codex 解释项目、进行一项针对性更改,或帮助调试问题。
Tell me about this project在任务前后创建 Git 检查点,这样你就可以还原更改。请参阅最佳实践。
查看 Codex CLI 的功能
Section titled “查看 Codex CLI 的功能”使用一个专注的终端循环来完成交互式工作、自动化、审查和委派。
01
在终端中完成编码循环
Section titled “在终端中完成编码循环”在代码仓库中启动 Codex,以探索不熟悉的代码、规划更改、编辑文件并运行本地开发工具。引导当前轮次,检查不断显示的命令和差异,并在同一会话中继续后续工作。
>_ OpenAI Codex (v0.143.0)
model: gpt-5.6-sol medium /model to changedirectory: ~/code/my-app02
使用技能和插件
Section titled “使用技能和插件”将可重复的指令打包为技能,然后添加插件,将 Codex 连接到团队的工具和数据,无需离开 CLI。
zsh — plugins
Plugins
Browse plugins from available marketplaces.
Installed 17 of 1751 available plugins.
[All Plugins] Installed (17) OpenAI Curated Workspace Shared with meopenai-primary-runtime Add Marketplace
Type to search plugins
› [-] [Beta] Workspace agents InstalledPress Enter to view plugin details.
[*] Build Web Apps Installed · OpenAI CuratedBuild frontend-focused web apps with browser testing
[-] Default templates Installed · OpenAI CuratedDefault templates for documents, spreadsheets, and slides
[*] Documents Installed · openai-primary-runtimeCreate and edit document artifacts
[*] GitHub Installed · OpenAI CuratedTriage PRs, issues, CI, and publish flows
[*] Gmail Installed · OpenAI CuratedRead and manage Gmail
[*] Google Calendar Installed · OpenAI CuratedManage Google Calendar events and schedules
[-] Google Drive Installed · OpenAI CuratedWork across Drive, Docs, Sheets, and Slides03
在发布前审查更改
Section titled “在发布前审查更改”针对未提交的更改、某次提交或基准分支运行专门的审查。Codex 会报告按优先级排列的问题,但不会修改你的工作树,因此你可以在提交或创建拉取请求前处理风险。
选择审查预设
› 1. Review against a base branch (PR Style) 2. Review uncommitted changes 3. Review a commit 4. Custom review instructions围绕 Codex 构建终端工作流
Section titled “围绕 Codex 构建终端工作流”了解可用于恢复会话、添加视觉和网页上下文、拆分复杂工作以及将 Codex 连接到开发工具的 CLI 功能。
返回已保存的聊天
Section titled “返回已保存的聊天”重新打开当前代码仓库中的最近聊天,或跨本地聊天搜索,以便返回更早的工作。
将视觉上下文添加到提示词
Section titled “将视觉上下文添加到提示词”在第一个提示词中附加错误截图、架构图或设计参考,或者将图片粘贴到交互式编辑器中。
拆分较大的调查任务
Section titled “拆分较大的调查任务”让 Codex 将专注的工作委派给专门的代理,然后将它们的发现带回主终端会话。
搜索最新上下文
Section titled “搜索最新上下文”当任务依赖最新版本、文档或外部行为时,将运行切换为实时网页搜索。搜索活动会持续显示在记录中。
将工作转移到 Codex cloud
Section titled “将工作转移到 Codex cloud”浏览活跃和已完成的聊天,将工作提交到已配置的环境,并从终端将结果应用到本地代码仓库。
使用 MCP 连接外部工具
Section titled “使用 MCP 连接外部工具”添加本地或远程 MCP 服务器,按需进行身份验证,并检查当前会话可用的工具,然后再让 Codex 使用它们。
为每次运行设置边界
Section titled “为每次运行设置边界”选择 Codex 何时可以在不询问的情况下编辑文件或运行命令,并在继续之前检查当前的沙箱和可写入根目录。
让 Codex 适配你的终端
Section titled “让 Codex 适配你的终端”为你的 shell 生成补全,选择语法主题,并在 VISUAL 或 EDITOR 配置的编辑器中打开较长的提示词。
在以下情况下使用 Codex CLI……
Section titled “在以下情况下使用 Codex CLI……”你在终端中工作时
Section titled “你在终端中工作时”在一个专注的循环中探索、编辑并运行代码仓库。
你需要脚本或 CI 时
Section titled “你需要脚本或 CI 时”在可重复的工作流中运行非交互式命令。
你希望进行本地代码审查
Section titled “你希望进行本地代码审查”在提交或创建拉取请求前检查更改。
你想将工作交给云端时
Section titled “你想将工作交给云端时”启动云端聊天,稍后再返回终端。