Login
Back to Blog
"Gemini CLI Complete Guide: Google's AI-Powered Command Line Tool for Developers"

"Gemini CLI Complete Guide: Google's AI-Powered Command Line Tool for Developers"

C
Crazyrouter Team
February 19, 2026
22 viewsEnglishGuide
Share:

Google's Gemini CLI has quickly become one of the most popular AI developer tools since its open-source release. Powered by Gemini 2.5 Pro with its massive 1 million token context window, it brings AI assistance directly into your terminal — where developers actually work.

This is the complete guide: installation, configuration, everyday workflows, advanced techniques, and how to get the most out of it.

What Is Gemini CLI?#

Gemini CLI is an open-source, terminal-native AI assistant built by Google. It connects to Gemini 2.5 Pro and lets you interact with AI without leaving your command line.

Why developers love it:

  • 1M token context — analyze entire codebases in a single conversation
  • File-aware — reads and understands your project files directly
  • Free daily quota — no credit card required to start
  • Open source — fully customizable, MIT licensed
  • Shell integration — pipes, redirects, and scripting support
  • Multimodal — handles text, code, images, and more

Gemini CLI vs Other AI CLI Tools#

FeatureGemini CLIClaude CodeAiderCopilot CLI
ModelGemini 2.5 ProClaude Sonnet 4.5MultipleGPT-4o
Context Window1M tokens200K tokensVaries128K tokens
Free Tier✅ Daily quota
Open Source✅ MIT
File EditingLimited
Image Input
Shell IntegrationLimited
PriceFree / Pay-per-use$20/mo+Free / API costs$10/mo+

Installation#

Prerequisites#

  • Node.js 18 or later
  • npm or yarn
  • A Google account (for free tier) or API key

Install via npm#

bash
# Global install
npm install -g @google/gemini-cli

# Verify installation
gemini --version

Install via npx (No Install)#

bash
# Run directly without installing
npx @google/gemini-cli

Build from Source#

bash
git clone https://github.com/google-gemini/gemini-cli.git
cd gemini-cli
npm install
npm run build
npm link

Platform-Specific Notes#

macOS:

bash
# If you get permission errors
sudo npm install -g @google/gemini-cli
# Or better, use nvm to manage Node.js

Linux:

bash
# Ensure Node.js 18+
curl -fsSL https://deb.nodesource.com/setup_18.x | sudo -E bash -
sudo apt-get install -y nodejs
npm install -g @google/gemini-cli

Windows (WSL recommended):

bash
# Install in WSL for best experience
wsl
npm install -g @google/gemini-cli

Configuration#

Authentication Options#

1. Google Account (Free Tier)#

bash
gemini
# First run opens browser for Google OAuth
# After login, you get daily free quota

2. Google AI Studio API Key#

bash
# Get key from https://aistudio.google.com/apikey
export GEMINI_API_KEY="your-key-here"
gemini

3. Vertex AI (Enterprise)#

bash
export GOOGLE_CLOUD_PROJECT="your-project-id"
export GOOGLE_CLOUD_REGION="us-central1"
gemini --backend vertex

4. Crazyrouter (Alternative API Provider)#

For developers who want access to Gemini alongside other models, or need reliable access from regions where Google APIs are restricted:

bash
export GEMINI_API_KEY="your-crazyrouter-key"
export GEMINI_API_BASE="https://api.crazyrouter.com/v1"
gemini

Crazyrouter offers Gemini 2.5 Pro at competitive rates alongside 300+ other models.

Configuration File#

Create ~/.gemini/settings.json:

json
{
  "theme": "dark",
  "model": "gemini-2.5-pro",
  "maxTokens": 8192,
  "temperature": 0.7,
  "systemPrompt": "You are a senior software engineer. Be concise and practical.",
  "safetySettings": {
    "harassment": "BLOCK_NONE",
    "dangerousContent": "BLOCK_NONE"
  }
}

Custom System Prompts#

