mcpField
C
codex-agent

codex-agent

github.com/majiayu000测试与质量28884 次安装今天更新
代码仓库

关于 codex-agent

供 Claude Code 与 OpenAI Codex CLI 协作的技能,涵盖代码审查、交叉验证、调试分析和替代实现建议。审查默认以只读方式进行,是否应用修改取决于用户请求或确认。

主要功能

  1. 01调用 Codex CLI 获取审查意见
  2. 02只读审查与结果写入报告
  3. 03按反馈检查并应用修复
  4. 04修复后可选再次验证
  5. 05提供安装、认证与故障排查指引

适用场景

  1. 01请 Codex 检查安全与代码质量
  2. 02交叉验证已完成的实现
  3. 03分析测试失败原因
  4. 04征求替代实现方案

安装

复制下面的命令,在终端中运行。

$npx skills add https://github.com/majiayu000/spellbook --skill codex-agent

安装后在 Claude Code 中输入/codex-agent确认已加载。

包含的文件

除 SKILL.md 外,安装时一起下载的参考资料和脚本。

advanced.md
examples.md
README.md
sandbox-modes.md
scripts/
check-codex.sh
codex-wrapper.sh

详细介绍

Codex Agent 协作技能

此技能使 Claude Code 能够与 OpenAI 的 Codex CLI Agent 协作,进行第二意见审查、交叉验证、调试分析和替代实现方案探讨。

默认做法:Codex 以 read-only 模式审查;只有在用户要求修复或阅读审查结果后批准时,主 Agent 才会应用更改。

可选的 Codex 审查工作流

当用户要求 Codex 审查、希望获得第二意见,或需要另一个编码 Agent 进行交叉验证时,请使用此工作流。

步骤 1:调用 Codex 并阅读反馈
REPORT="$(mktemp -t codex-review.XXXXXX.md)"
codex exec -C <project_path> -s read-only -o "$REPORT" \
  "Review the code in <file_or_directory>. Check for:
   - Security vulnerabilities
   - Performance issues
   - Code quality and best practices
   - Potential bugs and edge cases
   - Naming and readability
   Provide specific, actionable feedback with file paths and line numbers."

cat "$REPORT"

将写入和读取操作放在同一次 Bash 调用中,或者在多次调用之间传递一个明确的报告路径;shell 变量不会在工具调用之间持久保存。

步骤 2:根据 Codex 反馈应用修复

当用户要求应用修复时,处理 Codex 指出的每个问题:

  1. 阅读相关文件
  2. 使用 Edit 工具应用修复
  3. 验证修复是否解决了 Codex 提出的问题

如果用户只要求审查或第二意见,则报告发现的问题,不要编辑文件。

步骤 3:使用 Codex 重新验证(可选)
codex exec -C <project_path> -s read-only \
  "Verify the fixes applied to <files>. Confirm issues are resolved."

工作流示例

示例 1:审查并修复单个文件
# Step 1: Get Codex review
REPORT="$(mktemp -t codex-review.XXXXXX.md)"
codex exec -C /project -s read-only -o "$REPORT" \
  "Review src/auth/login.ts for security vulnerabilities and code quality issues. Provide specific line numbers and fixes."

# Step 2: Read the feedback
cat "$REPORT"

然后,主 Agent 阅读反馈,使用 Edit 工具应用修复,并可选择重新验证。

示例 2:审查近期更改
# Get diff of recent changes
DIFF_REPORT="$(mktemp -t recent-changes.XXXXXX.diff)"
git diff HEAD~1 > "$DIFF_REPORT"

# Step 1: Have Codex review the diff
REPORT="$(mktemp -t codex-review.XXXXXX.md)"
codex exec -C /project -s read-only -o "$REPORT" \
  "Review the changes saved at $DIFF_REPORT. Check for bugs, security issues, and improvements needed."

