codex

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

Codex CLI Delegation

Codex CLI 委托工作流

Delegate specific complex development tasks to OpenAI's Codex CLI when the user explicitly requests Codex, especially for tasks requiring advanced code generation capabilities.
当用户明确要求使用Codex时,将特定的复杂开发任务委托给OpenAI的Codex CLI,尤其适用于需要高级代码生成能力的任务。

Overview

概述

This skill provides a safe and consistent workflow to:
  • convert the task request into English before execution
  • run
    codex exec
    or
    codex review
    in non-interactive mode for deterministic outputs
  • support model, sandbox, approval, and execution options
  • return formatted results to the user for decision-making
This skill complements existing capabilities by delegating complex programming tasks to Codex when requested, leveraging OpenAI's GPT-5.3-codex models for advanced code generation and analysis.
本技能提供安全且一致的工作流,可用于:
  • 执行前将任务请求转换为英文
  • 以非交互模式运行
    codex exec
    codex review
    ,确保输出结果可复现
  • 支持模型选择、沙箱模式、审批机制及执行选项配置
  • 向用户返回格式化结果,辅助决策
本技能可补充现有能力,在用户请求时将复杂编程任务委托给Codex,借助OpenAI的GPT-5.3-codex模型实现高级代码生成与分析。

When to Use

适用场景

Use this skill when:
  • the user explicitly asks to use Codex for a task
  • the task benefits from advanced code generation (complex refactoring, architectural design, API design)
  • the task requires deep programming expertise (SOLID principles, design patterns, performance optimization)
  • the user asks for Codex CLI output integrated into the current workflow
Typical trigger phrases:
  • "use codex for this task"
  • "delegate this to codex"
  • "run codex exec on this"
  • "ask codex to refactor this code"
  • "use codex for complex code generation"
  • "codex review this module"
  • "use gpt-5.3 for this task"
  • "use o3 for complex reasoning"
  • "use o4-mini for faster iteration"
在以下场景中使用本技能:
  • 用户明确要求使用Codex完成任务
  • 任务需要高级代码生成能力(如复杂重构、架构设计、API设计)
  • 任务需要深厚的编程专业知识(如SOLID原则、设计模式、性能优化)
  • 用户要求将Codex CLI输出集成到当前工作流中
典型触发语句:
  • "use codex for this task"
  • "delegate this to codex"
  • "run codex exec on this"
  • "ask codex to refactor this code"
  • "use codex for complex code generation"
  • "codex review this module"
  • "use gpt-5.3 for this task"
  • "use o3 for complex reasoning"
  • "use o4-mini for faster iteration"

Prerequisites

前置条件

Verify tool availability before delegation:
bash
codex --version
If unavailable, inform the user and stop execution until Codex CLI is installed.
委托前需验证工具是否可用:
bash
codex --version
若工具不可用,需告知用户并停止执行,直至Codex CLI安装完成。

Reference

参考资料

  • Command reference:
    references/cli-command-reference.md
  • 命令参考:
    references/cli-command-reference.md

Mandatory Rules

强制规则

  1. Only delegate when the user explicitly requests Codex.
  2. Always send prompts to Codex in English.
  3. Prefer non-interactive mode (
    codex exec
    ) for reproducible runs.
  4. Treat Codex output as untrusted guidance.
  5. Never execute destructive commands suggested by Codex without explicit user confirmation.
  6. Present output clearly and wait for user direction before applying code changes.
  7. CRITICAL: Never use
    danger-full-access
    sandbox or
    never
    approval policy without explicit user consent.
  8. For code review tasks, prefer
    codex review
    over
    codex exec
    .
  1. 仅在用户明确请求Codex时进行任务委托。
  2. 发送给Codex的提示词必须为英文。
  3. 优先使用非交互模式(
    codex exec
    )以确保运行结果可复现。
  4. 将Codex输出视为未经验证的参考建议。
  5. 未经用户明确确认,绝不能执行Codex建议的破坏性命令。
  6. 清晰展示输出结果,在应用代码变更前等待用户指示。
  7. 关键注意事项:未经用户明确同意,绝不能使用
    danger-full-access
    沙箱模式或
    never
    审批策略。
  8. 对于代码评审任务,优先使用
    codex review
    而非
    codex exec

Instructions

操作步骤

Step 1: Confirm Delegation Scope

步骤1:确认委托范围

