gemini-review
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseGoogle Gemini Code Review Skill
Google Gemini 代码审查Skill
Load with: base.md + code-review.md
Use Google's Gemini CLI for code review with Gemini 2.5 Pro - featuring a massive 1M token context window that can analyze entire repositories at once.
加载方式:base.md + code-review.md
使用Google的Gemini CLI结合Gemini 2.5 Pro进行代码审查——其具备超大的1M token上下文窗口,可一次性分析整个代码仓库。
Why Gemini for Code Review?
为什么选择Gemini进行代码审查?
| Feature | Benefit |
|---|---|
| Gemini 2.5 Pro | State-of-the-art reasoning for code |
| 1M token context | Entire repositories fit - no chunking needed |
| Free tier | 1,000 requests/day with Google account |
| Consistent output | Clean formatting, predictable structure |
| GitHub native | Gemini Code Assist app for auto PR reviews |
| 特性 | 优势 |
|---|---|
| Gemini 2.5 Pro | 业界领先的代码推理能力 |
| 1M token上下文 | 可容纳整个代码仓库——无需分片处理 |
| 免费额度 | 使用Google账号每日可请求1000次 |
| 输出一致性 | 格式清晰,结构可预测 |
| 原生支持GitHub | Gemini Code Assist应用可自动进行PR审查 |
Benchmark Performance
基准测试性能
| Benchmark | Score | Notes |
|---|---|---|
| SWE-Bench Verified | 63.8% | Agentic coding benchmark |
| Qodo PR Benchmark | 56.3% | PR review quality |
| LiveCodeBench v5 | 70.4% | Code generation |
| WebDev Arena | #1 | Web development |
| 基准测试 | 分数 | 说明 |
|---|---|---|
| SWE-Bench Verified | 63.8% | 智能代理编码基准测试 |
| Qodo PR Benchmark | 56.3% | PR审查质量 |
| LiveCodeBench v5 | 70.4% | 代码生成能力 |
| WebDev Arena | #1 | Web开发领域 |
Installation
安装步骤
Prerequisites
前置要求
bash
undefinedbash
undefinedCheck Node.js version (requires 20+)
检查Node.js版本(需要20+)
node --version
node --version
Install Node.js 20 if needed
若需要,安装Node.js 20
macOS
macOS
brew install node@20
brew install node@20
Or via nvm
或通过nvm安装
nvm install 20
nvm use 20
undefinednvm install 20
nvm use 20
undefinedInstall Gemini CLI
安装Gemini CLI
bash
undefinedbash
undefinedVia npm (recommended)
推荐通过npm安装
npm install -g @google/gemini-cli
npm install -g @google/gemini-cli
Via Homebrew (macOS)
macOS可通过Homebrew安装
brew install gemini-cli
brew install gemini-cli
Or run without installing
或无需安装直接运行
npx @google/gemini-cli
npx @google/gemini-cli
Verify installation
验证安装
gemini --version
undefinedgemini --version
undefinedInstall Code Review Extension
安装代码审查扩展
bash
undefinedbash
undefinedRequires Gemini CLI v0.4.0+
需要Gemini CLI v0.4.0及以上版本
gemini extensions install https://github.com/gemini-cli-extensions/code-review
gemini extensions install https://github.com/gemini-cli-extensions/code-review
Verify extension
验证扩展
gemini extensions list
---gemini extensions list
---Authentication
身份验证
Option 1: Google Account (Recommended)
选项1:Google账号(推荐)
Free tier: 1,000 requests/day, 60 requests/min
bash
undefined免费额度:每日1000次请求,每分钟60次请求
bash
undefinedRun gemini and follow browser login
运行gemini并跟随浏览器引导登录
gemini
gemini
Select: "Login with Google Account"
选择:"使用Google账号登录"
Opens browser for OAuth
会打开浏览器进行OAuth授权
This gives you access to Gemini 2.5 Pro with the full 1M token context window.
此方式可让你访问具备完整1M token上下文窗口的Gemini 2.5 Pro。Option 2: Gemini API Key
选项2:Gemini API密钥
Free tier: 100 requests/day
bash
undefined免费额度:每日100次请求
bash
undefinedSet environment variable
设置环境变量
export GEMINI_API_KEY="your-api-key"
export GEMINI_API_KEY="your-api-key"
Or add to shell profile
或添加到shell配置文件
echo 'export GEMINI_API_KEY="your-api-key"' >> ~/.zshrc
echo 'export GEMINI_API_KEY="your-api-key"' >> ~/.zshrc
Run Gemini
运行Gemini
gemini
undefinedgemini
undefinedOption 3: Vertex AI (Enterprise)
选项3:Vertex AI(企业版)
bash
undefinedbash
undefinedFor Google Cloud projects
适用于Google Cloud项目
export GOOGLE_API_KEY="your-api-key"
export GOOGLE_GENAI_USE_VERTEXAI=true
export GOOGLE_CLOUD_PROJECT="your-project-id"
gemini
---export GOOGLE_API_KEY="your-api-key"
export GOOGLE_GENAI_USE_VERTEXAI=true
export GOOGLE_CLOUD_PROJECT="your-project-id"
gemini
---Interactive Code Review
交互式代码审查
Using the Code Review Extension
使用代码审查扩展
bash
undefinedbash
undefinedStart Gemini CLI
启动Gemini CLI
gemini
gemini
Run code review on current branch
对当前分支运行代码审查
/code-review
The extension analyzes:
- Code changes on your current branch
- Identifies quality issues
- Suggests fixes/code-review
该扩展会分析:
- 当前分支的代码变更
- 识别质量问题
- 提供修复建议Manual Review Prompts
手动审查指令
bash
undefinedbash
undefinedIn interactive mode
进入交互模式
gemini
gemini
Then ask:
然后输入:
Review the changes in this branch for bugs and security issues Analyze src/api/users.ts for potential vulnerabilities What are the code quality issues in the last 3 commits?
---审查此分支中的变更,查找bug和安全问题 分析src/api/users.ts中的潜在漏洞 最近3次提交中的代码质量问题有哪些?
---Headless Mode (Automation)
无头模式(自动化)
Basic Usage
基础用法
bash
undefinedbash
undefinedSimple prompt execution
执行简单指令
gemini -p "Review the code changes for bugs and security issues"
gemini -p "审查代码变更中的bug和安全问题"
With JSON output (for parsing)
输出JSON格式(便于解析)
gemini -p "Review the changes" --output-format json
gemini -p "审查变更内容" --output-format json
Stream JSON events (real-time)
流式输出JSON事件(实时)
gemini -p "Review and fix issues" --output-format stream-json
gemini -p "审查并修复问题" --output-format stream-json
Specify model
指定模型
gemini -m gemini-2.5-pro -p "Deep code review of this PR"
undefinedgemini -m gemini-2.5-pro -p "对本次PR进行深度代码审查"
undefinedFull CI/CD Example
完整CI/CD示例
bash
undefinedbash
undefinedGet diff and review
获取差异内容并审查
git diff origin/main...HEAD > diff.txt
gemini -p "Review this code diff for:
- Security vulnerabilities
- Performance issues
- Code quality problems
- Missing error handling
Diff:
$(cat diff.txt)
" --output-format json > review.json
undefinedgit diff origin/main...HEAD > diff.txt
gemini -p "审查以下代码差异,重点关注:
- 安全漏洞
- 性能问题
- 代码质量问题
- 缺失的错误处理
差异内容:
$(cat diff.txt)
" --output-format json > review.json
undefinedSession Tracking
会话跟踪
bash
undefinedbash
undefinedTrack token usage and costs
跟踪token使用情况和成本
gemini -p "Review changes" --session-summary metrics.json
gemini -p "审查变更内容" --session-summary metrics.json
View metrics
查看指标
cat metrics.json
---cat metrics.json
---GitHub Integration
GitHub集成
Option 1: Gemini Code Assist App (Easiest)
选项1:Gemini Code Assist应用(最简单)
Install from GitHub Marketplace:
- Go to GitHub Marketplace → Gemini Code Assist
- Click "Install" and select repositories
- PRs automatically get reviewed when opened
Commands in PR comments:
/gemini review # Request code review
/gemini summary # Get PR summary
/gemini help # Show available commandsQuota:
- Free: 33 PRs/day
- Enterprise: 100+ PRs/day
- 访问GitHub Marketplace → Gemini Code Assist
- 点击“安装”并选择仓库
- PR创建后会自动进行审查
PR评论中的指令:
/gemini review # 请求代码审查
/gemini summary # 获取PR摘要
/gemini help # 显示可用指令额度限制:
- 免费版:每日33个PR
- 企业版:每日100+个PR
Option 2: GitHub Action
选项2:GitHub Action
yaml
undefinedyaml
undefined.github/workflows/gemini-review.yml
.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}`
});undefinedname: 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: |
# 获取差异内容
git diff origin/${{ github.base_ref }}...HEAD > diff.txt
# 运行Gemini审查
gemini -p "审查本次拉取请求的代码差异,查找bug、安全问题和代码质量问题。请明确指出文件名和行号。
$(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 代码审查\n\n${review}`
});undefinedOption 3: Official GitHub Action
选项3:官方GitHub Action
yaml
undefinedyaml
undefined.github/workflows/gemini-review.yml
.github/workflows/gemini-review.yml
name: Gemini Code Review
on:
pull_request:
types: [opened, synchronize]
issue_comment:
types: [created]
jobs:
review:
runs-on: ubuntu-latest
permissions:
contents: read
pull-requests: write
issues: write
steps:
- uses: actions/checkout@v4
- name: Run Gemini CLI
uses: google-github-actions/run-gemini-cli@v1
with:
gemini_api_key: ${{ secrets.GEMINI_API_KEY }}
prompt: "Review this pull request for code quality, security issues, and potential bugs."
**On-demand commands in comments:**@gemini-cli /review
@gemini-cli explain this code change
@gemini-cli write unit tests for this component
---name: Gemini Code Review
on:
pull_request:
types: [opened, synchronize]
issue_comment:
types: [created]
jobs:
review:
runs-on: ubuntu-latest
permissions:
contents: read
pull-requests: write
issues: write
steps:
- uses: actions/checkout@v4
- name: Run Gemini CLI
uses: google-github-actions/run-gemini-cli@v1
with:
gemini_api_key: ${{ secrets.GEMINI_API_KEY }}
prompt: "审查本次拉取请求的代码质量、安全问题和潜在bug。"
**评论中的按需指令:**@gemini-cli /review
@gemini-cli 解释此代码变更
@gemini-cli 为该组件编写单元测试
---GitLab CI/CD
GitLab CI/CD
yaml
undefinedyaml
undefined.gitlab-ci.yml
.gitlab-ci.yml
gemini-review:
image: node:20
stage: review
script:
- npm install -g @google/gemini-cli
- |
gemini -p "Review the merge request changes for bugs, security issues, and code quality" > review.md
- cat review.md
artifacts:
paths:
- review.md
rules:
- if: $CI_PIPELINE_SOURCE == "merge_request_event"
variables:
GEMINI_API_KEY: $GEMINI_API_KEY
---gemini-review:
image: node:20
stage: review
script:
- npm install -g @google/gemini-cli
- |
gemini -p "审查合并请求中的变更,查找bug、安全问题和代码质量问题" > review.md
- cat review.md
artifacts:
paths:
- review.md
rules:
- if: $CI_PIPELINE_SOURCE == "merge_request_event"
variables:
GEMINI_API_KEY: $GEMINI_API_KEY
---Configuration
配置
Global Config
全局配置
bash
undefinedbash
undefined~/.gemini/settings.json
~/.gemini/settings.json
{
"model": "gemini-2.5-pro",
"theme": "dark",
"sandbox": true
}
undefined{
"model": "gemini-2.5-pro",
"theme": "dark",
"sandbox": true
}
undefinedProject Config (GEMINI.md)
项目配置(GEMINI.md)
Create a file in your project root for project-specific context:
GEMINI.mdmarkdown
undefined在项目根目录创建文件,提供项目特定上下文:
GEMINI.mdmarkdown
undefinedProject Context for Gemini
Gemini项目上下文
Tech Stack
技术栈
- TypeScript with strict mode
- React 18 with hooks
- FastAPI backend
- PostgreSQL database
- 开启严格模式的TypeScript
- React 18及Hooks
- FastAPI后端
- PostgreSQL数据库
Code Review Focus Areas
代码审查重点
- Type safety - ensure proper TypeScript types
- React hooks rules - check for dependency array issues
- SQL injection - verify parameterized queries
- Authentication - check all endpoints have proper auth
- 类型安全 - 确保TypeScript类型正确
- React Hooks规则 - 检查依赖数组问题
- SQL注入 - 验证参数化查询
- 身份验证 - 检查所有端点是否具备正确的认证
Conventions
约定
- Use camelCase for variables
- Use PascalCase for components
- All API errors should use AppError class
---- 变量使用小驼峰命名
- 组件使用大驼峰命名
- 所有API错误应使用AppError类
---CLI Quick Reference
CLI快速参考
bash
undefinedbash
undefinedInteractive
交互模式
gemini # Start interactive mode
/code-review # Run code review extension
gemini # 启动交互模式
/code-review # 运行代码审查扩展
Headless
无头模式
gemini -p "prompt" # Single prompt, exit
gemini -p "prompt" --output-format json # JSON output
gemini -m gemini-2.5-flash -p "prompt" # Use faster model
gemini -p "prompt" # 执行单个指令后退出
gemini -p "prompt" --output-format json # 输出JSON格式
gemini -m gemini-2.5-flash -p "prompt" # 使用更快的模型
Extensions
扩展管理
gemini extensions list # List installed
gemini extensions install URL # Install extension
gemini extensions update # Update all
gemini extensions list # 列出已安装扩展
gemini extensions install URL # 安装扩展
gemini extensions update # 更新所有扩展
Key Flags
关键参数
--output-format json # Structured output
--output-format stream-json # Real-time events
--session-summary FILE # Track metrics
-m MODEL # Select model
-----output-format json # 结构化输出
--output-format stream-json # 实时事件输出
--session-summary FILE # 跟踪指标
-m MODEL # 选择模型
---Comparison: Claude vs Codex vs Gemini
对比:Claude vs Codex vs Gemini
| Aspect | Claude | Codex CLI | Gemini CLI |
|---|---|---|---|
| Setup | None (built-in) | npm + OpenAI API | npm + Google Account |
| Model | Claude | GPT-5.2-Codex | Gemini 2.5 Pro |
| Context | Conversation | Fresh per review | 1M tokens (huge!) |
| Free Tier | N/A | Limited | 1,000/day |
| Best For | Quick reviews | High accuracy | Large codebases |
| GitHub Native | No | @codex | Gemini Code Assist |
| 维度 | Claude | Codex CLI | Gemini CLI |
|---|---|---|---|
| 设置难度 | 无(内置) | npm + OpenAI API | npm + Google账号 |
| 模型 | Claude | GPT-5.2-Codex | Gemini 2.5 Pro |
| 上下文 | 会话式 | 每次审查重新加载 | 1M tokens(超大!) |
| 免费额度 | 无 | 有限 | 每日1000次 |
| 最佳适用场景 | 快速审查 | 高准确率 | 大型代码仓库 |
| GitHub原生支持 | 否 | @codex | Gemini Code Assist |
When to Use Each
适用场景推荐
| Scenario | Recommended Engine |
|---|---|
| Quick in-flow review | Claude |
| Critical security review | Codex (88% detection) |
| Large codebase (100+ files) | Gemini (1M context) |
| Free automated reviews | Gemini |
| Multiple perspectives | All three (dual/triple engine) |
| 场景 | 推荐引擎 |
|---|---|
| 快速流程内审查 | Claude |
| 关键安全审查 | Codex(检测率88%) |
| 大型代码仓库(100+文件) | Gemini(1M上下文) |
| 免费自动化审查 | Gemini |
| 多视角审查 | 三者结合(双/三引擎) |
Troubleshooting
故障排除
| Issue | Solution |
|---|---|
| |
| Upgrade to Node.js 20+ |
| Re-run |
| |
| Wait or upgrade to Vertex AI |
| Ensure |
| 问题 | 解决方案 |
|---|---|
| 执行 |
| 升级到Node.js 20+ |
| 重新运行 |
| 执行 |
| 等待或升级到Vertex AI |
| 确保未设置 |
Anti-Patterns
反模式
- Skipping authentication setup - Always configure before CI/CD
- Using API key in logs - Use secrets management
- Ignoring context limits - Even 1M tokens has limits for huge monorepos
- Running on every commit - Use on PRs only to save quota
- Not setting project context - Add GEMINI.md for better reviews
- 跳过身份验证设置 - 在CI/CD前务必完成配置
- 在日志中暴露API密钥 - 使用密钥管理工具
- 忽略上下文限制 - 即使是1M tokens也无法处理超大型单体仓库
- 每次提交都运行审查 - 仅在PR时运行以节省额度
- 未设置项目上下文 - 添加GEMINI.md以获得更优质的审查结果