gemini-cli

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

Gemini CLI Integration Skill

Gemini CLI 集成技能

This skill enables Claude Code to effectively orchestrate Gemini CLI (v0.16.0+) with Gemini 3 Pro for code generation, review, analysis, and specialized tasks.
本技能可让Claude Code有效编排Gemini CLI(v0.16.0及以上版本)与Gemini 3 Pro,完成代码生成、审查、分析及各类专项任务。

When to Use This Skill

适用场景

Ideal Use Cases

理想使用场景

  1. Second Opinion / Cross-Validation
    • Code review after writing code (different AI perspective)
    • Security audit with alternative analysis
    • Finding bugs Claude might have missed
  2. Google Search Grounding
    • Questions requiring current internet information
    • Latest library versions, API changes, documentation updates
    • Current events or recent releases
  3. Codebase Architecture Analysis
    • Use Gemini's
      codebase_investigator
      tool
    • Understanding unfamiliar codebases
    • Mapping cross-file dependencies
  4. Parallel Processing
    • Offload tasks while continuing other work
    • Run multiple code generations simultaneously
    • Background documentation generation
  5. Specialized Generation
    • Test suite generation
    • JSDoc/documentation generation
    • Code translation between languages
  1. 二次意见/交叉验证
    • 代码编写完成后的多AI视角审查
    • 基于替代分析的安全审计
    • 排查Claude可能遗漏的Bug
  2. Google Search 信息支撑
    • 需要最新互联网信息的问题
    • 最新库版本、API变更、文档更新
    • 当前事件或近期发布内容
  3. 代码库架构分析
    • 使用Gemini的
      codebase_investigator
      工具
    • 理解陌生代码库
    • 梳理跨文件依赖关系
  4. 并行处理
    • 在处理其他工作时异步执行任务
    • 同时运行多个代码生成任务
    • 后台生成文档
  5. 专项代码生成
    • 测试套件生成
    • JSDoc/文档生成
    • 跨语言代码转换

When NOT to Use

不适用场景

  • Simple, quick tasks (overhead not worth it)
  • Tasks requiring immediate response (rate limits cause delays)
  • When context is already loaded and understood
  • Interactive refinement requiring conversation
  • 简单快速的任务(使用该工具的成本得不偿失)
  • 需要即时响应的任务(速率限制会导致延迟)
  • 上下文已加载且完全理解的场景
  • 需要交互式迭代优化的对话任务

Core Instructions

核心操作指南

1. Verify Installation

1. 验证安装情况

bash
command -v gemini || which gemini
bash
command -v gemini || which gemini

2. Basic Command Pattern

2. 基础命令格式

bash
gemini "[prompt]" --yolo -o text 2>&1
Key flags:
  • --yolo
    or
    -y
    : Auto-approve all tool calls
  • -o text
    : Human-readable output
  • -o json
    : Structured output with stats
  • -m gemini-2.5-flash
    : Use faster model for simple tasks
bash
gemini "[prompt]" --yolo -o text 2>&1
关键参数:
  • --yolo
    -y
    :自动批准所有工具调用
  • -o text
    :输出人类可读的文本格式
  • -o json
    :输出包含统计信息的结构化数据
  • -m gemini-2.5-flash
    :针对简单任务使用更快的模型

3. Critical Behavioral Notes

3. 重要行为说明

YOLO Mode Behavior: Auto-approves tool calls but does NOT prevent planning prompts. Gemini may still present plans and ask "Does this plan look good?" Use forceful language:
  • "Apply now"
  • "Start immediately"
  • "Do this without asking for confirmation"
Rate Limits: Free tier has 60 requests/min, 1000/day. CLI auto-retries with backoff. Expect messages like "quota will reset after Xs".
YOLO模式行为:自动批准工具调用,但不会阻止Gemini输出计划提示。Gemini仍可能展示执行计划并询问“该计划是否可行?”,此时需使用明确指令:
  • "立即执行"
  • "马上开始"
  • "无需确认直接执行"
速率限制:免费版限制为每分钟60次请求,每天1000次请求。CLI会自动重试并逐步延长间隔时间,可能会出现类似“配额将在X秒后重置”的提示。

4. Output Processing

4. 输出处理

For JSON output (
-o json
), parse:
json
{
  "response": "actual content",
  "stats": {
    "models": { "tokens": {...} },
    "tools": { "byName": {...} }
  }
}
对于JSON格式输出(
-o json
),可解析如下结构:
json
{
  "response": "实际内容",
  "stats": {
    "models": { "tokens": {...} },
    "tools": { "byName": {...} }
  }
}

Quick Reference Commands

快速参考命令

Code Generation

代码生成

bash
gemini "Create [description] with [features]. Output complete file content." --yolo -o text
bash
gemini "创建具备[特性]的[描述内容]。输出完整文件内容。" --yolo -o text

Code Review

代码审查

bash
gemini "Review [file] for: 1) features, 2) bugs/security issues, 3) improvements" -o text
bash
gemini "审查[文件],重点关注:1) 功能实现,2) Bug/安全问题,3) 优化建议" -o text

