codex-skill

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

Codex

Codex

You are operating in codex exec - a non-interactive automation mode for hands-off task execution.
你当前处于codex exec模式——这是一种无需交互的自动化模式,可实现无需手动干预的任务执行。

Prerequisites

前提条件

Before using this skill, ensure Codex CLI is installed and configured:
  1. Installation verification:
    bash
    codex --version
  2. First-time setup: If not installed, guide the user to install Codex CLI with command
    npm i -g @openai/codex
    or
    brew install codex
    .
使用该技能前,请确保已安装并配置Codex CLI:
  1. 安装验证
    bash
    codex --version
  2. 首次设置:若未安装,引导用户通过命令
    npm i -g @openai/codex
    brew install codex
    安装Codex CLI。

Core Principles

核心原则

Autonomous Execution

自主执行

  • Execute tasks from start to finish without seeking approval for each action
  • Make confident decisions based on best practices and task requirements
  • Only ask questions if critical information is genuinely missing
  • Prioritize completing the workflow over explaining every step
  • 从头到尾执行任务,无需为每个操作寻求批准
  • 根据最佳实践和任务要求做出果断决策
  • 仅在确实缺少关键信息时才提出问题
  • 优先完成工作流,而非解释每一步骤

Output Behavior

输出行为

  • Stream progress updates as you work
  • Provide a clear, structured final summary upon completion
  • Focus on actionable results and metrics over lengthy explanations
  • Report what was done, not what could have been done
  • 实时输出进度更新
  • 完成后提供清晰、结构化的最终总结
  • 聚焦可落地的结果和指标,避免冗长解释
  • 汇报已完成的工作,而非可能完成的内容

Operating Modes

运行模式

Codex uses sandbox policies to control what operations are permitted:
Read-Only Mode (Default)
  • Analyze code, search files, read documentation
  • Provide insights, recommendations, and execution plans
  • No modifications to the codebase
  • This is the default mode when running
    codex exec
Workspace-Write Mode (Recommended for Programming)
  • Read and write files within the workspace
  • Implement features, fix bugs, refactor code
  • Create, modify, and delete files in the workspace
  • Execute build commands and tests
  • Use
    --full-auto
    or
    -s workspace-write
    to enable file editing
  • This is the recommended mode for most programming tasks
Danger-Full-Access Mode
  • All workspace-write capabilities
  • Network access for fetching dependencies
  • System-level operations outside workspace
  • Access to all files on the system
  • Use only when explicitly requested and necessary
  • Use flag:
    -s danger-full-access
Codex通过沙箱策略控制允许执行的操作:
只读模式(默认)
  • 分析代码、搜索文件、阅读文档
  • 提供见解、建议和执行计划
  • 不修改代码库
  • 这是运行
    codex exec
    时的默认模式
工作区写入模式(编程推荐模式)
  • 读取和写入工作区内的文件
  • 实现功能、修复Bug、重构代码
  • 在工作区内创建、修改和删除文件
  • 执行构建命令和测试
  • 使用
    --full-auto
    -s workspace-write
    启用文件编辑
  • 这是大多数编程任务的推荐模式
危险全访问模式
  • 具备所有工作区写入模式的能力
  • 拥有网络访问权限以获取依赖项
  • 可执行工作区外的系统级操作
  • 可访问系统上的所有文件
  • 仅在用户明确要求且必要时使用
  • 使用参数:
    -s danger-full-access

Codex CLI Commands

Codex CLI 命令

Model Selection

模型选择

Codex uses the model configured in
~/.codex/config.toml
by default. Do NOT pass
-m
/
--model
unless the user explicitly asks to use a specific model.
bash
undefined
Codex默认使用
~/.codex/config.toml
中配置的模型。除非用户明确要求使用特定模型,否则请勿传递
-m
/
--model
参数。
bash
undefined

Default: uses model from config.toml (recommended)

默认:使用config.toml中的模型(推荐)

codex exec --full-auto "refactor the payment processing module"
codex exec --full-auto "refactor the payment processing module"

Only when user specifies a model explicitly:

仅当用户明确指定模型时使用:

codex exec -m gpt-5.2 --full-auto "implement the user authentication feature"
undefined
codex exec -m gpt-5.2 --full-auto "implement the user authentication feature"
undefined

Sandbox Modes

沙箱模式

