CodexCLI集成技能 codex-cli

Codex CLI 集成技能允许 Claude 使用 OpenAI 的 Codex CLI 和 gpt-5.3-codex 模型进行代码生成、审查、分析和自动编辑。支持复杂代码任务的 AI 辅助、多文件重构、自动化代码生成、代码实现的第二意见审查、并行代码任务处理和基于会话的迭代开发。

后端开发 0 次安装 0 次浏览 更新于 3/4/2026

版本:2.89.0

name: codex-cli description: "OpenAI Codex CLI 为 AI 辅助开发提供编排,使用 gpt-5.3-codex 模型家族。模型变体:gpt-5.3-codex(中等),gpt-5.3-codex-high,gpt-5.3-codex-xhigh。能力:代码生成、重构、自动编辑、并行任务执行、会话管理、代码审查、架构分析和 MCP 集成。动作:使用 Codex 进行分析、实现、审查、修复和重构。关键词:Codex CLI,gpt-5.3-codex,codex exec,代码生成,重构,并行执行,会话恢复,代码审查,第二意见,独立审查,架构验证,Context7 MCP。使用场景:将复杂代码任务委托给 Codex,运行多代理工作流,执行自动化审查,使用 AI 辅助实现功能,恢复先前的会话,查询 OpenAI 文档。触发词:‘使用 codex’,‘codex exec’,‘与 codex 一起运行’,‘codex 恢复’,‘使用 codex 实现’,‘使用 codex 审查’,‘codex 文档’。

Codex CLI 集成技能(v2.37)

v2.89 主要变更(GPT-5.3-CODEX 家族)

  • 模型家族gpt-5.3-codex,包含三个推理层级
  • 推理层级:中等(默认),高,xhigh(最大)
  • 配置文件:为每个推理级别预配置的配置文件
  • 向后兼容:仍然支持通过 -m 标志覆盖模型

推理层级选择

层级 模型 用例 命令
medium gpt-5.3-codex 默认,快速代码任务 codex exec "prompt"
high gpt-5.3-codex-high 复杂分析,安全 codex exec --profile high "prompt"
xhigh gpt-5.3-codex-xhigh 架构,关键审查 codex exec --profile xhigh "prompt"

ultrathink - 深呼吸。我们不是来写代码的。我们是来在宇宙中留下印记的。

愿景

Codex 编排应该感觉不可避免:最小化风险,最大化清晰度。

你的工作,一步一步

  1. 选择策略:模型、沙盒和推理努力。
  2. 准备上下文:注入最小、最精确的提示。
  3. 执行:用清晰的约束运行 Codex。
  4. 验证输出:检查正确性和范围合规性。
  5. 总结:报告发现和后续步骤。

Ultrathink 原则在实践中

  • 不同思考:选择通往洞察的最安全路径。
  • 对细节着迷:尊重沙盒边界。
  • 像达芬奇一样计划:在执行前塑造提示。
  • 打造,不编码:保持命令精确。
  • 无情迭代:用精炼的提示重新运行。
  • 无情简化:减少噪音和范围。

Codex CLI 集成技能(v2.37)

这项技能使得 Claude 能够使用 OpenAI 的 Codex CLI(v0.79+)和 gpt-5.3-codex 模型进行代码生成、审查、分析和自动编辑。包括 Context7 MCP 集成以访问文档。

何时使用这项技能

理想用例

  • 需要深度理解的复杂代码分析
  • 跨多个文件的大规模重构
  • 带有安全控制的自动代码生成
  • 第二意见/跨验证代码实现
  • 并行处理独立的代码任务
  • 基于会话的迭代开发工作流

快速开始

先决条件

验证 Codex CLI 安装:

codex --version  # 应显示 v0.50.0+

认证(首次):

codex  # 通过 ChatGPT 账户进行交互式登录
# 或:export CODEX_API_KEY=sk-...

模型选择(v2.89)

模型家族gpt-5.3-codex 与推理层级

模型 推理 用例
gpt-5.3-codex 中等 默认,快速代码任务(推荐)
gpt-5.3-codex-high 复杂分析,安全审查
gpt-5.3-codex-xhigh xhigh 架构设计,关键决策
o3 - 最高推理能力
o4-mini - 快速,简单任务

按层级使用

# 中等(默认) - 快速迭代
codex exec "refactor authentication module"

# 高 - 复杂分析
codex exec -m gpt-5.3-codex-high "security audit of payment flow"

# XHigh - 架构决策
codex exec -m gpt-5.3-codex-xhigh "design microservices architecture"

沙盒模式

模式 权限 用例
read-only 只读文件(默认) 分析,审查
workspace-write 读写工作区 代码编辑,重构
danger-full-access 全系统访问 安装依赖,网络

核心命令

基本执行

# 只读分析(默认)
codex exec -m gpt-5.3-codex "analyze src/auth for security issues"

# 代码编辑(workspace-write)
codex exec -m gpt-5.3-codex --full-auto "fix bug in login.py"

# 带推理努力
codex exec -m gpt-5.3-codex --config model_reasoning_effort=high "complex analysis"