Bug Fixing

Bug修复

bash
gemini "Fix these bugs in [file]: [list]. Apply fixes now." --yolo -o text
bash
gemini "修复[文件]中的以下Bug:[列表]。立即应用修复。" --yolo -o text

Test Generation

测试生成

bash
gemini "Generate [Jest/pytest] tests for [file]. Focus on [areas]." --yolo -o text
bash
gemini "为[文件]生成[Jest/pytest]测试用例。重点覆盖[领域]。" --yolo -o text

Documentation

文档生成

bash
gemini "Generate JSDoc for all functions in [file]. Output as markdown." --yolo -o text
bash
gemini "为[文件]中所有函数生成JSDoc。以Markdown格式输出。" --yolo -o text

Architecture Analysis

架构分析

bash
gemini "Use codebase_investigator to analyze this project" -o text
bash
gemini "使用codebase_investigator分析该项目" -o text

Web Research

网页调研

bash
gemini "What are the latest [topic]? Use Google Search." -o text
bash
gemini "[主题]的最新动态是什么?使用Google Search查询。" -o text

Faster Model (Simple Tasks)

快速模型(简单任务)

bash
gemini "[prompt]" -m gemini-2.5-flash -o text
bash
gemini "[prompt]" -m gemini-2.5-flash -o text

Error Handling

错误处理

Rate Limit Exceeded

超出速率限制

  • CLI auto-retries with backoff
  • Use
    -m gemini-2.5-flash
    for lower priority tasks
  • Run in background for long operations
  • CLI会自动重试并延长间隔时间
  • 低优先级任务使用
    -m gemini-2.5-flash
    模型
  • 长时间任务在后台运行

Command Failures

命令执行失败

  • Check JSON output for detailed error stats
  • Verify Gemini is authenticated:
    gemini --version
  • Check
    ~/.gemini/settings.json
    for config issues
  • 查看JSON格式输出获取详细错误统计
  • 验证Gemini身份认证:
    gemini --version
  • 检查
    ~/.gemini/settings.json
    配置文件是否存在问题

Validation After Generation

生成结果验证

Always verify Gemini's output:
  • Check for security vulnerabilities (XSS, injection)
  • Test functionality matches requirements
  • Review code style consistency
  • Verify dependencies are appropriate
始终验证Gemini的输出内容:
  • 检查是否存在安全漏洞(如XSS、注入攻击)
  • 测试功能是否符合需求
  • 审查代码风格一致性
  • 验证依赖是否合适

Integration Workflow

集成工作流

Standard Generate-Review-Fix Cycle

标准生成-审查-修复流程

bash
undefined
bash
undefined

1. Generate

1. 生成代码

gemini "Create [code]" --yolo -o text
gemini "创建[代码内容]" --yolo -o text

2. Review (Gemini reviews its own work)

2. 审查(Gemini自审)

gemini "Review [file] for bugs and security issues" -o text
gemini "审查[文件]中的Bug和安全问题" -o text

3. Fix identified issues

3. 修复发现的问题

gemini "Fix [issues] in [file]. Apply now." --yolo -o text
undefined
gemini "修复[文件]中的[问题列表]。立即应用修复。" --yolo -o text
undefined

Background Execution

后台执行

For long tasks, run in background and monitor:
bash
gemini "[long task]" --yolo -o text 2>&1 &
对于长时间任务,可在后台运行并监控:
bash
gemini "[长时间任务]" --yolo -o text 2>&1 &

Monitor with BashOutput tool

使用BashOutput工具监控执行情况

undefined
undefined

Gemini's Unique Capabilities

Gemini 专属能力

These tools are available only through Gemini:
  1. google_web_search - Real-time internet search via Google
  2. codebase_investigator - Deep architectural analysis
  3. save_memory - Cross-session persistent memory
以下工具仅通过Gemini提供:
  1. google_web_search - 通过Google实现实时互联网搜索
  2. codebase_investigator - 深度架构分析
  3. save_memory - 跨会话持久化记忆

Configuration

配置说明

Project Context (Optional)

项目上下文(可选)

Create
.gemini/GEMINI.md
in project root for persistent context that Gemini will automatically read.
在项目根目录创建
.gemini/GEMINI.md
文件,Gemini会自动读取该文件中的持久化上下文信息。

Session Management

会话管理

List sessions:
gemini --list-sessions
Resume session:
echo "follow-up" | gemini -r [index] -o text
列出所有会话:
gemini --list-sessions
恢复会话:
echo "后续指令" | gemini -r [索引] -o text

See Also

相关文档

  • reference.md
    - Complete command and flag reference
  • templates.md
    - Prompt templates for common operations
  • patterns.md
    - Advanced integration patterns
  • tools.md
    - Gemini's built-in tools documentation
  • reference.md
    - 完整命令及参数参考
  • templates.md
    - 常见操作的提示词模板
  • patterns.md
    - 高级集成模式
  • tools.md
    - Gemini内置工具文档