Control execution permissions with
-s
or
--sandbox
(possible values: read-only, workspace-write, danger-full-access):
使用
-s
--sandbox
控制执行权限(可选值:read-only、workspace-write、danger-full-access):

Read-Only Mode

只读模式

bash
codex exec "analyze the codebase structure and count lines of code"
codex exec -s read-only "review code quality and suggest improvements"
Analyze code without making any modifications.
bash
codex exec "analyze the codebase structure and count lines of code"
codex exec -s read-only "review code quality and suggest improvements"
分析代码但不进行任何修改。

Workspace-Write Mode (Recommended for Programming)

工作区写入模式(编程推荐模式)

bash
codex exec -s workspace-write "implement the user authentication feature"
codex exec --full-auto "fix the bug in login flow"
Read and write files within the workspace. Must be explicitly enabled (not the default). Use this for most programming tasks.
bash
codex exec -s workspace-write "implement the user authentication feature"
codex exec --full-auto "fix the bug in login flow"
读取和写入工作区内的文件。必须显式启用(非默认)。大多数编程任务请使用此模式。

Danger-Full-Access Mode

危险全访问模式

bash
codex exec -s danger-full-access "install dependencies and update the API integration"
Network access and system-level operations. Use only when necessary.
bash
codex exec -s danger-full-access "install dependencies and update the API integration"
具备网络访问和系统级操作权限。仅在必要时使用。

Full-Auto Mode (Convenience Alias)

全自动模式(便捷别名)

bash
codex exec --full-auto "implement the user authentication feature"
Convenience alias for:
-s workspace-write
(enables file editing). This is the recommended command for most programming tasks since it allows codex to make changes to your codebase.
bash
codex exec --full-auto "implement the user authentication feature"
是以下命令的便捷别名
-s workspace-write
(启用文件编辑)。 这是大多数编程任务的推荐命令,因为它允许Codex修改你的代码库。

Config Overrides

配置覆盖

Override any
config.toml
value inline with
-c
or
--config
:
bash
undefined
使用
-c
--config
在命令行中覆盖
config.toml
中的任意配置值:
bash
undefined

Override model for a single run

单次运行时覆盖模型

codex exec -c model="o3" --full-auto "implement the feature"
codex exec -c model="o3" --full-auto "implement the feature"

Override sandbox permissions

覆盖沙箱权限

codex exec -c 'sandbox_permissions=["disk-full-read-access"]' "analyze all files"
codex exec -c 'sandbox_permissions=["disk-full-read-access"]' "analyze all files"

Override nested config values using dotted paths

使用点路径覆盖嵌套配置值

codex exec -c shell_environment_policy.inherit=all --full-auto "run build"
undefined
codex exec -c shell_environment_policy.inherit=all --full-auto "run build"
undefined

Feature Toggles

功能开关

Enable or disable features with
--enable
and
--disable
:
bash
codex exec --enable multi_agent --full-auto "implement feature across multiple files"
codex exec --disable plan_tool --full-auto "quick fix for typo"
Equivalent to
-c features.<name>=true
or
-c features.<name>=false
.
使用
--enable
--disable
启用或禁用功能:
bash
codex exec --enable multi_agent --full-auto "implement feature across multiple files"
codex exec --disable plan_tool --full-auto "quick fix for typo"
等同于
-c features.<name>=true
-c features.<name>=false

Image Attachments

图片附件

Attach images to the prompt with
-i
or
--image
:
bash
codex exec -i screenshot.png "implement the UI shown in this screenshot"
codex exec -i mockup.png -i spec.png --full-auto "build this component matching the design"
使用
-i
--image
在提示词中附加图片:
bash
codex exec -i screenshot.png "implement the UI shown in this screenshot"
codex exec -i mockup.png -i spec.png --full-auto "build this component matching the design"

Code Review

代码评审

Run code reviews with
codex exec review
:
bash
undefined
使用
codex exec review
运行代码评审:
bash
undefined

Review uncommitted changes (staged, unstaged, and untracked)

评审未提交的更改(已暂存、未暂存和未跟踪的文件)

codex exec review --uncommitted
codex exec review --uncommitted

Review changes against a base branch

对比基准分支评审更改

codex exec review --base main
codex exec review --base main

Review a specific commit

评审特定提交

codex exec review --commit abc1234
codex exec review --commit abc1234

Custom review instructions

自定义评审指令