# 跳过 git 检查(非 git 目录)
codex exec --skip-git-repo-check "analyze code"

抑制思考标记

添加 2>/dev/null 以抑制 stderr(思考标记):

codex exec -m gpt-5.3-codex "review code" 2>/dev/null

会话恢复

# 恢复上一次会话(stdin 提示 - 由于 CLI 错误需要)
echo "continue with fixes" | codex exec resume --last 2>/dev/null

# 恢复并全自动化
echo "apply fixes" | codex exec resume --last --full-auto 2>/dev/null

# 恢复特定会话
echo "follow-up" | codex exec resume SESSION_ID

重要:恢复继承原始会话的模型、推理和沙盒。

JSON 输出

# JSON 行输出
codex exec --json -m gpt-5.3-codex "analyze code" > output.jsonl

# 提取会话 ID
SID=$(grep -o '"thread_id":"[^"]*"' output.jsonl | head -1 | cut -d'"' -f4)

# 提取代理消息
grep '"type":"agent_message"' output.jsonl | jq -r '.item.text'

编排模式

模式 1:上下文预注入

Claude 首先收集信息,注入提示以加快执行速度:

# 收集错误
ERRORS=$(npm run lint 2>&1 | grep error)

# 注入上下文
codex exec -m gpt-5.3-codex --full-auto "Fix these errors:
$ERRORS

Files: src/auth/login.ts, src/utils/token.ts
Constraint: Only modify listed files."

模式 2:会话重用

相关任务重用会话以保留上下文:

# 首先:分析
codex exec -m gpt-5.3-codex "analyze src/auth for issues"

# 继续:修复(重用上下文)
echo "fix the issues you found" | codex exec resume --last --full-auto

何时重用:

  • 分析 → 修复(知道发现的问题)
  • 实现 → 测试(知道实现)
  • 测试 → 修复(知道失败)

模式 3:并行执行

独立任务同时运行:

# 并行分析
codex exec --json -m gpt-5.3-codex "analyze auth" > auth.jsonl 2>&1 &
codex exec --json -m gpt-5.3-codex "analyze api" > api.jsonl 2>&1 &
wait

# 并行修复并恢复
AUTH_SID=$(grep -o '"thread_id":"[^"]*"' auth.jsonl | head -1 | cut -d'"' -f4)
echo "fix issues" | codex exec resume $AUTH_SID --full-auto &
# ...
wait

可并行化:

  • 不同目录/模块
  • 不同分析维度(安全/性能/质量)
  • 只读操作

必须序列化:

  • 写入相同文件
  • 依赖先前结果

交互式工作流

在运行 Codex 任务之前,与用户确认:

  1. 模型选择gpt-5.3-codexgpt-5.2
  2. 推理努力lowmedium,或 high
  3. 沙盒模式:根据任务要求

决策矩阵

任务类型 沙盒 标志
审查/分析 read-only --sandbox read-only 2>/dev/null
应用本地编辑 workspace-write --full-auto 2>/dev/null
网络/依赖 danger-full-access --sandbox danger-full-access --full-auto
恢复会话 继承 echo "prompt" | codex exec resume --last

代码审查工作流

独立审查

使用 Codex 作为 Claude 工作的第二意见:

codex exec -m gpt-5.3-codex --sandbox read-only "Review src/payment/processor.py for:
1. Race conditions in transaction processing
2. Proper error handling and rollback
3. Security issues with payment data
4. Edge cases that could cause data loss
Provide specific line numbers and severity ratings."

全面审查

# 安全审计
codex exec -m gpt-5.3-codex --sandbox read-only --config model_reasoning_effort=high \
  "Perform security audit of src/auth. Check for:
  - Authentication/authorization issues
  - Input validation vulnerabilities
  - Cryptographic weaknesses
  - Sensitive data exposure"

# 性能审查
codex exec -m gpt-5.3-codex --sandbox read-only \
  "Analyze src/database for performance:
  - N+1 query problems
  - Missing indexes
  - Blocking operations"

拉取请求审查

codex exec -m gpt-5.3-codex --sandbox read-only \
  "Run 'git diff main...HEAD' to see changes.
  Review for:
  1. Breaking changes
  2. Performance implications
  3. Test coverage
  4. Security concerns
  Provide feedback by file with severity levels."

提示设计

结构公式

[动词] + [范围] + [要求] + [输出格式] + [约束]

动词选择

只读
analyze, review, find, explain fix, refactor, implement, add

示例

坏与好:

# 坏:模糊
codex exec "review code"

# 好:具体
codex exec -m gpt-5.3-codex --sandbox read-only \
  "Review src/auth for SQL injection, XSS.
  Output: markdown with severity levels.
  Format: file:line, description, fix suggestion."

并行提示一致性

# 聚合一致的结构
FORMAT="Output JSON: {category, items: [{file, line, description}]}"

codex exec -m gpt-5.3-codex "review security. $FORMAT" &
codex exec -m gpt-5.3-codex "review performance. $FORMAT" &
codex exec -m gpt-5.3-codex "review quality. $FORMAT" &
wait

Claude-Codex 工程循环