# Step 2: Read and apply fixes
cat "$REPORT"
示例 3:审查整个项目
# Step 1: Comprehensive review
REPORT="$(mktemp -t codex-review.XXXXXX.md)"
codex exec -C /project -s read-only -o "$REPORT" \
  "Perform a comprehensive code review of src/. Focus on:
   1. Security vulnerabilities (OWASP Top 10)
   2. Error handling patterns
   3. Performance bottlenecks
   4. Code duplication
   Prioritize issues by severity (critical/high/medium/low)."

# Step 2: Read prioritized feedback
cat "$REPORT"

审查请求格式

请求 Codex 审查时,请包含:

Review <target_files_or_directory>.

Context:
- Project type: <TypeScript/Python/etc>
- Framework: <Express/React/etc>
- Focus areas: <security/performance/quality>

Check for:
1. Security vulnerabilities
2. Performance issues
3. Error handling
4. Code quality
5. Edge cases

Output format:
For each issue:
- File: <path>
- Line: <number>
- Severity: critical/high/medium/low
- Issue: <description>
- Fix: <specific code change>

应用修复

收到 Codex 反馈后,系统地应用修复:

  1. 解析审查结果 - 提取每个问题及其文件、行号和严重性
  2. 确定优先级 - 优先修复严重和高优先级问题
  3. 阅读文件 - 使用 Read 工具查看当前代码
  4. 应用修复 - 使用 Edit 工具,精确指定 old_string/new_string
  5. 跟踪进度 - 将每个问题标记为已修复

先决条件

必须安装并完成身份验证的 Codex CLI:

# Install via npm
npm install -g @openai/codex

# Or via Homebrew (macOS)
brew install --cask codex

# Authenticate
codex login

命令参考

基本命令模式
codex exec [options] "<task_description>"
核心选项
选项说明
"<task>"任务描述(位置参数,必须加引号)
-C <dir>工作目录(使用绝对路径)
-s read-only只读沙盒(用于审查)
-o <path>将输出保存到文件
--json以 JSON Lines 格式输出
AI 之间的通信

与 Codex 通信时,优先确保准确性和精确性:

  • 使用结构化数据和准确的技术术语
  • 提供完整的文件路径和精确的细节
  • 包含当前代码库中的相关上下文
  • 无需使用对话式格式

其他用例

交叉验证(Claude 实现后)
codex exec -C /project -s read-only \
  "Verify the implementation in src/feature/. Check correctness and edge cases."
获取替代实现方案
REPORT="$(mktemp -t codex-alternative.XXXXXX.md)"
codex exec -C /project -s read-only -o "$REPORT" \
  "Propose an alternative implementation for the caching in src/cache/manager.ts"
cat "$REPORT"
调试协助
codex exec -C /project -s read-only \
  "Debug: tests in tests/auth.test.ts failing with timeout. Analyze root cause."

会话管理

对于多轮审查:

# Initial review
codex exec -C /project -s read-only "Review src/api/ for security issues"
# Note session ID from output

# Follow-up after fixes
codex exec resume <session_id> "I've applied the fixes. Please re-verify."

辅助脚本

  • scripts/check-codex.sh 检查是否已安装并完成身份验证的 Codex CLI。
  • scripts/codex-wrapper.sh 是可选脚本。仅在需要简易 CLI 封装时使用;它通过 shell 数组执行 Codex,且不得使用 eval。

注意事项

  • 不要将审查结果写入 /tmp/codex-review.md 等固定路径;请使用 mktemp 或项目专用的私有报告路径,以免并行项目相互覆盖,或读取过期反馈。
  • 除非用户明确要求 Codex 自行编辑,否则 Codex 审查命令应保持在 read-only 模式。
  • 将 danger-full-access、--dangerously-bypass-approvals-and-sandbox、--dangerously-bypass-hook-trust 和 --skip-git-repo-check 视为高影响标志。使用前请先征求同意。
  • 不要盲目应用 Codex 的所有建议。重新阅读目标文件,确认根本原因,并验证最终行为。

故障排除

身份验证问题
codex logout
codex login
检查安装情况
codex --version
which codex

另请参阅

评论

支持 Markdown