How to Use Gemini CLI: Complete Beginner Guide (2026)
How to Use Gemini CLI: Complete Beginner Guide (2026)
Gemini CLI is Google's command-line tool for using Gemini models directly in your terminal. Like Claude Code, it lets you interact with AI without leaving the command line -- but it uses Google's Gemini models instead of Anthropic's Claude.
This guide covers installation, setup, your first task, and how Gemini CLI compares to other terminal AI tools.
In this guide:
- What Gemini CLI does
- Installation and setup (3 minutes)
- Your first Gemini CLI task
- Common use cases
- Gemini CLI pricing
- Gemini CLI vs Claude Code
Related guides: Gemini CLI vs Claude Code Comparison · How to Use Claude Code · How to Use Cursor AI · All AI Coding Tool Comparisons
What Gemini CLI Does
Gemini CLI brings Google's Gemini models to your terminal. You type natural language instructions, and Gemini CLI:
- Answers questions about code, APIs, documentation
- Writes and edits code in your project files
- Explains codebases by reading your project structure
- Runs shell commands when needed
- Processes files -- feed it documents, logs, or data for analysis
The key advantage: Gemini 2.5 Pro has a 1M token context window -- one of the largest available. This means Gemini CLI can process much larger files and codebases in a single conversation than tools using smaller-context models.
For a detailed comparison with Anthropic's CLI tool, see our Gemini CLI vs Claude Code comparison.
Installation and Setup
Prerequisites
- Node.js 18+ (check with
node --version) - A Google AI Studio API key (get one here)
- A terminal (Terminal on macOS, PowerShell on Windows)
Step 1: Install Gemini CLI
npm install -g @anthropic-ai/claude-code
Wait -- that's Claude Code. For Gemini CLI, the installation depends on the package:
npm install -g @anthropic-ai/gemini-cli
Actually, let's use the correct Google package. Install via:
npm install -g @google/generative-ai-cli
If npm isn't your thing, you can also use:
# Using the standalone installer
curl -fsSL https://cli.gemini.google.com/install.sh | bash
# Or with Homebrew (macOS)
brew install gemini-cli
Verify the installation:
gemini --version
Step 2: Set Your API Key
Get your API key from Google AI Studio. Google offers a free tier with generous limits (see pricing below).
Set the key as an environment variable:
macOS/Linux (add to ~/.bashrc or ~/.zshrc):
export GEMINI_API_KEY="your-api-key-here"
Windows PowerShell:
$env:GEMINI_API_KEY = "your-api-key-here"
Step 3: Start Using Gemini CLI
cd your-project-folder
gemini
You'll see the prompt:
gemini>
Total setup time: about 3 minutes.
Your First Gemini CLI Task
Example 1: Analyze Your Project
gemini> What does this project do? Summarize the tech stack and architecture.
Gemini CLI reads your project files and provides a summary. With the 1M token context window, it can process large codebases that other tools might struggle with.
Example 2: Write a Feature
gemini> Add pagination to the /api/users endpoint. Return 20 users per page with a total count. Include prev/next page links.
Gemini CLI finds the relevant file, reads the existing code, and adds pagination.
Example 3: Debug an Error
gemini> I'm getting a CORS error when calling the API from localhost:3000. Here's the error:
Access to fetch at 'https://api.example.com/users' from origin 'http://localhost:3000' has been blocked by CORS policy
Fix it.
Gemini CLI explains the CORS issue and provides the fix (adding appropriate headers to your server or configuring a proxy).
Example 4: Process a Large File
gemini> Read the file logs/app.log and find the most common error types. Summarize the top 5 errors with their frequency and likely causes.
This is where Gemini CLI's large context window shines -- it can process multi-megabyte log files that other tools might truncate.
Common Use Cases
Code Generation
gemini> Create a Express.js middleware that validates JWT tokens. Include:
- Token extraction from Authorization header
- Token verification using jsonwebtoken
- Error handling for expired and invalid tokens
- TypeScript types
Documentation
gemini> Read all files in src/api/ and generate API documentation in Markdown format. Include endpoint paths, HTTP methods, request/response schemas, and example curl commands.
Data Analysis
gemini> Read data/sales.csv and answer:
1. What's the total revenue by month?
2. Which product has the highest growth rate?
3. Are there any seasonal patterns?
Present the results in tables.
Refactoring
gemini> The file src/utils/helpers.ts has 15 exported functions that are used across the project. Split it into 3 files based on logical grouping (string utils, date utils, format utils). Update all imports across the project.
Gemini CLI Pricing
Google offers one of the most generous free tiers among AI providers:
| Plan | Price | Rate Limits |
|---|---|---|
| Free | $0 | 15 requests/minute, 1M tokens/min, 1,500 requests/day |
| Pay-as-you-go | Per token | Higher rate limits, no daily cap |
Pay-as-you-go pricing (Gemini 2.5 Pro):
- Input: $1.25 per 1M tokens
- Output: $10.00 per 1M tokens
Pay-as-you-go pricing (Gemini 2.0 Flash):
- Input: $0.10 per 1M tokens
- Output: $0.40 per 1M tokens
How this compares:
| Model | Input (per 1M) | Output (per 1M) | Context Window |
|---|---|---|---|
| Gemini 2.5 Pro | $1.25 | $10.00 | 1M tokens |
| Gemini 2.0 Flash | $0.10 | $0.40 | 1M tokens |
| Claude 3.5 Sonnet | $3.00 | $15.00 | 200K tokens |
| GPT-4o | $2.50 | $10.00 | 128K tokens |
Gemini is the cheapest per-token option with the largest context window. The trade-off: output quality on complex reasoning tasks is slightly below Claude Sonnet.
For a full pricing comparison, see our AI cost calculator and our 200-task benchmark report.
Gemini CLI vs Claude Code
Both are terminal-based AI coding tools, but they have different strengths:
| Feature | Gemini CLI | Claude Code |
|---|---|---|
| Provider | Anthropic | |
| Model | Gemini 2.5 Pro | Claude 3.5 Sonnet |
| Context Window | 1M tokens | 200K tokens |
| Free Tier | Yes (generous) | $5 free credits |
| Input Price | $1.25/M tokens | $3.00/M tokens |
| File Editing | Limited | Full (reads, writes, creates) |
| Command Execution | Limited | Full (runs any terminal command) |
| Code Quality | Good | Very good |
| Large File Processing | Excellent | Good |
| Best For | Analysis, large codebases, free usage | Implementation, debugging, multi-file edits |
When to Choose Gemini CLI
- You want a free terminal AI tool with generous limits
- You work with large files (log analysis, big data, long documents)
- You need the 1M token context window for processing entire codebases
- You want the cheapest per-token pricing
When to Choose Claude Code
- You need AI to edit files and run commands autonomously
- You want the highest code quality for complex implementations
- You need multi-step debugging with terminal command execution
- You want to connect to multi-agent squads via Ivern
For the detailed breakdown, see our Gemini CLI vs Claude Code comparison.
Using Both Together
Many developers use both: Gemini CLI for analysis and large-context tasks, Claude Code for implementation and debugging. Through Ivern Squads, you can coordinate both in the same workflow:
- Gemini agent processes the codebase and identifies issues
- Claude Code agent implements the fixes
- A Reviewer agent verifies the changes
See our multi-agent coding setup guide for instructions on coordinating multiple terminal agents.
Frequently Asked Questions
How do I install Gemini CLI?
Install with npm (npm install -g @google/generative-ai-cli), set your API key from Google AI Studio as an environment variable (export GEMINI_API_KEY="your-key"), then run gemini in any project directory. Setup takes about 3 minutes. You need Node.js 18+ installed.
Is Gemini CLI free?
Yes. Google's free tier includes 15 requests per minute and 1,500 requests per day with Gemini 2.5 Pro. This is enough for most individual developers. Paid usage starts at $1.25 per million input tokens -- cheaper than Claude ($3.00/M) and GPT-4o ($2.50/M). See our cost calculator for monthly estimates.
What is the difference between Gemini CLI and Claude Code?
Gemini CLI uses Google's Gemini models with a 1M token context window and a generous free tier. Claude Code uses Anthropic's Claude models with stronger code generation and autonomous file editing. Gemini CLI is better for analysis and large-file processing. Claude Code is better for implementation and debugging. See our detailed comparison.
Can Gemini CLI edit files?
Gemini CLI can read and analyze files, but its autonomous file editing capabilities are more limited than Claude Code. For complex multi-file edits, Claude Code or Cursor are better options. Gemini CLI excels at analysis, explanation, and generation of code snippets that you can apply manually.
What context window does Gemini CLI support?
Gemini 2.5 Pro supports a 1M token context window -- roughly 750,000 words of text. This means Gemini CLI can process an entire medium-sized codebase in a single conversation, or analyze very large files (multi-MB logs, datasets, documentation) without truncation.
Can I use Gemini CLI for non-coding tasks?
Yes. Gemini CLI works for any text-based task: analyzing documents, summarizing reports, processing CSV data, generating documentation, writing emails, and more. The terminal interface and large context window make it particularly useful for processing large text files that won't fit in browser-based chat tools.
Next Steps
- Install Gemini CLI:
npm install -g @google/generative-ai-cli - Get your API key: Google AI Studio (free)
- Try it:
cd your-project && gemini - Compare tools: Gemini CLI vs Claude Code
- Optional: Connect to Ivern Squads for multi-agent coordination
Related reading: Gemini CLI vs Claude Code · How to Use Claude Code · How to Use Cursor AI · AI Cost Calculator · All AI Coding Tool Comparisons
Related Articles
Gemini CLI Tutorial: How to Use Google's AI Coding Agent for Real Projects (2026)
Google's Gemini CLI brings Gemini 2.5 Pro to your terminal for coding, research, and automation. This tutorial covers setup, real-world usage examples, and how to connect it to a multi-agent squad with Claude Code and Cursor.
Gemini CLI vs Claude Code: Terminal AI Coding Agent Comparison (2026)
Gemini CLI and Claude Code are the two leading terminal-based AI coding agents. We compare them on speed, context window, pricing (free vs paid), code quality, and real-world usage. Find out which terminal AI agent is better for your workflow.
How to Use Claude Code: Complete Beginner Guide (2026)
Step-by-step tutorial for installing Claude Code, setting up your API key, and running your first AI coding tasks from the terminal. Covers installation, basic commands, file editing, multi-file projects, and connecting Claude Code to a multi-agent squad. No prior experience needed.
Build Your AI Agent Squad -- Free
Connect Claude Code, Cursor, or OpenAI into coordinated squads. Free tier, BYOK, no markup.