code-review by alinaqi/claude-bootstrap
npx skills add https://github.com/alinaqi/claude-bootstrap --skill code-review加载方式:base.md + [codex-review.md 用于 OpenAI Codex] + [gemini-review.md 用于 Google Gemini]
目的: 在每次提交和部署前强制执行自动化代码审查,作为强制性的防护措施。可选择 Claude、OpenAI Codex、Google Gemini 或多种引擎进行综合分析。
运行 /code-review 时,用户可以选择他们偏好的审查引擎:
┌─────────────────────────────────────────────────────────────────┐
│ 代码审查 - 选择您的引擎 │
├─────────────────────────────────────────────────────────────────┤
│ │
│ ○ Claude (默认) │
│ 内置,无需额外设置,完整的对话上下文 │
│ │
│ ○ OpenAI Codex CLI │
│ 专为代码审查优化的 GPT-5.2-Codex,检测率 88% │
│ 要求:npm install -g @openai/codex │
│ │
│ ○ Google Gemini CLI │
│ Gemini 2.5 Pro 支持 1M token 上下文,提供免费层级 │
│ 要求:npm install -g @google/gemini-cli │
│ │
│ ○ 双引擎 (任意两个) │
│ 运行两个引擎,比较发现的问题,捕获更多问题 │
│ │
│ ○ 三引擎 (最大覆盖) │
│ 运行 Claude + Codex + Gemini 用于关键/安全代码 │
│ │
└─────────────────────────────────────────────────────────────────┘
广告位招租
在这里展示您的产品或服务
触达数万 AI 开发者,精准高效
| 方面 | Claude | Codex | Gemini | 多引擎 |
|---|---|---|---|---|
| 设置 | 无 | npm + OpenAI API | npm + Google 账户 | 所有设置 |
| 速度 | 快 | 快 | 快 | 2-3 倍时间 |
| 上下文 | 对话 | 每次审查全新 | 1M tokens | 不适用 |
| 检测率 | 良好 | 88% (最佳) | 63.8% SWE-Bench | 综合 |
| 免费层级 | 不适用 | 有限 | 1,000/天 | 视情况而定 |
| 最适合 | 快速审查 | 高精度 | 大型代码库 | 关键代码 |
# ~/.claude/settings.toml 或项目 CLAUDE.md
[code-review]
default_engine = "claude" # 选项:claude, codex, gemini, dual, all
# 使用默认引擎
/code-review
# 明确选择引擎
/code-review --engine claude
/code-review --engine codex
/code-review --engine gemini
# 双引擎 (选择任意两个)
/code-review --engine claude,codex
/code-review --engine claude,gemini
/code-review --engine codex,gemini
# 三引擎
/code-review --engine all
# 快捷方式
/code-review # 使用默认
/code-review --codex # 使用 Codex
/code-review --gemini # 使用 Gemini
/code-review --all # 三引擎
使用多个引擎时,发现的问题会进行比较和去重:
┌─────────────────────────────────────────────────────────────────┐
│ 代码审查结果 - 双引擎 (Claude + Codex) │
├─────────────────────────────────────────────────────────────────┤
│ │
│ ✅ 一致 (双方均发现): │
│ 🔴 auth.ts:45 处的 SQL 注入 │
│ 🟡 api.ts:112 处缺少错误处理 │
│ │
│ 🔷 仅 CLAUDE 发现: │
│ 🟠 worker.ts:89 处潜在的竞态条件 │
│ 🟢 考虑提取辅助函数 │
│ │
│ 🔶 仅 CODEX 发现: │
│ 🟠 upload.ts:34 处内存泄漏 - 未关闭的流 │
│ 🟡 orders.ts:156 处的 N+1 查询模式 │
│ │
├─────────────────────────────────────────────────────────────────┤
│ 摘要 │
│ 一致:2 | 仅 Claude:2 | 仅 Codex:2 │
│ 关键:1 | 高:2 | 中:2 | 低:1 │
│ 状态:❌ 已阻止 - 修复关键/高优先级问题 │
└─────────────────────────────────────────────────────────────────┘
┌─────────────────────────────────────────────────────────────────┐
│ 代码审查结果 - 三引擎 │
├─────────────────────────────────────────────────────────────────┤
│ │
│ ✅ 一致 (全部 3 个发现): │
│ 🔴 auth.ts:45 处的 SQL 注入 │
│ │
│ ✅ 多数 (3 个中的 2 个发现): │
│ 🟠 upload.ts:34 处内存泄漏 - 未关闭的流 (Codex+Gemini) │
│ 🟡 api.ts:112 处缺少错误处理 (Claude+Codex) │
│ │
│ 🔷 仅 CLAUDE 发现: │
│ 🟠 worker.ts:89 处潜在的竞态条件 │
│ │
│ 🔶 仅 CODEX 发现: │
│ 🟡 orders.ts:156 处的 N+1 查询模式 │
│ │
│ 🟢 仅 GEMINI 发现: │
│ 🟡 考虑使用批处理 API 以获得更好的性能 │
│ 🟢 types.ts:23 处的类型可以更具体 │
│ │
├─────────────────────────────────────────────────────────────────┤
│ 摘要 │
│ 一致:1 | 多数:2 | 单个:5 │
│ 关键:1 | 高:2 | 中:3 | 低:2 │
│ 状态:❌ 已阻止 - 修复关键/高优先级问题 │
└─────────────────────────────────────────────────────────────────┘
| 模式 | 使用场景 |
|---|---|
| 单引擎 (Claude) | 流程中的快速审查、探索 |
| 单引擎 (Codex) | CI/CD 自动化、需要高精度 |
| 单引擎 (Gemini) | 大型代码库 (100+ 文件)、免费层级 |
| 双引擎 | 重要的 PR、合并前审查 |
| 三引擎 (全部) | 安全关键代码、支付系统、认证 |
┌─────────────────────────────────────────────────────────────────┐
│ 代码审查是不可协商的 │
│ ───────────────────────────────────────────────────────────── │
│ │
│ 每次提交都必须通过代码审查。 │
│ 每个 PR 在合并前都必须经过审查。 │
│ 每次部署都必须包含审查签署。 │
│ │
│ AI 捕获人类遗漏的问题。人类捕获 AI 遗漏的问题。 │
│ 共同作用:更少的 bug、更干净的代码、更好的安全性。 │
├─────────────────────────────────────────────────────────────────┤
│ 调用:/code-review │
│ 插件:code-review@claude-plugins-official │
└─────────────────────────────────────────────────────────────────┘
| 触发点 | 操作 | 命令 |
|---|---|---|
| 提交前 | 审查暂存的更改 | /code-review |
| PR 前 | 审查所有相对于基线的更改 | /code-review |
| 合并前 | 对 PR 进行最终审查 | /code-review |
| 部署前 | 审查部署差异 | /code-review |
在每次提交前自动运行代码审查:
┌─────────────────────────────────────────────────────────────────┐
│ 提交工作流程 │
│ ───────────────────────────────────────────────────────────── │
│ │
│ 1. 编写代码 │
│ 2. 运行测试 (TDD - 必须通过) │
│ 3. 运行 /code-review ← 强制步骤 │
│ 4. 解决关键/高优先级问题 │
│ 5. 提交 │
│ 6. 推送 │
│ │
│ 跳过第 3 步? ❌ 不允许提交 │
└─────────────────────────────────────────────────────────────────┘
# 审查当前更改
/code-review
# 审查特定文件
/code-review src/auth/*.ts
# 审查 PR
/code-review --pr 123
# 审查特定关注点
/code-review --focus security
/code-review --focus performance
/code-review --focus architecture
代码审查插件分析以下类别:
| 类别 | 检查内容 |
|---|---|
| 安全性 | 漏洞、注入风险、认证问题、密钥 |
| 性能 | N+1 查询、内存泄漏、低效算法 |
| 架构 | 设计模式、SOLID 原则、耦合度 |
| 代码质量 | 可读性、复杂度、重复 |
| 最佳实践 | 语言习惯用法、框架约定 |
| 测试 | 覆盖率缺口、测试质量、边界情况 |
| 文档 | 缺少文档、过时注释 |
| 级别 | 所需操作 | 能否提交? |
|---|---|---|
| 🔴 关键 | 必须立即修复 | ❌ 否 |
| 🟠 高 | 应在提交前修复 | ❌ 否 |
| 🟡 中 | 尽快修复,可以提交 | ✅ 是 |
| 🟢 低 | 建议修复 | ✅ 是 |
| ℹ️ 信息 | 仅建议 | ✅ 是 |
#!/bin/bash
# .git/hooks/pre-commit
echo "🔍 正在运行代码审查..."
# 对暂存文件运行 Claude 代码审查
STAGED_FILES=$(git diff --cached --name-only --diff-filter=ACM | grep -E '\.(ts|tsx|js|jsx|py|go|rs)$')
if [ -n "$STAGED_FILES" ]; then
# 调用代码审查 (需要 claude CLI)
claude --print "/code-review $STAGED_FILES" > /tmp/code-review-result.txt 2>&1
# 检查关键/高优先级问题
if grep -q "🔴\|Critical\|🟠\|High" /tmp/code-review-result.txt; then
echo "❌ 代码审查发现关键/高优先级问题:"
cat /tmp/code-review-result.txt
echo ""
echo "请在提交前修复这些问题。"
exit 1
fi
echo "✅ 代码审查通过"
fi
exit 0
chmod +x .git/hooks/pre-commit
如果您想使用 Codex 或双引擎模式,请安装 Codex CLI:
# 先决条件:Node.js 22+
node --version # 必须是 22+
# 安装 Codex CLI
npm install -g @openai/codex
# 认证 (选择一种):
# 选项 1:ChatGPT 订阅 (Plus, Pro, Team, Enterprise)
codex # 按照提示登录
# 选项 2:API 密钥
export OPENAI_API_KEY=sk-proj-...
# 检查 Codex 是否已安装
codex --version
# 测试审查
codex
> /review
完整的 Codex 文档请参见 codex-review.md 技能。
如果您想使用 Gemini 或多引擎模式,请安装 Gemini CLI:
# 先决条件:Node.js 20+
node --version # 必须是 20+
# 安装 Gemini CLI
npm install -g @google/gemini-cli
# 或通过 Homebrew (macOS)
brew install gemini-cli
# 安装代码审查扩展
gemini extensions install https://github.com/gemini-cli-extensions/code-review
# 选项 1:Google 账户 (推荐,每天 1000 次免费请求)
gemini # 按照浏览器登录提示操作
# 选项 2:API 密钥 (每天 100 次免费请求)
export GEMINI_API_KEY="your-key-from-aistudio.google.com"
# 检查 Gemini 是否已安装
gemini --version
# 列出扩展
gemini extensions list
# 测试审查
gemini
> /code-review
完整的 Gemini 文档请参见 gemini-review.md 技能。
# .github/workflows/code-review.yml
name: 代码审查
on:
pull_request:
types: [opened, synchronize, reopened]
jobs:
code-review:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- name: 获取更改的文件
id: changed-files
run: |
echo "files=$(git diff --name-only origin/${{ github.base_ref }}...HEAD | tr '\n' ' ')" >> $GITHUB_OUTPUT
- name: 运行 Claude 代码审查
env:
ANTHROPIC_API_KEY: ${{ secrets.ANTHROPIC_API_KEY }}
run: |
npx @anthropic-ai/claude-code --print "/code-review ${{ steps.changed-files.outputs.files }}" > review.md
- name: 发布审查评论
uses: actions/github-script@v7
with:
script: |
const fs = require('fs');
const review = fs.readFileSync('review.md', 'utf8');
github.rest.issues.createComment({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: context.issue.number,
body: `## 🔍 Claude 代码审查\n\n${review}`
});
- name: 检查关键问题
run: |
if grep -q "Critical\|🔴" review.md; then
echo "❌ 发现关键问题"
exit 1
fi
# .github/workflows/codex-review.yml
name: Codex 代码审查
on:
pull_request:
jobs:
review:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Codex 审查
uses: openai/codex-action@main
with:
openai_api_key: ${{ secrets.OPENAI_API_KEY }}
model: gpt-5.2-codex
safety_strategy: drop-sudo
# .github/workflows/dual-review.yml
name: 双引擎代码审查
on:
pull_request:
jobs:
claude-review:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Claude 审查
env:
ANTHROPIC_API_KEY: ${{ secrets.ANTHROPIC_API_KEY }}
run: |
npx @anthropic-ai/claude-code --print "/code-review" > claude-review.md
- uses: actions/upload-artifact@v4
with:
name: claude-review
path: claude-review.md
codex-review:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- uses: actions/setup-node@v4
with:
node-version: '22'
- name: 安装 Codex
run: npm install -g @openai/codex
- name: Codex 审查
env:
OPENAI_API_KEY: ${{ secrets.OPENAI_API_KEY }}
run: |
codex exec --full-auto --sandbox read-only \
--output-last-message codex-review.md \
"Review this code for bugs, security issues, and quality problems"
- uses: actions/upload-artifact@v4
with:
name: codex-review
path: codex-review.md
combine-reviews:
needs: [claude-review, codex-review]
runs-on: ubuntu-latest
steps:
- uses: actions/download-artifact@v4
- name: 合并审查结果
run: |
echo "## 🔍 双引擎代码审查结果" > combined-review.md
echo "" >> combined-review.md
echo "### Claude 发现" >> combined-review.md
cat claude-review/claude-review.md >> combined-review.md
echo "" >> combined-review.md
echo "### Codex 发现" >> combined-review.md
cat codex-review/codex-review.md >> combined-review.md
- name: 发布合并的审查结果
uses: actions/github-script@v7
with:
script: |
const fs = require('fs');
const review = fs.readFileSync('combined-review.md', 'utf8');
github.rest.issues.createComment({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: context.issue.number,
body: review
});
# .github/workflows/gemini-review.yml
name: Gemini 代码审查
on:
pull_request:
types: [opened, synchronize]
jobs:
review:
runs-on: ubuntu-latest
permissions:
contents: read
pull-requests: write
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- name: 设置 Node.js
uses: actions/setup-node@v4
with:
node-version: '20'
- name: 安装 Gemini CLI
run: npm install -g @google/gemini-cli
- name: 运行审查
env:
GEMINI_API_KEY: ${{ secrets.GEMINI_API_KEY }}
run: |
# 获取差异
git diff origin/${{ github.base_ref }}...HEAD > diff.txt
# 运行 Gemini 审查
gemini -p "Review this pull request diff for bugs, security issues, and code quality problems. Be specific about file names and line numbers.
$(cat diff.txt)" > review.md
- name: 发布审查评论
uses: actions/github-script@v7
with:
script: |
const fs = require('fs');
const review = fs.readFileSync('review.md', 'utf8');
github.rest.issues.createComment({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: context.issue.number,
body: `## 🤖 Gemini 代码审查\n\n${review}`
});
- name: 检查关键问题
run: |
if grep -qi "critical\|security vulnerability\|injection" review.md; then
echo "❌ 发现关键问题"
exit 1
fi
# .github/workflows/triple-review.yml
name: 三引擎代码审查
on:
pull_request:
jobs:
claude-review:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Claude 审查
env:
ANTHROPIC_API_KEY: ${{ secrets.ANTHROPIC_API_KEY }}
run: |
npx @anthropic-ai/claude-code --print "/code-review" > claude-review.md
- uses: actions/upload-artifact@v4
with:
name: claude-review
path: claude-review.md
codex-review:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- uses: actions/setup-node@v4
with:
node-version: '22'
- name: 安装 Codex
run: npm install -g @openai/codex
- name: Codex 审查
env:
OPENAI_API_KEY: ${{ secrets.OPENAI_API_KEY }}
run: |
codex exec --full-auto --sandbox read-only \
--output-last-message codex-review.md \
"Review this code for bugs, security issues, and quality problems"
- uses: actions/upload-artifact@v4
with:
name: codex-review
path: codex-review.md
gemini-review:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- uses: actions/setup-node@v4
with:
node-version: '20'
- name: 安装 Gemini CLI
run: npm install -g @google/gemini-cli
- name: Gemini 审查
env:
GEMINI_API_KEY: ${{ secrets.GEMINI_API_KEY }}
run: |
git diff origin/${{ github.base_ref }}...HEAD > diff.txt
gemini -p "Review this code diff for bugs, security, and quality issues:
$(cat diff.txt)" > gemini-review.md
- uses: actions/upload-artifact@v4
with:
name: gemini-review
path: gemini-review.md
combine-reviews:
needs: [claude-review, codex-review, gemini-review]
runs-on: ubuntu-latest
steps:
- uses: actions/download-artifact@v4
- name: 合并审查结果
run: |
echo "## 🔍 三引擎代码审查结果" > combined-review.md
echo "" >> combined-review.md
echo "### 🟣 Claude 发现" >> combined-review.md
cat claude-review/claude-review.md >> combined-review.md
echo "" >> combined-review.md
echo "---" >> combined-review.md
echo "### 🟢 Codex 发现" >> combined-review.md
cat codex-review/codex-review.md >> combined-review.md
echo "" >> combined-review.md
echo "---" >> combined-review.md
echo "### 🔵 Gemini 发现" >> combined-review.md
cat gemini-review/gemini-review.md >> combined-review.md
- name: 发布合并的审查结果
uses: actions/github-script@v7
with:
script: |
const fs = require('fs');
const review = fs.readFileSync('combined-review.md', 'utf8');
github.rest.issues.createComment({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: context.issue.number,
body: review
});
- name: 检查关键问题
run: |
# 如果任何引擎发现关键问题,则失败
if grep -qi "critical\|🔴" combined-review.md; then
echo "❌ 至少一个引擎发现关键问题"
exit 1
fi
/code-review| 问题 | 示例 | 修复方法 |
|---|---|---|
| SQL 注入 | query = f"SELECT * FROM users WHERE id = {id}" | 使用参数化查询 |
| XSS | innerHTML = userInput | 清理或使用 textContent |
| 代码中的密钥 | apiKey = "sk-xxx" | 使用环境变量 |
| 缺少认证 | 未受保护的端点 | 添加认证中间件 |
| 不安全的加密 | 使用 MD5/SHA1 存储密码 | 使用 bcrypt/argon2 |
| 问题 | 示例 | 修复方法 |
|---|---|---|
| N+1 查询 | 循环中的单个查询 | 使用批处理/预加载 |
| 内存泄漏 | 未关闭的连接 | 使用连接池 |
| 缺少索引 | 慢查询 | 添加数据库索引 |
| 大负载 | 获取未使用的字段 | 仅选择需要的字段 |
| 无分页 | 加载所有记录 | 实现分页 |
| 问题 | 示例 | 修复方法 |
|---|---|---|
| 长函数 | 100+ 行 | 提取为更小的函数 |
| 深层嵌套 | 5+ 层 | 提前返回,提取方法 |
| 魔法数字 | if (status === 3) | 使用命名常量 |
| 重复代码 | 复制粘贴的代码块 | 提取共享函数 |
| 缺少类型 | 到处使用 any | 添加正确的 TypeScript 类型 |
┌─────────────────────────────────────────────────────────────────┐
│ TDD + 代码审查工作流 │
│ ───────────────────────────────────────────────────────────── │
│ │
│ 1. 红:编写失败的测试 │
│ 2. 绿:编写代码使测试通过 │
│ 3. 重构:清理代码 │
│ 4. 审查:运行 /code-review ← 新增步骤 │
│ 5. 修复:解决关键/高优先级问题 │
│ 6. 验证:Lint + 类型检查 + 覆盖率 │
│ 7. 提交:仅在审查通过后 │
│ │
│ 审查捕获测试遗漏的问题: │
│ - 安全漏洞 │
│ - 性能问题 │
│ - 架构问题 │
│ - 代码可维护性 │
└─────────────────────────────────────────────────────────────────┘
当代码审查发现问题时,使用以下模板响应:
## 代码审查结果
### 🔴 关键问题 (必须修复)
1. **userController.ts:45 处的 SQL 注入**
- 问题:用户输入直接插入到查询中
- 修复:使用参数化查询
- 代码:`db.query('SELECT * FROM users WHERE id = $1', [userId])`
### 🟠 高优先级问题 (应该修复)
1. **/api/admin 端点缺少认证**
- 问题:管理员路由无需认证即可访问
- 修复:添加认证中间件
### 🟡 中优先级问题 (尽快修复)
1. **getOrders 函数中的 N+1 查询**
- 考虑预加载或批处理查询
### 🟢 低优先级问题 (建议修复)
1. **考虑将验证逻辑提取到单独的文件**
### ✅ 优点
- 良好的测试覆盖率
- 清晰的函数命名
- 适当的错误处理
### 📊 摘要
- 关键:1 | 高:1 | 中:1 | 低:1
- **状态:❌ 已阻止** - 在提交前修复关键/高优先级问题
Claude 应自动建议或运行代码审查:
根据更改类型优先审查:
| 更改类型 | 关注领域 |
|---|---|
| 认证/安全代码 | 安全性、输入验证、加密 |
| 数据库代码 | SQL 注入、N+1、事务 |
| API 端点 | 认证、速率限制、验证 |
| 前端代码 | XSS、状态管理、性能 |
| 基础设施 | 密钥、权限、日志记录 |
# 基本审查
/code-review
# 审查特定文件
/code-review src/auth.ts src/users.ts
# 审查特定关注点
/code-review --focus security
# 审查 PR
/code-review --pr 123
🔴 关键 → 停止。立即修复。不能提交。
🟠 高 → 停止。立即修复。不能提交。
🟡 中 → 记录。尽快修复。可以提交。
🟢 低 → 可选。建议修复。
ℹ️ 信息 → 仅作参考。
代码 → 测试 → 审查 → 修复 → 提交 → 推送 → PR → 审查 → 合并 → 部署
↑ ↑ ↑
/code-review /code-review /code-review
每周安装次数
95
仓库
GitHub 星标数
529
首次出现
2026年1月20日
安全审计
安装于
opencode76
claude-code75
gemini-cli73
codex68
cursor68
github-copilot61
Load with: base.md + [codex-review.md for OpenAI Codex] + [gemini-review.md for Google Gemini]
Purpose: Enforce automated code reviews as a mandatory guardrail before every commit and deployment. Choose between Claude, OpenAI Codex, Google Gemini, or multiple engines for comprehensive analysis.
When running /code-review, users can choose their preferred review engine:
┌─────────────────────────────────────────────────────────────────┐
│ CODE REVIEW - Choose Your Engine │
├─────────────────────────────────────────────────────────────────┤
│ │
│ ○ Claude (default) │
│ Built-in, no extra setup, full conversation context │
│ │
│ ○ OpenAI Codex CLI │
│ GPT-5.2-Codex specialized for code review, 88% detection │
│ Requires: npm install -g @openai/codex │
│ │
│ ○ Google Gemini CLI │
│ Gemini 2.5 Pro with 1M token context, free tier available │
│ Requires: npm install -g @google/gemini-cli │
│ │
│ ○ Dual Engine (any two) │
│ Run two engines, compare findings, catch more issues │
│ │
│ ○ All Three (maximum coverage) │
│ Run Claude + Codex + Gemini for critical/security code │
│ │
└─────────────────────────────────────────────────────────────────┘
| Aspect | Claude | Codex | Gemini | Multi-Engine |
|---|---|---|---|---|
| Setup | None | npm + OpenAI API | npm + Google Account | All setups |
| Speed | Fast | Fast | Fast | 2-3x time |
| Context | Conversation | Fresh per review | 1M tokens | N/A |
| Detection | Good | 88% (best) | 63.8% SWE-Bench | Combined |
| Free Tier | N/A | Limited | 1,000/day | Varies |
# ~/.claude/settings.toml or project CLAUDE.md
[code-review]
default_engine = "claude" # Options: claude, codex, gemini, dual, all
# Use default engine
/code-review
# Explicitly choose engine
/code-review --engine claude
/code-review --engine codex
/code-review --engine gemini
# Dual engine (pick any two)
/code-review --engine claude,codex
/code-review --engine claude,gemini
/code-review --engine codex,gemini
# All three engines
/code-review --engine all
# Quick shortcuts
/code-review # Uses default
/code-review --codex # Use Codex
/code-review --gemini # Use Gemini
/code-review --all # All three engines
When using multiple engines, findings are compared and deduplicated:
┌─────────────────────────────────────────────────────────────────┐
│ CODE REVIEW RESULTS - DUAL ENGINE (Claude + Codex) │
├─────────────────────────────────────────────────────────────────┤
│ │
│ ✅ AGREED (Found by both): │
│ 🔴 SQL injection in auth.ts:45 │
│ 🟡 Missing error handling in api.ts:112 │
│ │
│ 🔷 CLAUDE ONLY: │
│ 🟠 Potential race condition in worker.ts:89 │
│ 🟢 Consider extracting helper function │
│ │
│ 🔶 CODEX ONLY: │
│ 🟠 Memory leak - unclosed stream in upload.ts:34 │
│ 🟡 N+1 query pattern in orders.ts:156 │
│ │
├─────────────────────────────────────────────────────────────────┤
│ SUMMARY │
│ Agreed: 2 | Claude only: 2 | Codex only: 2 │
│ Critical: 1 | High: 2 | Medium: 2 | Low: 1 │
│ Status: ❌ BLOCKED - Fix critical/high issues │
└─────────────────────────────────────────────────────────────────┘
┌─────────────────────────────────────────────────────────────────┐
│ CODE REVIEW RESULTS - TRIPLE ENGINE │
├─────────────────────────────────────────────────────────────────┤
│ │
│ ✅ UNANIMOUS (All 3 found): │
│ 🔴 SQL injection in auth.ts:45 │
│ │
│ ✅ MAJORITY (2 of 3 found): │
│ 🟠 Memory leak - unclosed stream in upload.ts:34 (Codex+Gemini)│
│ 🟡 Missing error handling in api.ts:112 (Claude+Codex) │
│ │
│ 🔷 CLAUDE ONLY: │
│ 🟠 Potential race condition in worker.ts:89 │
│ │
│ 🔶 CODEX ONLY: │
│ 🟡 N+1 query pattern in orders.ts:156 │
│ │
│ 🟢 GEMINI ONLY: │
│ 🟡 Consider using batch API for better performance │
│ 🟢 Type could be more specific in types.ts:23 │
│ │
├─────────────────────────────────────────────────────────────────┤
│ SUMMARY │
│ Unanimous: 1 | Majority: 2 | Single: 5 │
│ Critical: 1 | High: 2 | Medium: 3 | Low: 2 │
│ Status: ❌ BLOCKED - Fix critical/high issues │
└─────────────────────────────────────────────────────────────────┘
| Mode | Use When |
|---|---|
| Single (Claude) | Quick in-flow reviews, exploration |
| Single (Codex) | CI/CD automation, high accuracy needed |
| Single (Gemini) | Large codebases (100+ files), free tier |
| Dual | Important PRs, pre-merge reviews |
| Triple (All) | Security-critical code, payment systems, auth |
┌─────────────────────────────────────────────────────────────────┐
│ CODE REVIEW IS NON-NEGOTIABLE │
│ ───────────────────────────────────────────────────────────── │
│ │
│ Every commit must pass code review. │
│ Every PR must be reviewed before merge. │
│ Every deployment must include review sign-off. │
│ │
│ AI catches what humans miss. Humans catch what AI misses. │
│ Together: fewer bugs, cleaner code, better security. │
├─────────────────────────────────────────────────────────────────┤
│ INVOKE: /code-review │
│ PLUGIN: code-review@claude-plugins-official │
└─────────────────────────────────────────────────────────────────┘
| Trigger | Action | Command |
|---|---|---|
| Before commit | Review staged changes | /code-review |
| Before PR | Review all changes vs base | /code-review |
| Before merge | Final review of PR | /code-review |
| Before deploy | Review deployment diff | /code-review |
Run code review automatically before every commit:
┌─────────────────────────────────────────────────────────────────┐
│ COMMIT WORKFLOW │
│ ───────────────────────────────────────────────────────────── │
│ │
│ 1. Write code │
│ 2. Run tests (TDD - must pass) │
│ 3. Run /code-review ← MANDATORY │
│ 4. Address critical/high issues │
│ 5. Commit │
│ 6. Push │
│ │
│ Skip step 3? ❌ NO COMMIT ALLOWED │
└─────────────────────────────────────────────────────────────────┘
# Review current changes
/code-review
# Review specific files
/code-review src/auth/*.ts
# Review a PR
/code-review --pr 123
# Review with specific focus
/code-review --focus security
/code-review --focus performance
/code-review --focus architecture
The code review plugin analyzes:
| Category | What It Checks |
|---|---|
| Security | Vulnerabilities, injection risks, auth issues, secrets |
| Performance | N+1 queries, memory leaks, inefficient algorithms |
| Architecture | Design patterns, SOLID principles, coupling |
| Code Quality | Readability, complexity, duplication |
| Best Practices | Language idioms, framework conventions |
| Testing | Coverage gaps, test quality, edge cases |
| Documentation | Missing docs, outdated comments |
| Level | Action Required | Can Commit? |
|---|---|---|
| 🔴 Critical | Must fix immediately | ❌ NO |
| 🟠 High | Should fix before commit | ❌ NO |
| 🟡 Medium | Fix soon, can commit | ✅ YES |
| 🟢 Low | Nice to have | ✅ YES |
| ℹ️ Info | Suggestions only | ✅ YES |
#!/bin/bash
# .git/hooks/pre-commit
echo "🔍 Running code review..."
# Run Claude code review on staged files
STAGED_FILES=$(git diff --cached --name-only --diff-filter=ACM | grep -E '\.(ts|tsx|js|jsx|py|go|rs)$')
if [ -n "$STAGED_FILES" ]; then
# Invoke code review (requires claude CLI)
claude --print "/code-review $STAGED_FILES" > /tmp/code-review-result.txt 2>&1
# Check for critical/high issues
if grep -q "🔴\|Critical\|🟠\|High" /tmp/code-review-result.txt; then
echo "❌ Code review found critical/high issues:"
cat /tmp/code-review-result.txt
echo ""
echo "Fix these issues before committing."
exit 1
fi
echo "✅ Code review passed"
fi
exit 0
chmod +x .git/hooks/pre-commit
If you want to use Codex or Both modes, install the Codex CLI:
# Prerequisites: Node.js 22+
node --version # Must be 22+
# Install Codex CLI
npm install -g @openai/codex
# Authenticate (choose one):
# Option 1: ChatGPT subscription (Plus, Pro, Team, Enterprise)
codex # Follow prompts to sign in
# Option 2: API key
export OPENAI_API_KEY=sk-proj-...
# Check Codex is installed
codex --version
# Test review
codex
> /review
See codex-review.md skill for full Codex documentation.
If you want to use Gemini or multi-engine modes, install the Gemini CLI:
# Prerequisites: Node.js 20+
node --version # Must be 20+
# Install Gemini CLI
npm install -g @google/gemini-cli
# Or via Homebrew (macOS)
brew install gemini-cli
# Install Code Review extension
gemini extensions install https://github.com/gemini-cli-extensions/code-review
# Option 1: Google Account (recommended, 1000 req/day free)
gemini # Follow browser login prompts
# Option 2: API key (100 req/day free)
export GEMINI_API_KEY="your-key-from-aistudio.google.com"
# Check Gemini is installed
gemini --version
# List extensions
gemini extensions list
# Test review
gemini
> /code-review
See gemini-review.md skill for full Gemini documentation.
# .github/workflows/code-review.yml
name: Code Review
on:
pull_request:
types: [opened, synchronize, reopened]
jobs:
code-review:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Get changed files
id: changed-files
run: |
echo "files=$(git diff --name-only origin/${{ github.base_ref }}...HEAD | tr '\n' ' ')" >> $GITHUB_OUTPUT
- name: Run Claude Code Review
env:
ANTHROPIC_API_KEY: ${{ secrets.ANTHROPIC_API_KEY }}
run: |
npx @anthropic-ai/claude-code --print "/code-review ${{ steps.changed-files.outputs.files }}" > review.md
- name: Post Review Comment
uses: actions/github-script@v7
with:
script: |
const fs = require('fs');
const review = fs.readFileSync('review.md', 'utf8');
github.rest.issues.createComment({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: context.issue.number,
body: `## 🔍 Claude Code Review\n\n${review}`
});
- name: Check for Critical Issues
run: |
if grep -q "Critical\|🔴" review.md; then
echo "❌ Critical issues found"
exit 1
fi
# .github/workflows/codex-review.yml
name: Codex Code Review
on:
pull_request:
jobs:
review:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Codex Review
uses: openai/codex-action@main
with:
openai_api_key: ${{ secrets.OPENAI_API_KEY }}
model: gpt-5.2-codex
safety_strategy: drop-sudo
# .github/workflows/dual-review.yml
name: Dual Code Review
on:
pull_request:
jobs:
claude-review:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Claude Review
env:
ANTHROPIC_API_KEY: ${{ secrets.ANTHROPIC_API_KEY }}
run: |
npx @anthropic-ai/claude-code --print "/code-review" > claude-review.md
- uses: actions/upload-artifact@v4
with:
name: claude-review
path: claude-review.md
codex-review:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- uses: actions/setup-node@v4
with:
node-version: '22'
- name: Install Codex
run: npm install -g @openai/codex
- name: Codex Review
env:
OPENAI_API_KEY: ${{ secrets.OPENAI_API_KEY }}
run: |
codex exec --full-auto --sandbox read-only \
--output-last-message codex-review.md \
"Review this code for bugs, security issues, and quality problems"
- uses: actions/upload-artifact@v4
with:
name: codex-review
path: codex-review.md
combine-reviews:
needs: [claude-review, codex-review]
runs-on: ubuntu-latest
steps:
- uses: actions/download-artifact@v4
- name: Combine Reviews
run: |
echo "## 🔍 Dual Code Review Results" > combined-review.md
echo "" >> combined-review.md
echo "### Claude Findings" >> combined-review.md
cat claude-review/claude-review.md >> combined-review.md
echo "" >> combined-review.md
echo "### Codex Findings" >> combined-review.md
cat codex-review/codex-review.md >> combined-review.md
- name: Post Combined Review
uses: actions/github-script@v7
with:
script: |
const fs = require('fs');
const review = fs.readFileSync('combined-review.md', 'utf8');
github.rest.issues.createComment({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: context.issue.number,
body: review
});
# .github/workflows/gemini-review.yml
name: Gemini Code Review
on:
pull_request:
types: [opened, synchronize]
jobs:
review:
runs-on: ubuntu-latest
permissions:
contents: read
pull-requests: write
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: '20'
- name: Install Gemini CLI
run: npm install -g @google/gemini-cli
- name: Run Review
env:
GEMINI_API_KEY: ${{ secrets.GEMINI_API_KEY }}
run: |
# Get diff
git diff origin/${{ github.base_ref }}...HEAD > diff.txt
# Run Gemini review
gemini -p "Review this pull request diff for bugs, security issues, and code quality problems. Be specific about file names and line numbers.
$(cat diff.txt)" > review.md
- name: Post Review Comment
uses: actions/github-script@v7
with:
script: |
const fs = require('fs');
const review = fs.readFileSync('review.md', 'utf8');
github.rest.issues.createComment({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: context.issue.number,
body: `## 🤖 Gemini Code Review\n\n${review}`
});
- name: Check for Critical Issues
run: |
if grep -qi "critical\|security vulnerability\|injection" review.md; then
echo "❌ Critical issues found"
exit 1
fi
# .github/workflows/triple-review.yml
name: Triple Engine Code Review
on:
pull_request:
jobs:
claude-review:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Claude Review
env:
ANTHROPIC_API_KEY: ${{ secrets.ANTHROPIC_API_KEY }}
run: |
npx @anthropic-ai/claude-code --print "/code-review" > claude-review.md
- uses: actions/upload-artifact@v4
with:
name: claude-review
path: claude-review.md
codex-review:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- uses: actions/setup-node@v4
with:
node-version: '22'
- name: Install Codex
run: npm install -g @openai/codex
- name: Codex Review
env:
OPENAI_API_KEY: ${{ secrets.OPENAI_API_KEY }}
run: |
codex exec --full-auto --sandbox read-only \
--output-last-message codex-review.md \
"Review this code for bugs, security issues, and quality problems"
- uses: actions/upload-artifact@v4
with:
name: codex-review
path: codex-review.md
gemini-review:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- uses: actions/setup-node@v4
with:
node-version: '20'
- name: Install Gemini CLI
run: npm install -g @google/gemini-cli
- name: Gemini Review
env:
GEMINI_API_KEY: ${{ secrets.GEMINI_API_KEY }}
run: |
git diff origin/${{ github.base_ref }}...HEAD > diff.txt
gemini -p "Review this code diff for bugs, security, and quality issues:
$(cat diff.txt)" > gemini-review.md
- uses: actions/upload-artifact@v4
with:
name: gemini-review
path: gemini-review.md
combine-reviews:
needs: [claude-review, codex-review, gemini-review]
runs-on: ubuntu-latest
steps:
- uses: actions/download-artifact@v4
- name: Combine Reviews
run: |
echo "## 🔍 Triple Engine Code Review Results" > combined-review.md
echo "" >> combined-review.md
echo "### 🟣 Claude Findings" >> combined-review.md
cat claude-review/claude-review.md >> combined-review.md
echo "" >> combined-review.md
echo "---" >> combined-review.md
echo "### 🟢 Codex Findings" >> combined-review.md
cat codex-review/codex-review.md >> combined-review.md
echo "" >> combined-review.md
echo "---" >> combined-review.md
echo "### 🔵 Gemini Findings" >> combined-review.md
cat gemini-review/gemini-review.md >> combined-review.md
- name: Post Combined Review
uses: actions/github-script@v7
with:
script: |
const fs = require('fs');
const review = fs.readFileSync('combined-review.md', 'utf8');
github.rest.issues.createComment({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: context.issue.number,
body: review
});
- name: Check Critical Issues
run: |
# Fail if any engine found critical issues
if grep -qi "critical\|🔴" combined-review.md; then
echo "❌ Critical issues found by at least one engine"
exit 1
fi
/code-review on staged changes| Issue | Example | Fix |
|---|---|---|
| SQL Injection | query = f"SELECT * FROM users WHERE id = {id}" | Use parameterized queries |
| XSS | innerHTML = userInput | Sanitize or use textContent |
| Secrets in code | apiKey = "sk-xxx" | Use environment variables |
| Missing auth | Unprotected endpoints | Add authentication middleware |
| Insecure crypto | MD5/SHA1 for passwords | Use bcrypt/argon2 |
| Issue | Example | Fix |
|---|---|---|
| N+1 queries | Loop with individual queries | Use batch/eager loading |
| Memory leak | Unclosed connections | Use connection pooling |
| Missing index | Slow queries | Add database indexes |
| Large payload | Fetching unused fields | Select only needed fields |
| No pagination | Loading all records | Implement pagination |
| Issue | Example | Fix |
|---|---|---|
| Long function | 100+ lines | Extract into smaller functions |
| Deep nesting | 5+ levels | Early returns, extract methods |
| Magic numbers | if (status === 3) | Use named constants |
| Duplicate code | Copy-pasted blocks | Extract shared function |
| Missing types | any everywhere | Add proper TypeScript types |
┌─────────────────────────────────────────────────────────────────┐
│ TDD + CODE REVIEW WORKFLOW │
│ ───────────────────────────────────────────────────────────── │
│ │
│ 1. RED: Write failing tests │
│ 2. GREEN: Write code to pass tests │
│ 3. REFACTOR: Clean up code │
│ 4. REVIEW: Run /code-review ← NEW STEP │
│ 5. FIX: Address critical/high issues │
│ 6. VALIDATE: Lint + TypeCheck + Coverage │
│ 7. COMMIT: Only after review passes │
│ │
│ Review catches what tests miss: │
│ - Security vulnerabilities │
│ - Performance issues │
│ - Architecture problems │
│ - Code maintainability │
└─────────────────────────────────────────────────────────────────┘
When code review finds issues, respond with:
## Code Review Results
### 🔴 Critical Issues (Must Fix)
1. **SQL Injection in userController.ts:45**
- Issue: User input directly interpolated into query
- Fix: Use parameterized query
- Code: `db.query('SELECT * FROM users WHERE id = $1', [userId])`
### 🟠 High Issues (Should Fix)
1. **Missing authentication on /api/admin endpoints**
- Issue: Admin routes accessible without auth
- Fix: Add auth middleware
### 🟡 Medium Issues (Fix Soon)
1. **N+1 query in getOrders function**
- Consider eager loading or batch query
### 🟢 Low Issues (Nice to Have)
1. **Consider extracting validation logic to separate file**
### ✅ Strengths
- Good test coverage
- Clear function names
- Proper error handling
### 📊 Summary
- Critical: 1 | High: 1 | Medium: 1 | Low: 1
- **Status: ❌ BLOCKED** - Fix critical/high issues before commit
Claude should automatically suggest or run code review:
Prioritize review based on change type:
| Change Type | Focus Areas |
|---|---|
| Auth/Security code | Security, input validation, crypto |
| Database code | SQL injection, N+1, transactions |
| API endpoints | Auth, rate limiting, validation |
| Frontend code | XSS, state management, performance |
| Infrastructure | Secrets, permissions, logging |
# Basic review
/code-review
# Review specific files
/code-review src/auth.ts src/users.ts
# Review with focus
/code-review --focus security
# Review PR
/code-review --pr 123
🔴 Critical → STOP. Fix now. No commit.
🟠 High → STOP. Fix now. No commit.
🟡 Medium → Note it. Fix soon. Can commit.
🟢 Low → Optional. Nice to have.
ℹ️ Info → FYI only.
Code → Test → Review → Fix → Commit → Push → PR → Review → Merge → Deploy
↑ ↑ ↑
/code-review /code-review /code-review
Weekly Installs
95
Repository
GitHub Stars
529
First Seen
Jan 20, 2026
Security Audits
Gen Agent Trust HubPassSocketPassSnykWarn
Installed on
opencode76
claude-code75
gemini-cli73
codex68
cursor68
github-copilot61
AI Elements:基于shadcn/ui的AI原生应用组件库,快速构建对话界面
67,500 周安装
Terraform GitHub Actions 部署指南:无密钥CI/CD与安全自动化
4 周安装
Bun WebSocket服务器教程 - 使用Bun.serve()构建实时通信应用
6 周安装
web-auth-persist:Web 身份验证持久化工具 | API/Git 开源项目 | 安全开发
5 周安装
appdumpsearch - API与Git集成工具,高效搜索应用数据,提升开发效率
5 周安装
CI/CD Pipeline Builder - 自动化构建与部署工具,支持多平台集成
5 周安装
Bun测试模拟教程:mock()、spyOn()与模块模拟,兼容Jest的JavaScript测试指南
9 周安装
| Best for | Quick reviews | High accuracy | Large codebases | Critical code |