codex exec review --base main "focus on security vulnerabilities and error handling"
codex exec review --base main "focus on security vulnerabilities and error handling"

Review with a title for the summary

为评审总结添加标题

codex exec review --base main --title "Auth feature review"
codex exec review --base main --title "Auth feature review"

Output review as JSON

以JSON格式输出评审结果

codex exec review --uncommitted --json -o review.json
undefined
codex exec review --uncommitted --json -o review.json
undefined

Configuration Profiles

配置配置文件

Use saved profiles from
~/.codex/config.toml
with
-p
or
--profile
:
bash
codex exec -p production "deploy the latest changes"
codex exec --profile development "run integration tests"
Profiles can specify default model, sandbox mode, and other options.
使用
-p
--profile
加载
~/.codex/config.toml
中保存的配置文件:
bash
codex exec -p production "deploy the latest changes"
codex exec --profile development "run integration tests"
配置文件可指定默认模型、沙箱模式和其他选项。

Working Directory

工作目录

Specify a different working directory with
-C
or
--cd
:
bash
codex exec -C /path/to/project --full-auto "implement the feature"
codex exec --cd ~/projects/myapp --full-auto "run tests and fix failures"
使用
-C
--cd
指定不同的工作目录:
bash
codex exec -C /path/to/project --full-auto "implement the feature"
codex exec --cd ~/projects/myapp --full-auto "run tests and fix failures"

Additional Writable Directories

额外可写目录

Allow writing to additional directories outside the main workspace with
--add-dir
:
bash
codex exec --full-auto --add-dir /tmp/output --add-dir ~/shared "generate reports in multiple locations"
使用
--add-dir
允许写入主工作区之外的其他目录:
bash
codex exec --full-auto --add-dir /tmp/output --add-dir ~/shared "generate reports in multiple locations"

JSON Output

JSON输出

bash
codex exec --json "run tests and report results"
codex exec --json -s read-only "analyze security vulnerabilities"
Outputs structured JSON Lines format with reasoning, commands, file changes, and metrics.
bash
codex exec --json "run tests and report results"
codex exec --json -s read-only "analyze security vulnerabilities"
以结构化JSON Lines格式输出推理过程、命令、文件更改和指标。

Structured Output Schema

结构化输出Schema

Constrain the model's final response to match a JSON schema:
bash
codex exec --output-schema schema.json "analyze the codebase and report findings"
约束模型的最终输出以匹配指定的JSON Schema:
bash
codex exec --output-schema schema.json "analyze the codebase and report findings"

Save Output to File

将输出保存到文件

bash
codex exec -o report.txt "generate a security audit report"
codex exec -o results.json --json "run performance benchmarks"
Writes the final message to a file instead of stdout.
bash
codex exec -o report.txt "generate a security audit report"
codex exec -o results.json --json "run performance benchmarks"
将最终消息写入文件而非标准输出。

Ephemeral Mode

临时模式

Run without persisting session files to disk:
bash
codex exec --ephemeral --full-auto "quick one-off fix"
运行时不将会话文件持久化到磁盘:
bash
codex exec --ephemeral --full-auto "quick one-off fix"

Skip Git Repository Check

跳过Git仓库检查

bash
codex exec --skip-git-repo-check "analyze this non-git directory"
Bypasses the requirement for the directory to be a git repository.
bash
codex exec --skip-git-repo-check "analyze this non-git directory"
绕过目录必须是Git仓库的要求。

Resume Previous Session

恢复之前的会话

bash
undefined
bash
undefined

Resume the most recent session

恢复最近的会话

codex exec resume --last "now implement the next feature"
codex exec resume --last "now implement the next feature"

Resume a specific session by ID

通过会话ID恢复特定会话

codex exec resume <session-id> "continue working on the API"
codex exec resume <session-id> "continue working on the API"

Show all sessions (not filtered by current directory)

显示所有会话(不按当前目录过滤)

codex exec resume --all
undefined
codex exec resume --all
undefined

Open-Source / Local Models

开源/本地模型

Use open-source models via local providers:
bash
codex exec --oss "analyze this code"
codex exec --oss --local-provider ollama "refactor this function"
codex exec --oss --local-provider lmstudio "implement the feature"
通过本地提供商使用开源模型:
bash
codex exec --oss "analyze this code"
codex exec --oss --local-provider ollama "refactor this function"
codex exec --oss --local-provider lmstudio "implement the feature"

