gemini-cli
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseGemini 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
理想使用场景
-
Second Opinion / Cross-Validation
- Code review after writing code (different AI perspective)
- Security audit with alternative analysis
- Finding bugs Claude might have missed
-
Google Search Grounding
- Questions requiring current internet information
- Latest library versions, API changes, documentation updates
- Current events or recent releases
-
Codebase Architecture Analysis
- Use Gemini's tool
codebase_investigator - Understanding unfamiliar codebases
- Mapping cross-file dependencies
- Use Gemini's
-
Parallel Processing
- Offload tasks while continuing other work
- Run multiple code generations simultaneously
- Background documentation generation
-
Specialized Generation
- Test suite generation
- JSDoc/documentation generation
- Code translation between languages
-
二次意见/交叉验证
- 代码编写完成后的审查(不同AI视角)
- 通过替代分析进行安全审计
- 查找Claude可能遗漏的Bug
-
基于Google Search的信息获取
- 需要实时互联网信息的问题
- 最新的库版本、API变更、文档更新
- 时事或近期发布内容
-
代码库架构分析
- 使用Gemini的工具
codebase_investigator - 理解陌生代码库
- 映射跨文件依赖关系
- 使用Gemini的
-
并行处理
- 卸载任务同时继续其他工作
- 同时运行多个代码生成任务
- 后台生成文档
-
特定场景下的代码生成
- 测试套件生成
- 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 geminibash
command -v gemini || which gemini2. Basic Command Pattern
2. 基础命令格式
bash
gemini "[prompt]" --approval-mode yolo -o text 2>&1Key flags:
- : Auto-approve all tool calls (replaces deprecated
--approval-mode yolo)--yolo - : Human-readable output
-o text - : Structured output with stats
-o json - : Use faster model for simple tasks
-m gemini-2.5-flash - : Smart routing (default) — auto-selects Flash or Pro based on complexity
-m auto
bash
gemini "[prompt]" --approval-mode yolo -o text 2>&1关键参数:
- : 自动批准所有工具调用(替代已弃用的
--approval-mode yolo)--yolo - : 人类可读格式输出
-o text - : 带统计信息的结构化输出
-o json - : 简单任务使用更快的模型
-m gemini-2.5-flash - : 智能路由(默认)——根据任务复杂度自动选择Flash或Pro
-m auto
3. Critical Behavioral Notes
3. 重要行为说明
Approval 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:
--approval-mode yolo- "Apply now"
- "Start immediately"
- "Do this without asking for confirmation"
Note:/--yolois deprecated. Use-yinstead. Other modes:--approval-mode yolo,default.auto_edit
Rate Limits: Free tier limits apply. CLI auto-retries with exponential backoff. Expect messages like "quota will reset after Xs".
批准模式行为:会自动批准工具调用,但无法阻止规划提示。Gemini仍可能呈现计划并询问“此计划是否可行?”,需使用强制语言:
--approval-mode yolo- “立即执行”
- “马上开始”
- “无需确认直接执行”
注意:/--yolo已被弃用,请使用-y替代。其他模式:--approval-mode yolo、default。auto_edit
速率限制:免费版有使用限制。CLI会自动以指数退避策略重试。可能会收到类似“配额将在X秒后重置”的提示。
4. Output Processing
4. 输出处理
For JSON output (), parse:
-o jsonjson
{
"response": "actual content",
"stats": {
"models": { "tokens": {...} },
"tools": { "byName": {...} }
}
}对于JSON格式输出(),可解析如下结构:
-o jsonjson
{
"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 textbash
gemini "创建[描述]并包含[特性]。输出完整文件内容。" --approval-mode yolo -o textCode Review
代码审查
bash
gemini "Review [file] for: 1) features, 2) bugs/security issues, 3) improvements" -o textbash
gemini "审查[文件]的以下内容:1) 功能,2) Bug/安全问题,3) 优化建议" -o textBug Fixing
Bug修复
bash
gemini "Fix these bugs in [file]: [list]. Apply fixes now." --approval-mode yolo -o textbash
gemini "修复[文件]中的以下Bug:[列表]。立即应用修复。" --approval-mode yolo -o textTest Generation
测试用例生成
bash
gemini "Generate [Jest/pytest] tests for [file]. Focus on [areas]." --approval-mode yolo -o textbash
gemini "为[文件]生成[Jest/pytest]测试用例。重点覆盖[领域]。" --approval-mode yolo -o textDocumentation
文档生成
bash
gemini "Generate JSDoc for all functions in [file]. Output as markdown." --approval-mode yolo -o textbash
gemini "为[文件]中的所有函数生成JSDoc。以Markdown格式输出。" --approval-mode yolo -o textArchitecture Analysis
架构分析
bash
gemini "Use codebase_investigator to analyze this project" -o textbash
gemini "使用codebase_investigator分析此项目" -o textWeb Research
网络研究
bash
gemini "What are the latest [topic]? Use Google Search." -o textbash
gemini "[主题]的最新信息是什么?使用Google Search查询。" -o textFaster Model (Simple Tasks)
快速模型(简单任务)
bash
gemini "[prompt]" -m gemini-2.5-flash -o textbash
gemini "[prompt]" -m gemini-2.5-flash -o textError Handling
错误处理
Rate Limit Exceeded
超出速率限制
- CLI auto-retries with exponential backoff
- Use for lower priority tasks (different quota)
-m gemini-2.5-flash - 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 for config issues
~/.gemini/settings.json
- 检查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
undefinedbash
undefined1. 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
undefinedgemini "修复[文件]中的[问题]。立即应用。" --approval-mode yolo -o text
undefinedBackground 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工具监控
undefinedundefinedGemini's Unique Capabilities
Gemini的独特能力
These tools are available only through Gemini:
- google_web_search - Real-time internet search via Google
- codebase_investigator - Deep architectural analysis (experimental agent, may require opt-in)
- save_memory - Cross-session persistent memory
以下工具仅通过Gemini提供:
- google_web_search - 通过Google进行实时互联网搜索
- codebase_investigator - 深度架构分析(实验性Agent,可能需要手动启用)
- save_memory - 跨会话持久化记忆
Model Selection
模型选择
| Model | Use Case |
|---|---|
| Smart routing — auto-selects Flash or Pro based on task complexity |
| Complex reasoning tasks |
| Quick tasks, lower latency |
| Latest capabilities (requires Google AI Ultra or paid API key) |
| Latest Flash model (requires Preview Features enabled) |
| 模型 | 使用场景 |
|---|---|
| 智能路由——根据任务复杂度自动选择Flash或Pro |
| 复杂推理任务 |
| 快速任务,低延迟 |
| 最新功能(需要Google AI Ultra或付费API密钥) |
| 最新Flash模型(需要启用预览功能) |
Configuration
配置
Project Context (Optional)
项目上下文(可选)
Create in project root for persistent context that Gemini will automatically read.
.gemini/GEMINI.md在项目根目录创建,Gemini会自动读取该文件中的持久化上下文。
.gemini/GEMINI.mdSession Management
会话管理
List sessions:
Resume session:
gemini --list-sessionsecho "follow-up" | gemini -r [index] -o text列出会话:
恢复会话:
gemini --list-sessionsecho "follow-up" | gemini -r [index] -o textSee Also
另请参阅
- - Complete command and flag reference
reference.md - - Prompt templates for common operations
templates.md - - Advanced integration patterns
patterns.md - - Gemini's built-in tools documentation
tools.md
- - 完整命令及参数参考
reference.md - - 常见操作的Prompt模板
templates.md - - 高级集成模式
patterns.md - - Gemini内置工具文档
tools.md