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.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
理想使用场景
-
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]" --yolo -o text 2>&1Key flags:
- or
--yolo: Auto-approve all tool calls-y - : Human-readable output
-o text - : Structured output with stats
-o json - : Use faster model for simple tasks
-m gemini-2.5-flash
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 (), 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." --yolo -o textbash
gemini "创建具备[特性]的[描述内容]。输出完整文件内容。" --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." --yolo -o textbash
gemini "修复[文件]中的以下Bug:[列表]。立即应用修复。" --yolo -o textTest Generation
测试生成
bash
gemini "Generate [Jest/pytest] tests for [file]. Focus on [areas]." --yolo -o textbash
gemini "为[文件]生成[Jest/pytest]测试用例。重点覆盖[领域]。" --yolo -o textDocumentation
文档生成
bash
gemini "Generate JSDoc for all functions in [file]. Output as markdown." --yolo -o textbash
gemini "为[文件]中所有函数生成JSDoc。以Markdown格式输出。" --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 backoff
- Use for lower priority tasks
-m gemini-2.5-flash - 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]" --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
undefinedgemini "修复[文件]中的[问题列表]。立即应用修复。" --yolo -o text
undefinedBackground 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工具监控执行情况
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
- save_memory - Cross-session persistent memory
以下工具仅通过Gemini提供:
- google_web_search - 通过Google实现实时互联网搜索
- codebase_investigator - 深度架构分析
- save_memory - 跨会话持久化记忆
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 "后续指令" | gemini -r [索引] -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 - - 常见操作的提示词模板
templates.md - - 高级集成模式
patterns.md - - Gemini内置工具文档
tools.md