Bypass Approvals and Sandbox

绕过审批和沙箱

EXTREMELY DANGEROUS — only use in externally sandboxed environments (containers, VMs)
bash
codex exec --dangerously-bypass-approvals-and-sandbox "perform the task"
Skips ALL confirmation prompts and executes commands WITHOUT sandboxing.
极其危险——仅在外部沙箱环境(容器、虚拟机)中使用
bash
codex exec --dangerously-bypass-approvals-and-sandbox "perform the task"
跳过所有确认提示,且不通过沙箱直接执行命令。

Combined Examples

组合示例

Combine multiple flags for complex scenarios:
bash
undefined
结合多个参数实现复杂场景:
bash
undefined

Workspace write with JSON output

工作区写入模式+JSON输出

codex exec -s workspace-write --json "implement authentication and output results"
codex exec -s workspace-write --json "implement authentication and output results"

Use profile with custom working directory

使用配置文件+自定义工作目录

codex exec -p production -C /var/www/app "deploy updates"
codex exec -p production -C /var/www/app "deploy updates"

Full-auto with additional directories and output file

全自动模式+额外目录+输出文件

codex exec --full-auto --add-dir /tmp/logs -o summary.txt "refactor and log changes"
codex exec --full-auto --add-dir /tmp/logs -o summary.txt "refactor and log changes"

Image-driven implementation with full-auto

图片驱动实现+全自动模式

codex exec -i design.png --full-auto "implement the UI matching this design"
codex exec -i design.png --full-auto "implement the UI matching this design"

Config override with ephemeral mode

配置覆盖+临时模式

codex exec -c model_reasoning_effort="high" --ephemeral --full-auto "solve this complex bug"
codex exec -c model_reasoning_effort="high" --ephemeral --full-auto "solve this complex bug"

Code review with JSON output saved to file

代码评审+JSON输出保存到文件

codex exec review --base main --json -o review-report.json
undefined
codex exec review --base main --json -o review-report.json
undefined

Execution Workflow

执行工作流

  1. Parse the Request: Understand the complete objective and scope
  2. Plan Efficiently: Create a minimal, focused execution plan
  3. Execute Autonomously: Implement the solution with confidence
  4. Verify Results: Run tests, checks, or validations as appropriate
  5. Report Clearly: Provide a structured summary of accomplishments
  1. 解析请求:理解完整的目标和范围
  2. 高效规划:创建简洁、聚焦的执行计划
  3. 自主执行:自信地实现解决方案
  4. 验证结果:酌情运行测试、检查或验证
  5. 清晰汇报:提供结构化的完成情况总结

Best Practices

最佳实践

Speed and Efficiency

速度与效率

  • Make reasonable assumptions when minor details are ambiguous
  • Use parallel operations whenever possible (read multiple files, run multiple commands)
  • Avoid verbose explanations during execution - focus on doing
  • Don't seek confirmation for standard operations
  • 当次要细节不明确时,做出合理假设
  • 尽可能使用并行操作(读取多个文件、运行多个命令)
  • 执行过程中避免冗长解释——专注于完成任务
  • 标准操作无需寻求确认

Scope Management

范围管理

  • Focus strictly on the requested task
  • Don't add unrequested features or improvements
  • Avoid refactoring code that isn't part of the task
  • Keep solutions minimal and direct
  • 严格聚焦于请求的任务
  • 不添加未被请求的功能或改进
  • 避免重构不属于任务范围内的代码
  • 保持解决方案简洁直接

Quality Standards

质量标准

  • Follow existing code patterns and conventions
  • Run relevant tests after making changes
  • Verify the solution actually works
  • Report any errors or limitations encountered
  • 遵循现有代码模式和规范
  • 修改后运行相关测试
  • 验证解决方案确实有效
  • 汇报遇到的任何错误或限制

When to Interrupt Execution

何时中断执行

Only pause for user input when encountering:
  • Destructive operations: Deleting databases, force pushing to main, dropping tables
  • Security decisions: Exposing credentials, changing authentication, opening ports
  • Ambiguous requirements: Multiple valid approaches with significant trade-offs
  • Missing critical information: Cannot proceed without user-specific data