Create reusable prompts in ~/.gemini/prompts/:

bash
# ~/.gemini/prompts/code-review.txt
You are a strict code reviewer. Focus on:
1. Security vulnerabilities
2. Performance issues
3. Code maintainability
4. Error handling
Rate each area 1-5 and provide specific suggestions.
bash
# Use the custom prompt
gemini --prompt code-review "Review this PR" -f src/

Core Workflows#

Interactive Mode#

bash
# Start interactive session
gemini

# You're now in a REPL
> Explain the architecture of this project
> What are the main entry points?
> Find potential security issues

One-Shot Commands#

bash
# Quick question
gemini "What does this regex do: ^(?=.*[A-Z])(?=.*\d)[A-Za-z\d]{8,}$"

# File analysis
gemini "Explain this code" -f src/auth/middleware.ts

# Multiple files
gemini "How do these files interact?" -f src/api.ts -f src/database.ts -f src/models.ts

Code Review#

bash
# Review staged changes
git diff --staged | gemini "Review these changes for bugs and improvements"

# Review a specific commit
git show abc123 | gemini "Analyze this commit for potential issues"

# Review a PR (all changes from main)
git diff main...HEAD | gemini "Comprehensive code review of this PR"

# Review with custom criteria
git diff --staged | gemini --prompt code-review

Debugging#

bash
# Analyze error logs
cat error.log | gemini "What's causing these errors? Suggest fixes."

# Debug a specific error
gemini "I'm getting this error, what's wrong?" <<'EOF'
TypeError: Cannot read properties of undefined (reading 'map')
    at UserList (/src/components/UserList.tsx:15:23)
    at renderWithHooks (/node_modules/react-dom/cjs/react-dom.development.js:14985:18)
EOF

# Analyze test failures
npm test 2>&1 | gemini "Why are these tests failing?"

Code Generation#

bash
# Generate a function
gemini "Write a TypeScript function that debounces API calls with a configurable delay"

# Generate tests
gemini "Generate comprehensive unit tests for this module" -f src/utils/validation.ts

# Generate documentation
gemini "Generate JSDoc comments for all exported functions" -f src/api/handlers.ts

Advanced Techniques#

Shell Pipeline Integration#

Gemini CLI shines when combined with standard Unix tools:

bash
# Find and explain complex functions
grep -rn "async function" src/ | gemini "Which of these functions might have race conditions?"

# Analyze dependencies
cat package.json | gemini "Identify outdated or risky dependencies"

# System diagnostics
docker ps -a --format "table {{.Names}}\t{{.Status}}\t{{.Ports}}" | \
  gemini "Which containers look unhealthy?"

# Database analysis
pg_dump --schema-only mydb | gemini "Suggest index optimizations for this schema"

# Log analysis
journalctl -u myapp --since "1 hour ago" | gemini "Summarize errors and warnings"

Project-Wide Analysis#

The 1M token context window enables analysis that other tools can't match:

bash
# Analyze entire project architecture
find src/ -name "*.ts" | head -50 | xargs gemini "Map the architecture of this project"

# Find dead code
gemini "Identify unused exports and dead code" -f src/

# Security audit
gemini "Perform a security audit. Check for: SQL injection, XSS, CSRF, auth bypass, secrets in code" -f src/

# Migration planning
gemini "I want to migrate from Express to Fastify. Analyze the codebase and create a migration plan" -f src/

Git Workflow Integration#

bash
# Auto-generate commit messages
git diff --staged | gemini "Write a conventional commit message for these changes"

# Generate changelog
git log --oneline v1.0.0..HEAD | gemini "Generate a user-facing changelog grouped by feature/fix/chore"

# Pre-commit hook
# .git/hooks/pre-commit
#!/bin/bash
DIFF=$(git diff --staged)
REVIEW=$(echo "$DIFF" | gemini "Quick review: any obvious bugs or security issues? Reply YES or NO with brief explanation")
echo "$REVIEW"

