Gemini CLI Skill
A comprehensive guide for using the Gemini CLI tool to build, debug & deploy with AI directly from the command line.
What It Does
Gemini CLI enables command-line access to Google's Gemini models for:
- - Query Codebases — Analyze and understand large codebases
- Generate from Images — Create code, docs, or apps from screenshot/images
- Generate from PDFs — Extract and build from PDF documents
- Automate Workflows — Chain AI tasks for complex automation
- Interactive Shell — Chat with Gemini about your project
- Debugging — Get AI-powered debugging and code review
Perfect for developers who want to leverage AI without leaving the terminal.
⚠️ Trust Model & Security Declaration
Metadata Declaration:
- - Type: AI CLI tool (Google-managed, official)
- External Binary:
gemini (official Google package) - Manages Credentials: No (credentials stored locally as env var)
- Credential Storage: Environment variable (GEMINIAPIKEY)
- Capabilities: Code analysis, generation, automation
- Limitations: Requires internet, API quota limits apply
Authentication Model:
This tool uses your Gemini API Key passed as an environment variable:
CODEBLOCK0
Key Points:
- - ✅ Official Google tool (not third-party)
- ✅ Credentials stored as environment variable (not in tool)
- ✅ You control scope: set env var only when needed
- ✅ No persistent credential storage in ~/.gemini/ directory
- ✅ Direct calls to Gemini API endpoints (googleapis.com)
What This Skill Does:
- - ✅ Queries your codebase and documents with Gemini models
- ✅ Generates code/apps from images and PDFs
- ✅ Runs automated workflows using AI
- ✅ Provides interactive debugging and code review
- ❌ Does NOT store credentials
- ❌ Does NOT cache sensitive data
- ❌ Does NOT modify your system beyond running commands
Requirements
Binaries (required):
- -
gemini — Gemini CLI tool (installed via npm) - INLINECODE2 — Node.js 20.0.0+ (usually pre-installed)
Credentials (environment variable):
- -
GEMINI_API_KEY — Your Gemini API key from Google AI Studio or Google Cloud
System Requirements:
- - macOS 15+, Windows 11 24H2+, or Ubuntu 20.04+
- 4GB+ RAM (casual usage), 16GB+ (power usage with large codebases)
- Internet connection required
Optional:
- -
bash, zsh, or PowerShell — Any modern shell
Installation & Setup
1. Check Installation
Gemini CLI is usually pre-installed:
CODEBLOCK1
If not installed:
CODEBLOCK2
2. Set API Key (One-time per session)
CODEBLOCK3
Or use it inline:
CODEBLOCK4
To find your API key:
- - Go to https://aistudio.google.com/app/apikey
- Create or copy your API key
- Store securely (don't commit to git)
3. Verify Installation
CODEBLOCK5
Quick Start
Interactive Shell (Ask Gemini Questions)
CODEBLOCK6
Then type your questions about code, architecture, debugging, etc.
Query a Codebase
CODEBLOCK7
Generate from Image
CODEBLOCK8
Generate from PDF
CODEBLOCK9
Automate a Workflow
CODEBLOCK10
Get Help
CODEBLOCK11
Common Commands
Interactive
CODEBLOCK12
Code Analysis
CODEBLOCK13
Code Generation
CODEBLOCK14
Batch Operations
CODEBLOCK15
Configuration
- - API Key: Set via
GEMINI_API_KEY environment variable - Temp Storage: Uses system temp directory (auto-cleaned)
- No persistent config: Unlike mirocli, Gemini CLI doesn't store auth locally
To persist API key across sessions (optional):
Add to your ~/.bashrc, ~/.zshrc, or equivalent:
CODEBLOCK16
⚠️ Security warning: Only do this if your shell profile is secure and not synced to public repos.
Global Options
CODEBLOCK17
Help & Documentation
CODEBLOCK18
Official Docs: https://geminicli.com/docs
Tips & Tricks
- 1. Use with your codebase:
CODEBLOCK19
- 2. Chain commands:
CODEBLOCK20
- 3. Batch process files:
CODEBLOCK21
- 4. Store prompts in files:
CODEBLOCK22
When to Use Gemini CLI vs Other Tools
| Task | Gemini CLI | Cursor/IDE | Web UI |
|---|
| Quick code questions | ✅ Fast | ✅ Integrated | ❌ Context switch |
| Large codebase analysis |
✅ Better | ✅ Native | ❌ Limited |
| Generate from images | ✅ Works | ✅ Works | ✅ Works |
| Batch automation | ✅ Perfect | ❌ Manual | ❌ Manual |
| Interactive chat | ✅ Terminal | ✅ IDE | ✅ Browser |
| Scripting workflows | ✅ Yes | ❌ No | ❌ No |
Status & Next Steps
✅ Installation: Pre-installed (v0.28.2)
✅ Configuration: Ready to use with GEMINIAPIKEY environment variable
✅ Authentication: Set env var before use (no interactive steps needed)
Testing: Run gemini --help to verify installation
Usage: Set API key and start using:
export GEMINI_API_KEY="your-key-here"
gemini chat
Setup Date: 2026-03-14
Status: Ready (no authentication required — env var based)
技能名称: gemini-cli
详细描述:
Gemini CLI 技能
一份关于使用 Gemini CLI 工具从命令行直接构建、调试和部署 AI 的全面指南。
功能概述
Gemini CLI 允许通过命令行访问 Google 的 Gemini 模型,用于:
- - 查询代码库 — 分析和理解大型代码库
- 从图像生成 — 根据截图/图像创建代码、文档或应用
- 从 PDF 生成 — 从 PDF 文档中提取和构建内容
- 自动化工作流 — 串联 AI 任务实现复杂自动化
- 交互式 Shell — 与 Gemini 讨论您的项目
- 调试 — 获得 AI 驱动的调试和代码审查
非常适合希望在不离开终端的情况下利用 AI 的开发者。
⚠️ 信任模型与安全声明
元数据声明:
- - 类型:AI CLI 工具(Google 管理,官方)
- 外部二进制文件:gemini(官方 Google 包)
- 管理凭据:否(凭据以环境变量形式本地存储)
- 凭据存储:环境变量(GEMINIAPIKEY)
- 能力:代码分析、生成、自动化
- 限制:需要互联网,受 API 配额限制
认证模型:
此工具使用您的 Gemini API 密钥,通过环境变量传递:
bash
GEMINIAPIKEY= gemini
关键点:
- - ✅ 官方 Google 工具(非第三方)
- ✅ 凭据以环境变量形式存储(不在工具内)
- ✅ 您控制范围:仅在需要时设置环境变量
- ✅ 在 ~/.gemini/ 目录中没有持久化凭据存储
- ✅ 直接调用 Gemini API 端点(googleapis.com)
此技能的功能:
- - ✅ 使用 Gemini 模型查询您的代码库和文档
- ✅ 从图像和 PDF 生成代码/应用
- ✅ 使用 AI 运行自动化工作流
- ✅ 提供交互式调试和代码审查
- ❌ 不存储凭据
- ❌ 不缓存敏感数据
- ❌ 除运行命令外,不修改您的系统
要求
二进制文件(必需):
- - gemini — Gemini CLI 工具(通过 npm 安装)
- node — Node.js 20.0.0+(通常预装)
凭据(环境变量):
- - GEMINIAPIKEY — 来自 Google AI Studio 或 Google Cloud 的 Gemini API 密钥
系统要求:
- - macOS 15+、Windows 11 24H2+ 或 Ubuntu 20.04+
- 4GB+ 内存(日常使用),16GB+(处理大型代码库的高强度使用)
- 需要互联网连接
可选:
- - bash、zsh 或 PowerShell — 任何现代 Shell
安装与设置
1. 检查安装
Gemini CLI 通常预装:
bash
gemini --version
如果未安装:
bash
npm install -g @google/gemini-cli
或者
brew install gemini-cli
2. 设置 API 密钥(每次会话一次)
bash
export GEMINIAPIKEY=
或者内联使用:
bash
GEMINIAPIKEY= gemini
查找您的 API 密钥:
- - 访问 https://aistudio.google.com/app/apikey
- 创建或复制您的 API 密钥
- 安全存储(不要提交到 git)
3. 验证安装
bash
gemini --version
gemini --help
快速开始
交互式 Shell(向 Gemini 提问)
bash
gemini chat
然后输入关于代码、架构、调试等问题。
查询代码库
bash
gemini code --prompt 这个函数是做什么的?
从图像生成
bash
gemini create --from-image ./screenshot.png --prompt 根据这个设计创建一个 React 组件
从 PDF 生成
bash
gemini create --from-pdf ./document.pdf --prompt 根据这个文档创建 API 规范
自动化工作流
bash
gemini workflow --steps 1) 分析代码, 2) 识别问题, 3) 建议修复
获取帮助
bash
gemini --help
gemini --help
常用命令
交互式
bash
gemini chat # 启动交互式聊天
gemini chat --context ./src # 带代码库上下文的聊天
代码分析
bash
gemini code --prompt 分析 ./file.js
gemini code --explain ./function.ts
gemini code --review ./pull_request.patch
代码生成
bash
gemini create --from-image ./design.png
gemini create --from-pdf ./spec.pdf
gemini create --template react --prompt 计数器应用
批量操作
bash
gemini batch --input ./tasks.json --output ./results.json
配置
- - API 密钥: 通过 GEMINIAPIKEY 环境变量设置
- 临时存储: 使用系统临时目录(自动清理)
- 无持久化配置: 与 mirocli 不同,Gemini CLI 不在本地存储认证信息
跨会话持久化 API 密钥(可选):
添加到您的 ~/.bashrc、~/.zshrc 或等效文件:
bash
export GEMINIAPIKEY=
⚠️ 安全警告: 仅在您的 Shell 配置文件安全且未同步到公共仓库时执行此操作。
全局选项
bash
--version # 显示版本
--help # 显示帮助
--verbose # 详细输出
--api-key # 直接传递 API 密钥(覆盖环境变量)
--model # 指定 Gemini 模型(默认:gemini-2.5-pro)
帮助与文档
bash
gemini --help # 全局帮助
gemini --help # 命令特定帮助
官方文档: https://geminicli.com/docs
技巧与窍门
- 1. 与您的代码库一起使用:
bash
cd /path/to/your/project
gemini chat --context ./src
- 2. 串联命令:
bash
gemini code --review ./changes.patch | tee review.txt
- 3. 批量处理文件:
bash
for file in src/*.js; do
gemini code --explain $file > docs/${file}.md
done
- 4. 将提示存储在文件中:
bash
cat prompt.txt | gemini chat
何时使用 Gemini CLI 与其他工具
| 任务 | Gemini CLI | Cursor/IDE | Web UI |
|---|
| 快速代码问题 | ✅ 快速 | ✅ 集成 | ❌ 上下文切换 |
| 大型代码库分析 |
✅ 更好 | ✅ 原生 | ❌ 有限 |
| 从图像生成 | ✅ 可行 | ✅ 可行 | ✅ 可行 |
| 批量自动化 | ✅ 完美 | ❌ 手动 | ❌ 手动 |
| 交互式聊天 | ✅ 终端 | ✅ IDE | ✅ 浏览器 |
| 脚本化工作流 | ✅ 是 | ❌ 否 | ❌ 否 |
状态与后续步骤
✅ 安装: 预装(v0.28.2)
✅ 配置: 准备就绪,使用 GEMINIAPIKEY 环境变量
✅ 认证: 使用前设置环境变量(无需交互步骤)
测试: 运行 gemini --help 验证安装
使用: 设置 API 密钥并开始使用:
bash
export GEMINIAPIKEY=your-key-here
gemini chat
设置日期: 2026-03-14
状态: 就绪(无需认证 — 基于环境变量)