📦 google-gemini/gemini-cli:将 Gemini 的强大功能带入终端的开源 AI 智能体
英文标题:📦 google-gemini/gemini-cli
Gemini CLI 是 Google 开源的终端 AI 智能体,让开发者能直接在命令行中与 Gemini 模型交互。它提供免费额度(每分钟 60 次、每天 1,000 次请求),可访问拥有 1M token 上下文窗口的 Gemini 3 模型,并内置 Google 搜索、文件操作、Shell 命令等工具,同时通过 MCP 协议支持自定义扩展。该项目支持 OAuth、API 密钥和 Vertex AI 等多种认证方式,可集成 GitHub Actions 实现自动化代码审查与问题分诊,显著提升开发者的工作流效率。Gemini CLI 采用 Apache 2.0 许可证,每周发布预览版与稳定版更新,由社区共同维护。
59.8 KB
中文
Gemini CLI 是一个开源的 AI 智能体,它将 Gemini 的强大功能直接带入您的终端。它提供了轻量级的 Gemini 访问方式,为您提供从提示词到模型的最直接路径。
在文档中全面了解 Gemini CLI。
- 🎯 免费额度:使用个人 Google 账户,每分钟 60 次请求,每天 1,000 次请求。
- 🧠 强大的 Gemini 3 模型:访问改进的推理能力和 1M token 上下文窗口。
- 🔧 内置工具:Google 搜索 grounding、文件操作、shell 命令、网页抓取。
- 🔌 可扩展:支持 MCP(模型上下文协议),用于自定义集成。
- 💻 终端优先:为生活在命令行中的开发者设计。
- 🛡️ 开源:Apache 2.0 许可证。
有关推荐系统规格和详细安装指南,请参阅 Gemini CLI 安装、执行与发布说明。
使用 npx(无需安装)
npx @google/gemini-cli
使用 npm 全局安装
npm install -g @google/gemini-cli
使用 Homebrew 全局安装(macOS/Linux)
使用 MacPorts 全局安装(macOS)
sudo port install gemini-cli
使用 Anaconda 安装(适用于受限环境)
# 创建并激活新环境
conda create -y -n gemini_env -c conda-forge nodejs
conda activate gemini_env
# 在环境中通过 npm 全局安装 Gemini CLI
npm install -g @google/gemini-cli
查看发布说明了解详情。
新的预览版将在每周二 UTC 23:59 发布。这些版本尚未经过全面审查,可能包含回退或其他未解决的问题。请帮助测试并使用 preview 标签安装。
npm install -g @google/gemini-cli@preview
-
新的稳定版将在每周二 UTC 20:00 发布,这是上周
preview版的正式版加上所有错误修复和验证。使用latest标签。npm install -g @google/gemini-cli@latest
-
每日构建版将在每天 UTC 00:00 发布。这将包含发布时 main 分支的所有更改。应假设存在未完成的验证和问题。使用
nightly标签。npm install -g @google/gemini-cli@nightly
代码理解与生成
-
查询和编辑大型代码库
-
使用多模态功能从 PDF、图片或草图生成新应用
-
用自然语言调试和排除故障
-
自动化操作任务,如查询拉取请求或处理复杂的变基
-
使用 MCP 服务器连接新能力,包括使用 Imagen、Veo 或 Lyria 进行媒体生成
-
以非交互方式在脚本中运行,实现工作流自动化
-
利用内置的 Google 搜索 为查询提供实时信息
-
对话检查点功能,保存和恢复复杂会话
-
自定义上下文文件(GEMINI.md),为项目定制行为
使用 Gemini CLI GitHub Action 将 Gemini CLI 直接集成到您的 GitHub 工作流中:
- 拉取请求审查:自动代码审查,附带基于上下文的反馈和建议
- 问题分诊:基于内容分析自动为 GitHub 问题添加标签和优先级
- 按需协助:在问题和拉取请求中通过提及
@gemini-cli来获取调试、解释或任务委派方面的帮助 - 自定义工作流:构建自动化、定时和按需的工作流,满足团队需求
选择最适合您需求的认证方式:
选项 1:使用 Google 登录(通过 Google 账户进行 OAuth 登录)
✨ 最适合: 个人开发者以及拥有 Gemini Code Assist 许可证的任何人。(详情请参阅配额限制和服务条款)
好处:
- 免费额度:每分钟 60 次请求,每天 1,000 次请求
- Gemini 3 模型,拥有 1M token 上下文窗口
- 无需管理 API 密钥——只需使用 Google 账户登录
- 自动更新到最新模型
启动 Gemini CLI,然后选择 使用 Google 登录,并在提示时按照浏览器身份验证流程操作
如果您使用的是企业付费的 Code Assist 许可证,请记得设置 Google Cloud 项目
# 设置您的 Google Cloud 项目
export GOOGLE_CLOUD_PROJECT="YOUR_PROJECT_ID"
gemini
选项 2:Gemini API 密钥
✨ 最适合: 需要对特定模型进行控制或访问付费层的开发者
好处:
-
免费额度:每天使用 Gemini 3(混合 flash 和 pro)的 1000 次请求
-
模型选择:选择特定的 Gemini 模型
-
基于用量的计费:需要时升级以获得更高限制
从 https://aistudio.google.com/apikey 获取密钥
export GEMINI_API_KEY="YOUR_API_KEY" gemini
选项 3:Vertex AI
✨ 最适合: 企业团队和生产工作负载
好处:
-
企业功能:高级安全性和合规性
-
可扩展:通过计费账户获得更高的速率限制
-
集成:与现有的 Google Cloud 基础设施配合使用
从 Google Cloud Console 获取密钥
export GOOGLE_API_KEY="YOUR_API_KEY" export GOOGLE_GENAI_USE_VERTEXAI=true gemini
对于 Google Workspace 账户和其他认证方式,请参阅认证指南。
在当前目录启动
包含多个目录
gemini --include-directories ../lib,../docs
gemini -m gemini-2.5-flash
非交互模式(用于脚本)
获取简单的文本响应:
gemini -p "Explain the architecture of this codebase"
对于更高级的脚本编写(包括如何解析 JSON 和处理错误),请使用 --output-format json 标志获取结构化输出:
gemini -p "Explain the architecture of this codebase" --output-format json
对于实时事件流(适用于监控长时间运行的操作),使用 --output-format stream-json 获取以换行分隔的 JSON 事件:
gemini -p "Run tests and deploy" --output-format stream-json
cd new-project/
gemini
> Write me a Discord bot that answers questions using a FAQ.md file I will provide
git clone https://github.com/google-gemini/gemini-cli
cd gemini-cli
gemini
> Give me a summary of all of the changes that went in yesterday
故障排除与支持
在 ~/.gemini/settings.json 中配置 MCP 服务器,用自定义工具扩展 Gemini CLI:
> @github List my open pull requests
> @slack Send a summary of today's commits to #dev channel
> @database Run a query to find inactive users
查看 MCP 服务器集成指南 了解设置说明。
我们欢迎贡献!Gemini CLI 完全开源(Apache 2.0),我们鼓励社区:
- 报告错误和建议功能。
- 改进文档。
- 提交代码改进。
- 分享您的 MCP 服务器和扩展。
请参阅我们的贡献指南,了解开发环境搭建、编码标准以及如何提交拉取请求。
查看我们的官方路线图 了解计划功能和优先级。
请参阅卸载指南 了解移除说明。
Built with ❤️ by Google and the open source community
English / 原文
Gemini CLI is an open-source AI agent that brings the power of Gemini directly into your terminal. It provides lightweight access to Gemini, giving you the most direct path from your prompt to our model.
Learn all about Gemini CLI in our documentation.
- 🎯 Free tier : 60 requests/min and 1,000 requests/day with personal Google account.
- 🧠 Powerful Gemini 3 models : Access to improved reasoning and 1M token context window.
- 🔧 Built-in tools : Google Search grounding, file operations, shell commands, web fetching.
- 🔌 Extensible : MCP (Model Context Protocol) support for custom integrations.
- 💻 Terminal-first : Designed for developers who live in the command line.
- 🛡️ Open source : Apache 2.0 licensed.
See Gemini CLI installation, execution, and releases for recommended system specifications and a detailed installation guide.
# Using npx (no installation required)
npx @google/gemini-cli
Install globally with npm
npm install -g @google/gemini-cli
Install globally with Homebrew (macOS/Linux)
Install globally with MacPorts (macOS)
sudo port install gemini-cli
Install with Anaconda (for restricted environments)
# Create and activate a new environment
conda create -y -n gemini_env -c conda-forge nodejs
conda activate gemini_env
# Install Gemini CLI globally via npm (inside the environment)
npm install -g @google/gemini-cli
See Releases for more details.
New preview releases will be published each week at UTC 23:59 on Tuesdays. These releases will not have been fully vetted and may contain regressions or other outstanding issues. Please help us test and install with preview tag.
npm install -g @google/gemini-cli@preview
-
New stable releases will be published each week at UTC 20:00 on Tuesdays, this will be the full promotion of last week's
previewrelease + any bug fixes and validations. Uselatesttag.npm install -g @google/gemini-cli@latest
-
New releases will be published each day at UTC 00:00. This will be all changes from the main branch as represented at time of release. It should be assumed there are pending validations and issues. Use
nightlytag.npm install -g @google/gemini-cli@nightly
Code Understanding & Generation
-
Query and edit large codebases
-
Generate new apps from PDFs, images, or sketches using multimodal capabilities
-
Debug issues and troubleshoot with natural language
-
Automate operational tasks like querying pull requests or handling complex rebases
-
Use MCP servers to connect new capabilities, including media generation with Imagen, Veo or Lyria
-
Run non-interactively in scripts for workflow automation
-
Ground your queries with built-in Google Search for real-time information
-
Conversation checkpointing to save and resume complex sessions
-
Custom context files (GEMINI.md) to tailor behavior for your projects
Integrate Gemini CLI directly into your GitHub workflows with Gemini CLI GitHub Action:
- Pull Request Reviews : Automated code review with contextual feedback and suggestions
- Issue Triage : Automated labeling and prioritization of GitHub issues based on content analysis
- On-demand Assistance : Mention
@gemini-cliin issues and pull requests for help with debugging, explanations, or task delegation - Custom Workflows : Build automated, scheduled and on-demand workflows tailored to your team's needs
Choose the authentication method that best fits your needs:
Option 1: Sign in with Google (OAuth login using your Google Account)
✨ Best for: Individual developers as well as anyone who has a Gemini Code Assist License. (see quota limits and terms of service for details)
Benefits:
- Free tier : 60 requests/min and 1,000 requests/day
- Gemini 3 models with 1M token context window
- No API key management - just sign in with your Google account
- Automatic updates to latest models
Start Gemini CLI, then choose Sign in with Google and follow the browser authentication flow when prompted
If you are using a paid Code Assist License from your organization, remember to set the Google Cloud Project
# Set your Google Cloud Project
export GOOGLE_CLOUD_PROJECT="YOUR_PROJECT_ID"
gemini
✨ Best for: Developers who need specific model control or paid tier access
Benefits:
-
Free tier : 1000 requests/day with Gemini 3 (mix of flash and pro)
-
Model selection : Choose specific Gemini models
-
Usage-based billing : Upgrade for higher limits when needed
Get your key from https://aistudio.google.com/apikey
export GEMINI_API_KEY="YOUR_API_KEY" gemini
✨ Best for: Enterprise teams and production workloads
Benefits:
-
Enterprise features : Advanced security and compliance
-
Scalable : Higher rate limits with billing account
-
Integration : Works with existing Google Cloud infrastructure
Get your key from Google Cloud Console
export GOOGLE_API_KEY="YOUR_API_KEY" export GOOGLE_GENAI_USE_VERTEXAI=true gemini
For Google Workspace accounts and other authentication methods, see the authentication guide.
Start in current directory
Include multiple directories
gemini --include-directories ../lib,../docs
gemini -m gemini-2.5-flash
Non-interactive mode for scripts
Get a simple text response:
gemini -p "Explain the architecture of this codebase"
For more advanced scripting, including how to parse JSON and handle errors, use the --output-format json flag to get structured output:
gemini -p "Explain the architecture of this codebase" --output-format json
For real-time event streaming (useful for monitoring long-running operations), use --output-format stream-json to get newline-delimited JSON events:
gemini -p "Run tests and deploy" --output-format stream-json
cd new-project/
gemini
> Write me a Discord bot that answers questions using a FAQ.md file I will provide
git clone https://github.com/google-gemini/gemini-cli
cd gemini-cli
gemini
> Give me a summary of all of the changes that went in yesterday
Troubleshooting & Support
- Troubleshooting Guide - Common issues and solutions.
- FAQ - Frequently asked questions.
- Use
/bugcommand to report issues directly from the CLI.
Configure MCP servers in ~/.gemini/settings.json to extend Gemini CLI with custom tools:
> @github List my open pull requests
> @slack Send a summary of today's commits to #dev channel
> @database Run a query to find inactive users
See the MCP Server Integration guide for setup instructions.
We welcome contributions! Gemini CLI is fully open source (Apache 2.0), and we encourage the community to:
- Report bugs and suggest features.
- Improve documentation.
- Submit code improvements.
- Share your MCP servers and extensions.
See our Contributing Guide for development setup, coding standards, and how to submit pull requests.
Check our Official Roadmap for planned features and priorities.
See the Uninstall Guide for removal instructions.
Built with ❤️ by Google and the open source community