Batch Processing#

bash
# Add type annotations to all Python files
for f in src/**/*.py; do
  echo "Processing $f..."
  gemini "Add type hints to all functions in this file. Output only the modified code." -f "$f" > "${f}.typed"
done

# Generate API docs for all routes
for f in src/routes/*.ts; do
  gemini "Generate OpenAPI 3.0 YAML for the routes in this file" -f "$f" >> api-docs.yaml
done

Custom Aliases#

Add to your .bashrc or .zshrc:

bash
# Quick code review
alias cr='git diff --staged | gemini "Code review: bugs, security, performance"'

# Explain error
alias explain='gemini "Explain this error and suggest a fix"'

# Generate commit message
alias gcm='git diff --staged | gemini "Write a concise conventional commit message"'

# Quick question about current project
alias ask='gemini -f src/'

Pricing & Quotas#

Free Tier (Google Account)#

ResourceDaily Limit
Requests~50-100
Input tokens~500K
Output tokens~50K
ModelsGemini 2.5 Pro

The free tier resets daily and is sufficient for moderate use.

ProviderInput PriceOutput PriceNotes
Google AI Studio$1.25/1M tokens$10.00/1M tokensDirect access
Vertex AI$1.25/1M tokens$10.00/1M tokensEnterprise features
Crazyrouter$0.875/1M tokens$7.00/1M tokens30% cheaper, 300+ models

Cost Optimization Tips#

  1. Use the free tier for daily work — it's generous enough for most developers
  2. Be specific in prompts — reduces unnecessary output tokens
  3. Use -f selectively — don't feed entire directories when you only need specific files
  4. Cache results — pipe output to files for reference
  5. Use Crazyrouter for heavy usage — 30% savings on API costs

Troubleshooting#

Common Issues#

"Authentication failed"

bash
# Clear cached credentials
rm -rf ~/.gemini/auth
# Re-authenticate
gemini

"Rate limit exceeded"

bash
# Switch to API key
export GEMINI_API_KEY="your-key"
# Or use Crazyrouter
export GEMINI_API_BASE="https://api.crazyrouter.com/v1"

"Context too long"

bash
# Be selective with files
gemini "Review auth logic" -f src/auth/ # Instead of -f src/

Slow responses

bash
# Reduce max tokens
gemini --max-tokens 2048 "Quick answer: what does this function do?" -f utils.ts

Frequently Asked Questions#

Is Gemini CLI free?#

Yes, Gemini CLI itself is free and open source. With a Google account, you get a daily free quota for API calls. For heavier usage, you can use a paid API key from Google AI Studio or Crazyrouter.

Can Gemini CLI edit files directly?#

Yes, Gemini CLI can propose and apply file edits with your confirmation. It supports creating new files, modifying existing ones, and even running shell commands (with approval).

How does the 1M token context compare to competitors?#

Gemini CLI's 1M token context is 5x larger than Claude Code (200K) and 8x larger than Copilot CLI (128K). This means you can analyze entire medium-sized codebases in a single conversation without chunking.

Can I use Gemini CLI offline?#

No, Gemini CLI requires an internet connection to communicate with the Gemini API. The processing happens server-side.

Does Gemini CLI support other models?#

By default, Gemini CLI uses Gemini 2.5 Pro. Through custom API endpoints like Crazyrouter, you can potentially route to other models while using the same CLI interface.

Is my code sent to Google's servers?#

Yes, code you share with Gemini CLI is sent to Google's API for processing. Google's data usage policies apply. For sensitive codebases, consider using Vertex AI with enterprise data governance or self-hosting alternatives.

Summary#

Gemini CLI is the most capable free AI CLI tool available today. The 1M token context window, combined with solid file handling and shell integration, makes it a genuine productivity multiplier for developers.

Start with the free tier — it's enough for most daily workflows. When you need more, Crazyrouter offers Gemini API access at 30% below Google's prices, plus access to 300+ other models through the same API key.

Related Articles