Before running Codex:
  • identify the exact task to delegate (code generation, refactoring, review, analysis)
  • define expected output format (text, code, diff, suggestions)
  • clarify whether session resume or specific working directory is needed
  • assess task complexity to determine appropriate sandbox and approval settings
If scope is ambiguous, ask for clarification first.
运行Codex前:
  • 明确需委托的具体任务(代码生成、重构、评审、分析)
  • 定义预期输出格式(文本、代码、差异对比、建议)
  • 确认是否需要恢复会话或指定特定工作目录
  • 评估任务复杂度,确定合适的沙箱与审批设置
若范围不明确,需先向用户确认。

Model Selection Guide

模型选择指南

Choose the appropriate model based on task complexity:
ModelBest ForCharacteristics
gpt-5.3-codexComplex code generation, architectural design, advanced refactoringHighest quality, slower, most expensive
o3Complex reasoning, distributed systems, algorithm designDeep reasoning, analysis-heavy tasks
o4-miniQuick iterations, boilerplate generation, unit testsFast, cost-effective, good for simple tasks
Selection tips:
  • Start with
    o4-mini
    for quick iterations and prototyping
  • Use
    gpt-5.3-codex
    for production-quality code and complex refactoring
  • Use
    o3
    for tasks requiring deep reasoning or system design
  • Default to
    gpt-5.3-codex
    if uncertain (highest quality)
根据任务复杂度选择合适的模型:
模型最佳适用场景特性
gpt-5.3-codex复杂代码生成、架构设计、高级重构输出质量最高,速度较慢,成本较高
o3复杂推理、分布式系统、算法设计深度推理能力强,适用于分析型任务
o4-mini快速迭代、样板代码生成、单元测试速度快,成本低,适用于简单任务
选择技巧
  • 快速迭代与原型开发时优先使用
    o4-mini
  • 生产级代码与复杂重构使用
    gpt-5.3-codex
  • 深度推理或系统设计任务使用
    o3
  • 若不确定,默认选择
    gpt-5.3-codex
    (输出质量最高)

Step 2: Formulate Prompt in English

步骤2:构建英文提示词

Build a precise English prompt from the user request.
Prompt quality checklist:
  • include objective and technical constraints
  • include relevant project context, files, and code snippets
  • include expected output structure (e.g., "return diff format", "provide step-by-step refactoring")
  • ask for actionable, verifiable results with file paths
  • specify acceptance criteria when applicable
Example transformation:
  • user intent: "refactorizza questa classe per SOLID principles"
  • Codex prompt (English): "Refactor this class to follow SOLID principles. Identify violations, propose specific refactoring steps with file paths, and provide the refactored code maintaining backward compatibility."
根据用户请求构建精准的英文提示词。
提示词质量检查清单:
  • 包含任务目标与技术约束
  • 包含相关项目上下文、文件及代码片段
  • 包含预期输出结构(如“返回差异对比格式”、“提供分步重构方案”)
  • 要求提供可执行、可验证的结果,并附带文件路径
  • 必要时明确验收标准
示例转换:
  • 用户需求:"refactorizza questa classe per SOLID principles"
  • Codex提示词(英文):"Refactor this class to follow SOLID principles. Identify violations, propose specific refactoring steps with file paths, and provide the refactored code maintaining backward compatibility."

Step 3: Select Execution Mode and Flags

步骤3:选择执行模式与参数

For Code Generation/Development Tasks

代码生成/开发任务

Preferred baseline command:
bash
codex exec "<english-prompt>"
Supported options:
  • -m, --model <model-id>
    for model selection (e.g.,
    gpt-5.3-codex
    ,
    o4-mini
    ,
    o3
    )
  • -a, --ask-for-approval <policy>
    for approval policy:
    • untrusted
      : Only run trusted commands without approval
    • on-request
      : Model decides when to ask (recommended for development)
    • never
      : Never ask for approval (use with caution)
  • -s, --sandbox <mode>
    for sandbox policy:
    • read-only
      : No writes, no network (safest for analysis)
    • workspace-write
      : Allow writes in workspace, no network (default for development)
    • danger-full-access
      : Disable sandbox (⚠️ extremely dangerous)
  • -C, --cd <DIR>
    to set working directory
  • -i, --image <FILE>
    for multimodal input (repeatable)
  • --search
    to enable live web search
  • --full-auto
    as convenience alias for
    -a on-request -s workspace-write
