codex

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

OpenAI Codex Integration

OpenAI Codex 集成

Autonomous code execution using OpenAI Codex CLI.

使用OpenAI Codex CLI实现自主代码执行。

Prerequisites

前提条件

bash
undefined
bash
undefined

Check installation

检查安装

codex --version
codex --version

Install if needed

若未安装则执行以下命令

npm i -g @openai/codex
npm i -g @openai/codex

or

brew install codex

---
brew install codex

---

Sandbox Modes

沙箱模式

ModeFlagCapabilities
Read-Only
-s read-only
Analyze code, no modifications (default)
Workspace-Write
-s workspace-write
or
--full-auto
Read/write files in workspace
Danger-Full-Access
-s danger-full-access
Network, system-level, all files
Key concept: Use
--full-auto
for most programming tasks—it enables file editing.

模式参数功能
只读
-s read-only
分析代码,不允许修改(默认模式)
工作区可写
-s workspace-write
--full-auto
可读写工作区内的文件
危险-完全访问
-s danger-full-access
可访问网络、系统级资源及所有文件
核心概念:大多数编程任务使用
--full-auto
参数即可,它支持文件编辑功能。

Common Commands

常用命令

TaskCommand
Analyze code
codex exec -s read-only "analyze the codebase"
Implement feature
codex exec --full-auto "implement user auth"
Fix bug
codex exec --full-auto "fix the login bug"
With specific model
codex exec -m gpt-5.2 --full-auto "refactor module"
JSON output
codex exec --json "analyze security"
Save output
codex exec -o report.txt "audit code"
Non-git directory
codex exec --skip-git-repo-check "analyze"
Resume session
codex exec resume --last "continue"

任务命令
分析代码
codex exec -s read-only "analyze the codebase"
实现功能
codex exec --full-auto "implement user auth"
修复Bug
codex exec --full-auto "fix the login bug"
指定模型
codex exec -m gpt-5.2 --full-auto "refactor module"
JSON格式输出
codex exec --json "analyze security"
保存输出结果
codex exec -o report.txt "audit code"
非Git目录场景
codex exec --skip-git-repo-check "analyze"
恢复会话
codex exec resume --last "continue"

Model Selection

模型选择

ModelUse Case
gpt-5.2
Latest capabilities
gpt-5.2-codex
Code-specialized
gpt-5.2-codex-max
Maximum quality
Use
-m MODEL
to specify.

模型使用场景
gpt-5.2
具备最新功能
gpt-5.2-codex
代码专用模型
gpt-5.2-codex-max
最高质量模型
使用
-m MODEL
参数指定模型。

Execution Principles

执行原则

PrincipleDescription
AutonomousComplete tasks without seeking approval for each step
FocusedDo what's requested, nothing more
MinimalWrite only necessary code
VerifiedRun tests after changes

原则说明
自主性无需每一步都请求批准即可完成任务
聚焦性仅执行请求的任务,不做额外操作
极简性仅编写必要的代码
可验证性修改后自动运行测试

When to Pause for User

需暂停并询问用户的场景

SituationAction
Destructive operationsAsk first (delete DB, force push)
Security decisionsAsk first (expose credentials, open ports)
Ambiguous requirementsClarify before proceeding
Missing critical infoRequest user-specific data
For everything else, proceed autonomously.

场景操作
破坏性操作先询问用户(如删除数据库、强制推送)
安全相关决策先询问用户(如暴露凭据、开放端口)
需求模糊先澄清需求再继续
缺少关键信息请求用户提供特定数据
除上述场景外,其余情况均自主执行。

Output Format

输出格式

✓ Task completed successfully

Changes made:
- [Files modified/created]
- [Key code changes]

Results:
- [Metrics: lines changed, files affected]

Verification:
- [Tests run, checks performed]

✓ 任务执行成功

已完成的修改:
- [修改/创建的文件]
- [关键代码变更]

执行结果:
- [指标:变更代码行数、受影响文件数]

验证信息:
- [运行的测试、执行的检查]

Error Handling

错误处理

ApproachDescription
Auto-recoverAttempt fix if possible
Log clearlyReport all errors
ContinueIf error is non-blocking
StopOnly if continuation impossible
处理方式说明
自动恢复若可能则尝试修复错误
清晰日志报告所有错误信息
继续执行若错误不影响后续操作则继续
停止执行仅当无法继续时才停止