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.27.0+) for code generation, review, analysis, and specialized tasks. The default model is Auto routing (automatically selects between Flash and Pro based on task complexity).
该技能可让Claude Code有效调度Gemini CLI(v0.27.0及以上版本)完成代码生成、审查、分析及特定任务。默认模型为自动路由(根据任务复杂度自动在Flash和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]" --approval-mode yolo -o text 2>&1
Key flags:
  • --approval-mode yolo
    : Auto-approve all tool calls (replaces deprecated
    --yolo
    )
  • -o text
    : Human-readable output
  • -o json
    : Structured output with stats
  • -m gemini-2.5-flash
    : Use faster model for simple tasks
  • -m auto
    : Smart routing (default) — auto-selects Flash or Pro based on complexity
bash
gemini "[prompt]" --approval-mode yolo -o text 2>&1
关键参数:
  • --approval-mode yolo
    : 自动批准所有工具调用(替代已弃用的
    --yolo
  • -o text
    : 人类可读格式输出
  • -o json
    : 带统计信息的结构化输出
  • -m gemini-2.5-flash
    : 简单任务使用更快的模型
  • -m auto
    : 智能路由(默认)——根据任务复杂度自动选择Flash或Pro

3. Critical Behavioral Notes

3. 重要行为说明

Approval Mode Behavior:
--approval-mode yolo
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"
Note:
--yolo
/
-y
is deprecated. Use
--approval-mode yolo
instead. Other modes:
default
,
auto_edit
.
Rate Limits: Free tier limits apply. CLI auto-retries with exponential backoff. Expect messages like "quota will reset after Xs".
批准模式行为
--approval-mode yolo
会自动批准工具调用,但无法阻止规划提示。Gemini仍可能呈现计划并询问“此计划是否可行?”,需使用强制语言:
  • “立即执行”
  • “马上开始”
  • “无需确认直接执行”
注意
--yolo
/
-y
已被弃用,请使用
--approval-mode yolo
替代。其他模式:
default
auto_edit
速率限制:免费版有使用限制。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." --approval-mode yolo -o text
bash
gemini "创建[描述]并包含[特性]。输出完整文件内容。" --approval-mode 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." --approval-mode yolo -o text
bash
gemini "修复[文件]中的以下Bug:[列表]。立即应用修复。" --approval-mode yolo -o text

Test Generation

测试用例生成

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

Documentation

文档生成

bash
gemini "Generate JSDoc for all functions in [file]. Output as markdown." --approval-mode yolo -o text
bash
gemini "为[文件]中的所有函数生成JSDoc。以Markdown格式输出。" --approval-mode 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 exponential backoff
  • Use
    -m gemini-2.5-flash
    for lower priority tasks (different quota)
  • Use Auto routing (default) to let the system optimize model selection
  • 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]" --approval-mode yolo -o text
gemini "创建[代码]" --approval-mode 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." --approval-mode yolo -o text
undefined
gemini "修复[文件]中的[问题]。立即应用。" --approval-mode yolo -o text
undefined

Background Execution

后台执行

For long tasks, run in background and monitor:
bash
gemini "[long task]" --approval-mode yolo -o text 2>&1 &
对于长时间任务,可在后台运行并监控:
bash
gemini "[长时间任务]" --approval-mode 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 (experimental agent, may require opt-in)
  3. save_memory - Cross-session persistent memory
以下工具仅通过Gemini提供:
  1. google_web_search - 通过Google进行实时互联网搜索
  2. codebase_investigator - 深度架构分析(实验性Agent,可能需要手动启用)
  3. save_memory - 跨会话持久化记忆

Model Selection

模型选择

ModelUse Case
auto
(default)
Smart routing — auto-selects Flash or Pro based on task complexity
gemini-2.5-pro
Complex reasoning tasks
gemini-2.5-flash
Quick tasks, lower latency
gemini-3-pro-preview
Latest capabilities (requires Google AI Ultra or paid API key)
gemini-3-flash-preview
Latest Flash model (requires Preview Features enabled)
模型使用场景
auto
(默认)
智能路由——根据任务复杂度自动选择Flash或Pro
gemini-2.5-pro
复杂推理任务
gemini-2.5-flash
快速任务,低延迟
gemini-3-pro-preview
最新功能(需要Google AI Ultra或付费API密钥)
gemini-3-flash-preview
最新Flash模型(需要启用预览功能)

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 "follow-up" | gemini -r [index] -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
    - 常见操作的Prompt模板
  • patterns.md
    - 高级集成模式
  • tools.md
    - Gemini内置工具文档