Safety guidance:
  • prefer
    read-only
    sandbox for analysis-only tasks
  • use
    workspace-write
    sandbox for code generation/refactoring
  • prefer
    on-request
    approval for development tasks
  • use
    never
    approval only with explicit user consent for automated tasks
  • NEVER use
    danger-full-access
    without explicit user approval and external sandboxing
  • For multi-turn conversations, consider using
    codex resume --last
    to continue from previous sessions
推荐基准命令:
bash
codex exec "<english-prompt>"
支持的选项:
  • -m, --model <model-id>
    :用于选择模型(如
    gpt-5.3-codex
    o4-mini
    o3
  • -a, --ask-for-approval <policy>
    :设置审批策略:
    • untrusted
      :仅运行受信任命令,无需审批
    • on-request
      :由模型决定何时请求审批(开发场景推荐)
    • never
      :从不请求审批(谨慎使用)
  • -s, --sandbox <mode>
    :设置沙箱策略:
    • read-only
      :禁止写入与网络访问(分析任务最安全)
    • workspace-write
      :允许在工作目录内写入,禁止网络访问(开发场景默认)
    • danger-full-access
      :禁用沙箱(⚠️ 极度危险)
  • -C, --cd <DIR>
    :设置工作目录
  • -i, --image <FILE>
    :支持多模态输入(可重复使用)
  • --search
    :启用实时网页搜索
  • --full-auto
    :便捷别名,等效于
    -a on-request -s workspace-write
安全指南:
  • 纯分析任务优先使用
    read-only
    沙箱
  • 代码生成/重构任务使用
    workspace-write
    沙箱
  • 开发任务优先使用
    on-request
    审批策略
  • 仅在用户明确同意的自动化任务中使用
    never
    审批策略
  • 绝不能在未获得用户明确批准且无外部沙箱(如容器、虚拟机)的情况下使用
    danger-full-access
  • 多轮对话场景下,可考虑使用
    codex resume --last
    从之前的会话继续

For Code Review Tasks

代码评审任务

Use the dedicated review command:
bash
codex review "<english-prompt>"
The review command includes optimizations for code analysis and supports the same flags as
codex exec
.
使用专用的评审命令:
bash
codex review "<english-prompt>"
评审命令针对代码分析进行了优化,支持与
codex exec
相同的参数。

Step 4: Execute Codex CLI

步骤4:执行Codex CLI

Run the selected command via Bash and capture stdout/stderr.
Examples:
bash
undefined
通过Bash运行选定的命令,并捕获标准输出与错误输出。
示例:
bash
undefined

Default non-interactive delegation

默认非交互委托

codex exec "Refactor this authentication module to use JWT with proper error handling"
codex exec "Refactor this authentication module to use JWT with proper error handling"

Explicit model and safe settings

明确指定模型与安全设置

codex exec "Review this codebase for security vulnerabilities. Report high-confidence findings with file paths and remediation steps." -m gpt-5.3-codex -a on-request -s read-only
codex exec "Review this codebase for security vulnerabilities. Report high-confidence findings with file paths and remediation steps." -m gpt-5.3-codex -a on-request -s read-only

Code review with workspace write

支持工作目录写入的代码评审

codex review "Analyze this pull request for potential bugs, performance issues, and code quality concerns. Provide specific line references." -a on-request -s workspace-write
codex review "Analyze this pull request for potential bugs, performance issues, and code quality concerns. Provide specific line references." -a on-request -s workspace-write

Complex refactoring with working directory

指定工作目录的复杂重构

codex exec -C ./src "Refactor these service classes to use dependency injection. Maintain all existing interfaces." -a on-request -s workspace-write
codex exec -C ./src "Refactor these service classes to use dependency injection. Maintain all existing interfaces." -a on-request -s workspace-write

With web search for latest best practices

启用网页搜索以获取最新最佳实践

codex exec --search "Implement OAuth2 authorization code flow using the latest security best practices and modern libraries"
codex exec --search "Implement OAuth2 authorization code flow using the latest security best practices and modern libraries"

Multimodal analysis

多模态分析

codex exec -i screenshot.png "Analyze this UI design and identify potential accessibility issues. Suggest specific improvements with code examples."
codex exec -i screenshot.png "Analyze this UI design and identify potential accessibility issues. Suggest specific improvements with code examples."

Full automation (use with caution)

全自动化执行(谨慎使用)

codex exec --full-auto "Generate unit tests for all service methods with >80% coverage"
undefined
codex exec --full-auto "Generate unit tests for all service methods with >80% coverage"
undefined

Step 5: Return Results Safely

步骤5:安全返回结果

When reporting Codex output:
  • summarize key findings, generated code, and confidence level
  • keep raw output available when needed for detailed review
  • separate observations from recommended actions
  • explicitly ask user confirmation before applying suggested edits
  • highlight any security implications or breaking changes
返回Codex输出时:
  • 总结关键发现、生成的代码及置信度
  • 保留原始输出,以便需要时进行详细评审
  • 将观察结果与建议操作分开呈现
  • 在应用建议的代码变更前,明确请求用户确认
  • 突出显示任何安全隐患或破坏性变更

Output Template

输出模板

Use this structure when returning delegated results:
markdown
undefined
返回委托结果时使用以下结构:
markdown
undefined

Codex Delegation Result

Codex 委托结果

Task

任务

[delegated task summary]
[委托任务摘要]

Command

执行命令

codex exec ...
codex exec ...

Key Findings

关键发现

  • Finding 1
  • Finding 2
  • 发现1
  • 发现2

Generated Code/Changes

生成代码/变更建议

[summary of code generated or changes proposed]
[生成代码或变更建议摘要]

Suggested Next Actions

建议下一步操作

  1. Action 1
  2. Action 2
  1. 操作1
  2. 操作2

Notes

说明

  • Output language from Codex: English
  • Sandbox mode: [mode used]
  • Requires user approval before applying code changes
undefined
  • Codex输出语言:英文
  • 沙箱模式:[使用的模式]
  • 应用代码变更前需用户批准
undefined

Examples

示例

Example 1: Complex refactoring for SOLID principles

示例1:遵循SOLID原则的复杂重构

bash
codex exec "Refactor this OrderService class to follow SOLID principles. Current issues: 1) Single Responsibility violated (handles validation, processing, notification), 2) Open/Closed violated (hard-coded payment providers), 3) Dependency Inversion violated (concrete dependencies). Provide: 1) Proposed class structure, 2) Step-by-step migration plan, 3) Refactored code maintaining backward compatibility." -m gpt-5.3-codex -a on-request -s workspace-write
bash
codex exec "Refactor this OrderService class to follow SOLID principles. Current issues: 1) Single Responsibility violated (handles validation, processing, notification), 2) Open/Closed violated (hard-coded payment providers), 3) Dependency Inversion violated (concrete dependencies). Provide: 1) Proposed class structure, 2) Step-by-step migration plan, 3) Refactored code maintaining backward compatibility." -m gpt-5.3-codex -a on-request -s workspace-write

Example 2: Security vulnerability analysis

示例2:安全漏洞分析

bash
codex exec "Perform a comprehensive security analysis of this authentication module. Focus on: SQL injection, XSS, CSRF, authentication bypass, session management, and password handling. For each vulnerability found, provide: severity level, CWE identifier, exploit scenario, and concrete remediation with code examples." -a on-request -s read-only
bash
codex exec "Perform a comprehensive security analysis of this authentication module. Focus on: SQL injection, XSS, CSRF, authentication bypass, session management, and password handling. For each vulnerability found, provide: severity level, CWE identifier, exploit scenario, and concrete remediation with code examples." -a on-request -s read-only

Example 3: API design and implementation

示例3:API设计与实现

bash
codex exec --search "Design and implement a RESTful API for user management following REST best practices. Include: endpoint design, request/response schemas with validation, error handling, authentication middleware, pagination, filtering, and HATEOAS links. Use the latest industry standards and provide OpenAPI 3.0 specification."
bash
codex exec --search "Design and implement a RESTful API for user management following REST best practices. Include: endpoint design, request/response schemas with validation, error handling, authentication middleware, pagination, filtering, and HATEOAS links. Use the latest industry standards and provide OpenAPI 3.0 specification."

Example 4: Performance optimization

示例4:性能优化

bash
codex exec "Analyze this database query module for performance bottlenecks. Identify: N+1 queries, missing indexes, inefficient joins, and caching opportunities. Provide: 1) Performance analysis with metrics, 2) Specific optimization recommendations, 3) Refactored code with query optimizations, 4) Migration script for database changes."
bash
codex exec "Analyze this database query module for performance bottlenecks. Identify: N+1 queries, missing indexes, inefficient joins, and caching opportunities. Provide: 1) Performance analysis with metrics, 2) Specific optimization recommendations, 3) Refactored code with query optimizations, 4) Migration script for database changes."

Example 5: Code review of pull request

示例5:拉取请求代码评审

bash
codex review "Review this pull request for: 1) Correctness and logic errors, 2) Performance issues, 3) Security vulnerabilities, 4) Code quality and maintainability, 5) Test coverage gaps, 6) Documentation completeness. Provide specific line references and actionable feedback." -a on-request -s read-only
bash
codex review "Review this pull request for: 1) Correctness and logic errors, 2) Performance issues, 3) Security vulnerabilities, 4) Code quality and maintainability, 5) Test coverage gaps, 6) Documentation completeness. Provide specific line references and actionable feedback." -a on-request -s read-only

Example 6: Multimodal UI analysis

示例6:多模态UI分析

bash
codex exec -i design-mockup.png -i current-implementation.png "Compare the design mockup with the current implementation. Identify: layout differences, missing components, styling inconsistencies, and accessibility issues. Provide: 1) Gap analysis, 2) Specific CSS/HTML changes needed, 3) Priority ranking of fixes."
bash
codex exec -i design-mockup.png -i current-implementation.png "Compare the design mockup with the current implementation. Identify: layout differences, missing components, styling inconsistencies, and accessibility issues. Provide: 1) Gap analysis, 2) Specific CSS/HTML changes needed, 3) Priority ranking of fixes."

Best Practices

最佳实践

  • Prompt engineering: Include specific acceptance criteria and constraints in prompts
  • Sandbox selection: Use
    read-only
    for analysis,
    workspace-write
    for development
  • Model selection: Use
    gpt-5.3-codex
    for complex tasks,
    o4-mini
    for faster iterations
  • Incremental delegation: Run multiple focused delegations instead of one vague prompt
  • Code review: Prefer
    codex review
    for review tasks over
    codex exec
  • Verification: Always review generated code before applying
  • Web search: Enable
    --search
    for tasks requiring latest best practices or library versions
  • Multimodal: Use
    -i
    for UI/UX analysis, diagram understanding, or visual debugging
  • 提示词工程:在提示词中包含明确的验收标准与约束
  • 沙箱选择:分析任务使用
    read-only
    ,开发任务使用
    workspace-write
  • 模型选择:复杂任务用
    gpt-5.3-codex
    ,快速迭代用
    o4-mini
  • 增量委托:将大型任务拆分为多个聚焦的子任务进行委托
  • 代码评审:优先使用
    codex review
    而非
    codex exec
    完成评审任务
  • 结果验证:应用生成的代码前务必进行审核
  • 网页搜索:需要最新最佳实践或库版本时启用
    --search
  • 多模态支持:UI/UX分析、图表理解或可视化调试时使用
    -i
    参数

Constraints and Warnings

约束与警告

  • Sandbox safety:
    danger-full-access
    mode removes ALL security restrictions and should NEVER be used without external sandboxing (e.g., containers, VMs)
  • Approval policies:
    never
    policy can execute destructive commands without confirmation
  • Output quality: Codex output may contain bugs, security vulnerabilities, or inefficient code
  • Context limits: Very large tasks may exceed model context; break into smaller sub-tasks
  • Network access: Sandbox modes (except
    danger-full-access
    ) block network access by default
  • Dependencies: Codex CLI behavior depends on local environment and configuration
  • Model availability: Model access depends on OpenAI account and API entitlements
  • Language requirement: All prompts sent to Codex must be in English for optimal results
  • This skill is for delegation, not autonomous code modification without user confirmation
  • 沙箱安全
    danger-full-access
    模式会移除所有安全限制,绝不能在无外部沙箱(如容器、虚拟机)的情况下使用
  • 审批策略
    never
    策略可能在无确认的情况下执行破坏性命令
  • 输出质量:Codex输出可能包含Bug、安全漏洞或低效代码
  • 上下文限制:超大型任务可能超出模型上下文窗口,需拆分为更小的子任务
  • 网络访问:默认情况下,除
    danger-full-access
    外的沙箱模式均禁止网络访问
  • 依赖环境:Codex CLI的行为依赖本地环境与配置
  • 模型可用性:模型访问权限取决于OpenAI账户与API授权
  • 语言要求:所有发送给Codex的提示词必须为英文,以获得最佳结果
  • 本技能仅用于任务委托,未经用户确认不得自主修改代码