gemini-review

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

Google 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进行代码审查?

FeatureBenefit
Gemini 2.5 ProState-of-the-art reasoning for code
1M token contextEntire repositories fit - no chunking needed
Free tier1,000 requests/day with Google account
Consistent outputClean formatting, predictable structure
GitHub nativeGemini Code Assist app for auto PR reviews
特性优势
Gemini 2.5 Pro业界领先的代码推理能力
1M token上下文可容纳整个代码仓库——无需分片处理
免费额度使用Google账号每日可请求1000次
输出一致性格式清晰,结构可预测
原生支持GitHubGemini Code Assist应用可自动进行PR审查

Benchmark Performance

基准测试性能

BenchmarkScoreNotes
SWE-Bench Verified63.8%Agentic coding benchmark
Qodo PR Benchmark56.3%PR review quality
LiveCodeBench v570.4%Code generation
WebDev Arena#1Web development

基准测试分数说明
SWE-Bench Verified63.8%智能代理编码基准测试
Qodo PR Benchmark56.3%PR审查质量
LiveCodeBench v570.4%代码生成能力
WebDev Arena#1Web开发领域

Installation

安装步骤

Prerequisites

前置要求

bash
undefined
bash
undefined

Check 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
undefined
nvm install 20 nvm use 20
undefined

Install Gemini CLI

安装Gemini CLI

bash
undefined
bash
undefined

Via 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
undefined
gemini --version
undefined

Install Code Review Extension

安装代码审查扩展

bash
undefined
bash
undefined

Requires Gemini CLI v0.4.0+

需要Gemini CLI v0.4.0及以上版本

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
undefined

Run 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
undefined

Set 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
undefined
gemini
undefined

Option 3: Vertex AI (Enterprise)

选项3:Vertex AI(企业版)

bash
undefined
bash
undefined

For 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
undefined
bash
undefined

Start 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
undefined
bash
undefined

In 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
undefined
bash
undefined

Simple 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"
undefined
gemini -m gemini-2.5-pro -p "对本次PR进行深度代码审查"
undefined

Full CI/CD Example

完整CI/CD示例

bash
undefined
bash
undefined

Get diff and review

获取差异内容并审查

git diff origin/main...HEAD > diff.txt
gemini -p "Review this code diff for:
  1. Security vulnerabilities
  2. Performance issues
  3. Code quality problems
  4. Missing error handling
Diff: $(cat diff.txt) " --output-format json > review.json
undefined
git diff origin/main...HEAD > diff.txt
gemini -p "审查以下代码差异,重点关注:
  1. 安全漏洞
  2. 性能问题
  3. 代码质量问题
  4. 缺失的错误处理
差异内容: $(cat diff.txt) " --output-format json > review.json
undefined

Session Tracking

会话跟踪

bash
undefined
bash
undefined

Track 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:
  1. Go to GitHub Marketplace → Gemini Code Assist
  2. Click "Install" and select repositories
  3. PRs automatically get reviewed when opened
Commands in PR comments:
/gemini review     # Request code review
/gemini summary    # Get PR summary
/gemini help       # Show available commands
Quota:
  • Free: 33 PRs/day
  • Enterprise: 100+ PRs/day
GitHub Marketplace安装:
  1. 访问GitHub Marketplace → Gemini Code Assist
  2. 点击“安装”并选择仓库
  3. PR创建后会自动进行审查
PR评论中的指令:
/gemini review     # 请求代码审查
/gemini summary    # 获取PR摘要
/gemini help       # 显示可用指令
额度限制:
  • 免费版:每日33个PR
  • 企业版:每日100+个PR

Option 2: GitHub Action

选项2:GitHub Action

yaml
undefined
yaml
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}`
        });
undefined
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: |
      # 获取差异内容
      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}`
        });
undefined

Option 3: Official GitHub Action

选项3:官方GitHub Action

yaml
undefined
yaml
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
undefined
yaml
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
undefined
bash
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 }
undefined

Project Config (GEMINI.md)

项目配置(GEMINI.md)

Create a
GEMINI.md
file in your project root for project-specific context:
markdown
undefined
在项目根目录创建
GEMINI.md
文件,提供项目特定上下文:
markdown
undefined

Project 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

代码审查重点

  1. Type safety - ensure proper TypeScript types
  2. React hooks rules - check for dependency array issues
  3. SQL injection - verify parameterized queries
  4. Authentication - check all endpoints have proper auth
  1. 类型安全 - 确保TypeScript类型正确
  2. React Hooks规则 - 检查依赖数组问题
  3. SQL注入 - 验证参数化查询
  4. 身份验证 - 检查所有端点是否具备正确的认证

Conventions

约定

  • Use camelCase for variables
  • Use PascalCase for components
  • All API errors should use AppError class

---
  • 变量使用小驼峰命名
  • 组件使用大驼峰命名
  • 所有API错误应使用AppError类

---

CLI Quick Reference

CLI快速参考

bash
undefined
bash
undefined

Interactive

交互模式

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

AspectClaudeCodex CLIGemini CLI
SetupNone (built-in)npm + OpenAI APInpm + Google Account
ModelClaudeGPT-5.2-CodexGemini 2.5 Pro
ContextConversationFresh per review1M tokens (huge!)
Free TierN/ALimited1,000/day
Best ForQuick reviewsHigh accuracyLarge codebases
GitHub NativeNo@codexGemini Code Assist
维度ClaudeCodex CLIGemini CLI
设置难度无(内置)npm + OpenAI APInpm + Google账号
模型ClaudeGPT-5.2-CodexGemini 2.5 Pro
上下文会话式每次审查重新加载1M tokens(超大!)
免费额度有限每日1000次
最佳适用场景快速审查高准确率大型代码仓库
GitHub原生支持@codexGemini Code Assist

When to Use Each

适用场景推荐

ScenarioRecommended Engine
Quick in-flow reviewClaude
Critical security reviewCodex (88% detection)
Large codebase (100+ files)Gemini (1M context)
Free automated reviewsGemini
Multiple perspectivesAll three (dual/triple engine)

场景推荐引擎
快速流程内审查Claude
关键安全审查Codex(检测率88%)
大型代码仓库(100+文件)Gemini(1M上下文)
免费自动化审查Gemini
多视角审查三者结合(双/三引擎)

Troubleshooting

故障排除

IssueSolution
gemini: command not found
npm install -g @google/gemini-cli
Node.js version error
Upgrade to Node.js 20+
Authentication failed
Re-run
gemini
and login again
Extension not found
gemini extensions install https://github.com/gemini-cli-extensions/code-review
Rate limited
Wait or upgrade to Vertex AI
Hangs in CI
Ensure
DEBUG
env var is not set

问题解决方案
gemini: command not found
执行
npm install -g @google/gemini-cli
Node.js version error
升级到Node.js 20+
Authentication failed
重新运行
gemini
并重新登录
Extension not found
执行
gemini extensions install https://github.com/gemini-cli-extensions/code-review
Rate limited
等待或升级到Vertex AI
CI中挂起
确保未设置
DEBUG
环境变量

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以获得更优质的审查结果