双 AI 工作流

  1. Claude 计划 → 架构,需求
  2. Codex 验证计划 → 检查逻辑,边缘情况
  3. Claude 实施 → 使用工具编写代码
  4. Codex 审查 → 错误检测,安全
  5. Claude 修复 → 应用更正
  6. Codex 重新验证 → 确认质量
  7. 重复 直到满足标准

实施

# 第 2 阶段:Codex 验证 Claude 的计划
echo "Review this implementation plan for issues:
[Claude's plan here]

Check for:
- Logic errors
- Missing edge cases
- Architecture flaws
- Security concerns" | codex exec -m gpt-5.3-codex --sandbox read-only

# 第 4 阶段:Codex 审查 Claude 的代码
codex exec -m gpt-5.3-codex --sandbox read-only \
  "Review implementation in src/feature for:
  - Bugs
  - Performance issues
  - Best practices
  - Security vulnerabilities"

错误处理

  1. 非零退出:停止并报告,询问方向
  2. 警告:总结并询问如何处理
  3. 高影响标志:在 --full-auto--sandbox danger-full-access 之前请求权限

任务后跟进

每次 Codex 命令后:

  1. 总结结果
  2. 与用户确认后续步骤
  3. 提供:“恢复会话以 ‘codex resume’ 继续分析”

配置

配置文件设置(~/.codex/config.toml)

model = "gpt-5.3-codex"
model_reasoning_effort = "medium"

# 推理层级配置文件
[profiles.medium]
model = "gpt-5.3-codex"
model_reasoning_effort = "medium"

[profiles.high]
model = "gpt-5.3-codex-high"
model_reasoning_effort = "high"

[profiles.xhigh]
model = "gpt-5.3-codex-xhigh"
model_reasoning_effort = "high"

# 任务特定配置文件
[profiles.review]
model = "gpt-5.3-codex-high"
model_reasoning_effort = "high"
sandbox_mode = "read-only"

[profiles.implement]
model = "gpt-5.3-codex"
model_reasoning_effort = "medium"
sandbox_mode = "workspace-write"

[profiles.architect]
model = "gpt-5.3-codex-xhigh"
model_reasoning_effort = "high"
sandbox_mode = "read-only"

用法:

# 使用推理层级配置文件
codex exec --profile medium "quick fix"
codex exec --profile high "security audit"
codex exec --profile xhigh "architecture review"

# 使用任务特定配置文件
codex exec --profile review "analyze code"
codex exec --profile implement "add feature"
codex exec --profile architect "design system"

快速参考

用例 命令
中等(默认) codex exec "prompt" 2>/dev/null
高推理 codex exec -m gpt-5.3-codex-high "prompt" 2>/dev/null
XHigh 推理 codex exec -m gpt-5.3-codex-xhigh "prompt" 2>/dev/null
编辑文件 codex exec --full-auto "prompt" 2>/dev/null
高努力 --config model_reasoning_effort=high
恢复上一个 echo "prompt" | codex exec resume --last
JSON 输出 codex exec --json "prompt" > out.jsonl
特定目录 codex exec -C /path "prompt"
非 git 目录 --skip-git-repo-check
配置文件:中等 codex exec --profile medium "prompt"
配置文件:高 codex exec --profile high "prompt"
配置文件:xhigh codex exec --profile xhigh "prompt"
配置文件:审查 codex exec --profile review "prompt"
配置文件:架构师 codex exec --profile architect "prompt"

文档访问通过 Context7 MCP

Claude 和 Codex 都配置了 Context7 MCP。使用它来访问 OpenAI 文档:

可用文档库

库 ID 内容 片段
/websites/developers_openai_codex Codex CLI 文档 614
/websites/platform_openai OpenAI API 文档 9,418
/openai/openai-python Python SDK 429
/openai/openai-node Node.js SDK 437

执行前查询文档

# 在运行复杂的 Codex 命令之前,验证语法
mcp__context7__query-docs:
  libraryId: "/websites/developers_openai_codex"
  query: "exec sandbox modes full-auto workspace-write"

# 出错时,查找解决方案
mcp__context7__query-docs:
  libraryId: "/websites/developers_openai_codex"
  query: "error troubleshooting session resume"

MCP 服务器配置参考

# ~/.codex/config.toml - Codex MCP 配置

# STDIO 服务器(本地命令)
[mcp_servers.context7]
command = "npx"
args = ["-y", "@upstash/context7-mcp@latest"]

# 远程 HTTP 服务器
[mcp_servers.remote]
url = "https://example.com/mcp"
bearer_token_env_var = "API_TOKEN"

# 带环境变量
[mcp_servers.server.env]
API_KEY = "value"

验证 MCP 服务器

# 列出配置的 MCP 服务器
codex mcp list

# 添加新 MCP 服务器
codex mcp add context7 -- npx -y @upstash/context7-mcp

# 测试 MCP 服务器
npx @modelcontextprotocol/inspector codex mcp-server

另见

  • /openai-docs - OpenAI 文档访问技能
  • references/cli_reference.md - 完整的 CLI 参数
  • references/prompt_patterns.md - 高级提示设计
  • references/parallel_execution.md - 并行编排细节