ogt-cli-gemini
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseGemini CLI Skill
Gemini CLI 技能
Run Google's Gemini CLI to leverage Gemini 3 models directly from the terminal.
运行Google的Gemini CLI,直接在终端中调用Gemini 3模型。
When to Use
适用场景
- Code understanding and generation
- Multi-file analysis and refactoring
- Debugging with natural language
- Research with Google Search grounding
- Automation and scripting tasks
- Tasks benefiting from 1M token context window
- 代码理解与生成
- 多文件分析与重构
- 自然语言调试
- 基于Google搜索的研究工作
- 自动化与脚本任务
- 需要100万token上下文窗口的任务
Quick Start
快速开始
Interactive mode
交互模式
bash
geminibash
geminiOne-shot query (non-interactive)
单次查询(非交互模式)
bash
gemini -p "Your prompt here"bash
gemini -p "Your prompt here"With specific model
指定模型
bash
gemini -p "Complex task" -m gemini-2.5-pro
gemini -p "Quick task" -m gemini-2.5-flashbash
gemini -p "Complex task" -m gemini-2.5-pro
gemini -p "Quick task" -m gemini-2.5-flashJSON output (for parsing)
JSON格式输出(用于解析)
bash
gemini -p "Your prompt" --output-format jsonbash
gemini -p "Your prompt" --output-format jsonStream JSON (real-time events)
流式JSON输出(实时事件)
bash
gemini -p "Run tests and deploy" --output-format stream-jsonbash
gemini -p "Run tests and deploy" --output-format stream-jsonInstallation
安装方法
bash
undefinedbash
undefinednpm (recommended)
npm(推荐方式)
npm install -g @google/gemini-cli
npm install -g @google/gemini-cli
Homebrew (macOS/Linux)
Homebrew(macOS/Linux)
brew install gemini-cli
brew install gemini-cli
Run without installing
无需安装直接运行
npx @google/gemini-cli
undefinednpx @google/gemini-cli
undefinedKey Options
核心选项
| Option | Description |
|---|---|
| Non-interactive mode, print response and exit |
| Model: |
| |
| Include additional directories |
| Auto-approve tool calls (use with caution) |
| Run in sandbox mode (safer) |
| 选项 | 说明 |
|---|---|
| 非交互模式,输出响应后退出 |
| 模型选项: |
| |
| 包含额外的目录 |
| 自动批准工具调用(谨慎使用) |
| 在沙箱模式下运行(更安全) |
Authentication
认证方式
Option 1: Google OAuth (Recommended)
方式1:Google OAuth(推荐)
bash
geminibash
geminiFollow browser auth flow on first run
首次运行时按照浏览器中的认证流程操作
- **Free tier:** 60 req/min, 1,000 req/day
- No API key needed- **免费层级:** 每分钟60次请求,每天1000次请求
- 无需API密钥Option 2: Gemini API Key
方式2:Gemini API密钥
bash
export GEMINI_API_KEY="YOUR_API_KEY"
geminiGet key from: https://aistudio.google.com/apikey
bash
export GEMINI_API_KEY="YOUR_API_KEY"
geminiOption 3: Vertex AI (Enterprise)
方式3:Vertex AI(企业版)
bash
export GOOGLE_API_KEY="YOUR_API_KEY"
export GOOGLE_GENAI_USE_VERTEXAI=true
geminibash
export GOOGLE_API_KEY="YOUR_API_KEY"
export GOOGLE_GENAI_USE_VERTEXAI=true
geminiWorking with Files
文件操作
Gemini CLI can read and work with files in the current directory:
bash
undefinedGemini CLI可以读取并处理当前目录下的文件:
bash
undefinedAnalyze codebase
分析代码库
cd /path/to/project && gemini -p "Explain this codebase architecture"
cd /path/to/project && gemini -p "Explain this codebase architecture"
Include multiple directories
包含多个目录
gemini --include-directories ../lib,../docs -p "Review the API"
gemini --include-directories ../lib,../docs -p "Review the API"
Pipe file content
管道传输文件内容
cat myfile.py | gemini -p "Review this code"
undefinedcat myfile.py | gemini -p "Review this code"
undefinedBuilt-in Tools
内置工具
Gemini CLI has built-in capabilities:
- Google Search: Ground responses with real-time web data
- File Operations: Read, write, edit files
- Shell Commands: Execute terminal commands
- Web Fetching: Retrieve content from URLs
Gemini CLI具备以下内置功能:
- Google搜索: 结合实时网络数据生成响应
- 文件操作: 读取、写入、编辑文件
- Shell命令: 执行终端命令
- 网页抓取: 获取URL中的内容
For Sub-Agent Delegation
子代理任务分发
When spawning Gemini CLI for background work:
bash
undefined当启动Gemini CLI执行后台任务时:
bash
undefinedRun with timeout
设置超时时间运行
timeout 300 gemini -p "Complete this task..." 2>&1
timeout 300 gemini -p "Complete this task..." 2>&1
Capture structured output
捕获结构化输出
gemini -p "Generate a report" --output-format json > result.json
gemini -p "Generate a report" --output-format json > result.json
Auto-approve for automation (careful!)
自动化场景下自动批准操作(谨慎使用!)
gemini -p "Run the build" --yolo
undefinedgemini -p "Run the build" --yolo
undefinedScript: Run Gemini Task
脚本:运行Gemini任务
Use the bundled script for reliable sub-agent execution:
bash
node {baseDir}/scripts/run-gemini-task.cjs "Your task prompt" [options]Options:
- — Model to use (default: gemini-2.5-flash)
--model <model> - — Timeout in seconds (default: 300)
--timeout <secs> - — Output in JSON format
--json - — Working directory
--workdir <path>
The script handles:
- Timeout protection
- Error capture and formatting
- Clean output for parsing
- Exit code propagation
使用内置脚本实现可靠的子代理执行:
bash
node {baseDir}/scripts/run-gemini-task.cjs "Your task prompt" [options]选项说明:
- — 使用的模型(默认:gemini-2.5-flash)
--model <model> - — 超时时间(秒,默认:300)
--timeout <secs> - — 以JSON格式输出
--json - — 工作目录
--workdir <path>
该脚本支持:
- 超时保护
- 错误捕获与格式化
- 便于解析的纯净输出
- 退出码传递
Model Selection
模型选择
| Model | Best For |
|---|---|
| Fast, cost-effective, everyday tasks |
| Complex reasoning, large context, nuanced tasks |
| 模型 | 最佳适用场景 |
|---|---|
| 快速、高性价比的日常任务 |
| 复杂推理、大上下文、精细化任务 |
Context File (GEMINI.md)
上下文文件(GEMINI.md)
Create a file in your project root to customize behavior:
GEMINI.mdmarkdown
undefined在项目根目录创建文件,自定义Gemini的行为:
GEMINI.mdmarkdown
undefinedProject: My App
Project: My App
Guidelines
Guidelines
- Use TypeScript for all new code
- Follow existing patterns in src/
- Run tests before committing
- Use TypeScript for all new code
- Follow existing patterns in src/
- Run tests before committing
Architecture
Architecture
- Frontend: React + Vite
- Backend: Node.js + Express
Gemini will automatically read this for project context.- Frontend: React + Vite
- Backend: Node.js + Express
Gemini会自动读取该文件获取项目上下文信息。Tips
使用技巧
- Use for scripts — Non-interactive mode for automation
-p - Set timeouts for long-running tasks
- Use when parsing results programmatically
--output-format json - Working directory matters — Gemini sees files relative to cwd
- Use carefully — Auto-approves all tool calls
--yolo - Google Search grounding — Great for real-time info queries
- 脚本中使用选项 — 非交互模式适用于自动化场景
-p - 为长时间运行的任务设置超时时间
- 编程解析结果时使用选项
--output-format json - 注意工作目录 — Gemini会基于当前工作目录识别文件
- 谨慎使用选项 — 会自动批准所有工具调用
--yolo - Google搜索 grounding — 非常适合实时信息查询
Rate Limits (Free Tier)
免费层级速率限制
- 60 requests per minute
- 1,000 requests per day
- 1M token context window
- 每分钟60次请求
- 每天1000次请求
- 100万token上下文窗口
Comparison with Claude CLI
与Claude CLI的对比
| Feature | Gemini CLI | Claude CLI |
|---|---|---|
| Free tier | ✅ 1000/day | ✅ Limited |
| Context window | 1M tokens | 200K tokens |
| Google Search | ✅ Built-in | ❌ |
| Shell execution | ✅ Built-in | ✅ Built-in |
| MCP support | ✅ | ✅ |
| Auth | Google OAuth | Anthropic OAuth |
| 功能 | Gemini CLI | Claude CLI |
|---|---|---|
| 免费层级 | ✅ 每天1000次 | ✅ 有限额度 |
| 上下文窗口 | 100万token | 20万token |
| Google搜索 | ✅ 内置 | ❌ |
| Shell命令执行 | ✅ 内置 | ✅ 内置 |
| MCP支持 | ✅ | ✅ |
| 认证方式 | Google OAuth | Anthropic OAuth |
Troubleshooting
故障排查
Authentication Issues
认证问题
bash
undefinedbash
undefinedClear cached auth
清除缓存的认证信息
rm -rf ~/.gemini-cli
rm -rf ~/.gemini-cli
Re-authenticate
重新认证
gemini
undefinedgemini
undefinedCommand Not Found
命令未找到
bash
undefinedbash
undefinedCheck installation
检查安装情况
which gemini
which gemini
Reinstall
重新安装
npm install -g @google/gemini-cli
undefinednpm install -g @google/gemini-cli
undefined