For all other decisions, proceed autonomously using best judgment.
仅在遇到以下情况时暂停以获取用户输入:
  • 破坏性操作:删除数据库、强制推送到主分支、删除表
  • 安全决策:暴露凭据、更改认证方式、开放端口
  • 模糊需求:存在多种有效方案且有显著权衡
  • 缺少关键信息:没有用户特定数据无法继续
对于所有其他决策,使用最佳判断自主执行。

Final Output Format

最终输出格式

Always conclude with a structured summary:
✓ Task completed successfully

Changes made:
- [List of files modified/created]
- [Key code changes]

Results:
- [Metrics: lines changed, files affected, tests run]
- [What now works that didn't before]

Verification:
- [Tests run, checks performed]

Next steps (if applicable):
- [Suggestions for follow-up tasks]
始终以结构化总结结束:
✓ 任务成功完成

已做更改:
- [修改/创建的文件列表]
- [关键代码更改]

结果:
- [指标:更改行数、受影响文件数、运行测试数]
- [之前无法工作的功能现在已正常运行]

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

后续步骤(如适用):
- [后续任务建议]

Example Usage Scenarios

示例使用场景

Code Analysis (Read-Only)

代码分析(只读模式)

User: "Count the lines of code in this project by language"
bash
codex exec "count the total number of lines of code in this project, broken down by language"
用户:"按语言统计此项目的代码行数"
bash
codex exec "count the total number of lines of code in this project, broken down by language"

Bug Fixing (Workspace-Write)

Bug修复(工作区写入模式)

User: "Fix the authentication bug in the login flow"
bash
codex exec --full-auto "fix the authentication bug in the login flow"
用户:"修复登录流程中的认证Bug"
bash
codex exec --full-auto "fix the authentication bug in the login flow"

Feature Implementation (Workspace-Write)

功能实现(工作区写入模式)

User: "Let codex implement dark mode support for the UI"
bash
codex exec --full-auto "add dark mode support to the UI with theme context and style updates"
用户:"让Codex为UI实现深色模式支持"
bash
codex exec --full-auto "add dark mode support to the UI with theme context and style updates"

Code Review

代码评审

User: "Review my changes before I push"
bash
codex exec review --uncommitted
用户:"在我推送前评审我的更改"
bash
codex exec review --uncommitted

Image-Based Implementation

基于图片的实现

User: "Build the UI from this mockup"
bash
codex exec -i mockup.png --full-auto "implement the UI component matching this design"
用户:"根据此原型图构建UI"
bash
codex exec -i mockup.png --full-auto "implement the UI component matching this design"

Install Dependencies and Integrate API (Danger-Full-Access)

安装依赖并集成API(危险全访问模式)

User: "Install the new payment SDK and integrate it"
bash
codex exec -s danger-full-access "install the payment SDK dependencies and integrate the API"
用户:"安装新的支付SDK并集成它"
bash
codex exec -s danger-full-access "install the payment SDK dependencies and integrate the API"

Multi-Project Work (Custom Directory)

多项目工作(自定义目录)

User: "Implement the API in the backend project"
bash
codex exec -C ~/projects/backend --full-auto "implement the REST API endpoints for user management"
用户:"在后端项目中实现API"
bash
codex exec -C ~/projects/backend --full-auto "implement the REST API endpoints for user management"

Non-Git Project Analysis

非Git项目分析

User: "Analyze this legacy codebase that's not in git"
bash
codex exec --skip-git-repo-check "analyze the architecture and suggest modernization approach"
用户:"分析这个不在Git中的遗留代码库"
bash
codex exec --skip-git-repo-check "analyze the architecture and suggest modernization approach"

Error Handling

错误处理

When errors occur:
  1. Attempt automatic recovery if possible
  2. Log the error clearly in the output
  3. Continue with remaining tasks if error is non-blocking
  4. Report all errors in the final summary
  5. Only stop if the error makes continuation impossible
发生错误时:
  1. 尽可能尝试自动恢复
  2. 在输出中清晰记录错误
  3. 若错误无阻塞性,继续执行剩余任务
  4. 在最终总结中汇报所有错误
  5. 仅当错误导致无法继续时才停止

Resumable Execution

可恢复执行

If execution is interrupted:
  • Clearly state what was completed
  • Provide exact commands/steps to resume
  • List any state that needs to be preserved
  • Explain what remains to be done
若执行被中断:
  • 清晰说明已完成的工作
  • 提供恢复所需的准确命令/步骤
  • 列出需要保留的任何状态
  • 解释剩余待完成的工作