| name | gemini-cli |
| description | Integrate Gemini AI CLI into Claude Code for AI collaboration, code analysis, and tool execution. Use when working with Gemini AI, Google AI, multimodal tasks, or needing advanced AI capabilities. |
Gemini CLI Integration
Integrates Google's Gemini CLI into Claude Code, enabling seamless AI collaboration between Claude and Gemini for enhanced capabilities.
When to Use
- Working with Google AI/Gemini models
- Need multimodal capabilities (text + images)
- Complex reasoning with ReAct architecture
- Web search and fetching capabilities
- MCP server integration
- Code analysis and generation with Gemini
- Comparing AI model outputs
Quick Start
1. Install Gemini CLI
node --version
npm install -g @google/gemini-cli
npx @google/gemini-cli
2. Setup Authentication
Option A: Google OAuth (Recommended - Free)
gemini
Option B: API Key
export GEMINI_API_KEY="your-api-key-here"
echo 'GEMINI_API_KEY="your-api-key-here"' > ~/.gemini/.env
3. Basic Usage
gemini -p "Explain this code: $(cat main.py)"
gemini --yolo -p "Analyze and optimize this codebase"
gemini -i "Let's analyze my project"
gemini --include-directories ./src,./tests --yolo -p "Review and improve this codebase"
gemini -m gemini-2.5-flash --yolo -p "Generate tests for all functions"
YOLO Mode - Use with Caution
--yolo automatically approves all actions. USE SPARINGLY - it's powerful but risky.
✅ Safe YOLO Operations
gemini --yolo -p "Analyze code quality in @./src and generate report"
gemini --yolo -p "Add JSDoc comments to all functions in ./src"
gemini --yolo -p "Fix ESLint errors in @./utils.js"
gemini --yolo -p "Format all JavaScript files with Prettier"
⚠️ Use YOLO with Safeguards
git stash push -m "pre-yolo-backup"
gemini --yolo -p "Refactor authentication module"
gemini --checkpointing --yolo -p "Major code modernization"
gemini --dry-run -p "Database migration"
gemini --yolo -p "Execute reviewed migration"
❌ NEVER Use YOLO For
- Complex, multi-step workflows - Break into sequential steps instead
- Production system modifications - Always manual review
- Database operations - Require human verification
- Security configurations - Too critical for automation
- File deletions - Risk of data loss
- Unknown/untested operations - Test manually first
Better Alternative: Iterative Workflows
Instead of large YOLO tasks, use Claude-orchestrated loops:
gemini --yolo -p "Complete Express.js to Fastify migration"
gemini -p "Step 1: Analyze Express dependencies"
gemini --yolo -p "Step 2: Install Fastify packages"
gemini -p "Step 3: Convert first route"
gemini --yolo -p "Step 4: Run tests"
Claude + Gemini Collaboration Patterns
AI-to-AI Integration: Claude and Gemini work best together with structured, iterative workflows.
The Think-Act-Observe Loop
Claude orchestrates, Gemini executes - the most powerful pattern for AI collaboration:
gemini -p "List all functions and their signatures in @./src/auth.js" > auth_analysis.txt
cat auth_analysis.txt
gemini --yolo -p "Add try-catch error handling to the 'login' function in @./src/auth.js"
gemini --yolo -p "Run tests in tests/auth.test.js and report results"
Structured Output for AI Parsing
Use --output-format json for machine-readable results:
gemini --output-format json -p "List all Python files in ./src" > files.json
cat files.json | jq '.files[]'
gemini --output-format json -p "Analyze security issues in @./src/auth.js" > security_report.json
jq '.vulnerabilities[] | .severity' security_report.json
Safe Automation with Dry-Run
Preview operations before execution:
gemini --dry-run -p "Refactor the authentication system"
gemini --yolo -p "Execute the reviewed refactoring plan"
Sequential Task Decomposition
Break complex tasks into atomic, verifiable steps:
#!/bin/bash
echo "Step 1: Initialize project"
gemini --yolo -p "Initialize Node.js project and create server.js"
echo "Step 2: Install dependencies"
gemini --yolo -p "Install express, cors, and body-parser"
echo "Step 3: Basic server"
gemini --yolo -p "Create basic Express server in server.js with hello world route"
echo "Step 4: Add authentication (review this step)"
gemini -p "Add JWT authentication middleware to server.js"
echo "Step 5: Verify"
gemini --yolo -p "Run tests and report results"
Tool Discovery and Schema
Claude learns available tools:
gemini tools list
gemini tools describe fileSystem
gemini tools describe shell
gemini tools describe google_web_search
Error Handling Patterns
Robust automation with proper error handling:
#!/bin/bash
set -e
if ! gemini --yolo -p "Run test suite"; then
echo "Tests failed. Analyzing..."
gemini -p "Analyze test failures and suggest fixes" > fixes.txt
cat fixes.txt
fi
Context Management
Efficient context for large projects:
gemini --include-directories ./src/auth,./tests/auth \
-p "Focus only on authentication module"
gemini -p "Compare @./src/auth-old.js with @./src/auth-new.js"
gemini -p "Compare my implementation @./src/api.js with @https://example.com/best-practices"
Checkpoint and Restore
Safe experimentation with rollback:
gemini --checkpointing --yolo -p "Major refactoring of core module"
gemini checkpoint list
gemini checkpoint restore <checkpoint-id>
Core Workflows
Code Analysis Workflow
gemini --include-directories . \
--exclude-directories node_modules,.git \
--yolo -p "Analyze this codebase and suggest improvements"
gemini --yolo -p "Review and fix security issues: @./src/auth.js"
gemini --yolo -p "Generate comprehensive tests for: @./src/utils.js"
gemini -p "Explain the architecture of this complex module: @./src/core.js"
Documentation Generation
gemini --include-directories . --yolo -p "Generate a comprehensive README.md for this project"
gemini --yolo -p "Generate complete API documentation for: @./src/api/"
gemini --yolo -p "Add detailed JSDoc comments to all functions in: @./src/"
gemini -p "Explain the documentation strategy for: @./complex_algorithm.py"
Multimodal Analysis
gemini --yolo -p "Describe this architecture diagram: @./docs/architecture.png"
gemini --yolo -p "Compare these UI designs and suggest improvements: @./design1.png @./design2.png"
gemini --yolo -p "Extract and format the text from: @./screenshot.png"
Web Research
gemini --yolo -p "Research best practices for React performance optimization and create summary"
gemini --yolo -p "Analyze this documentation: @https://docs.example.com/api"
gemini --yolo -p "Compare my implementation with: @https://github.com/example/repo and suggest improvements"
Advanced Features
Interactive Commands
/help
/tools
/mcp
/compress
/copy
/clear
/checkpoint
/restore
/ide install
/ide enable
Tool Execution
gemini --yolo -p "Create a Python script that processes all CSV files"
gemini --sandbox -p "Set up a new React project"
gemini -p "Organize my project files"
MCP Server Integration
gemini mcp list
gemini mcp add
gemini mcp remove <name>
gemini -p "Use the database MCP server to query user data"
Checkpointing
gemini --checkpointing -p "Refactor this entire module"
gemini checkpoint list
gemini checkpoint restore <id>
Configuration
Settings File (~/.gemini/settings.json)
{
"model": "gemini-2.5-pro",
"defaultFlags": {
"checkpointing": true,
"includeDirectories": ["./src", "./tests"],
"excludeDirectories": ["node_modules", ".git", "dist"]
},
"tools": {
"shell": {
"enabled": false,
"requireConfirmation": true
},
"fileSystem": {
"enabled": true,
"allowedPaths":
Environment Variables
export GEMINI_API_KEY="your-key"
export GOOGLE_CLOUD_PROJECT="your-project"
export GOOGLE_CLOUD_LOCATION="us-central1"
export GOOGLE_APPLICATION_CREDENTIALS="/path/to/service-account.json"
export GEMINI_MODEL="gemini-2.5-pro"
export GEMINI_INCLUDE_DIRS="./src,./lib"
export GEMINI_EXCLUDE_DIRS="node_modules,.git"
Integration Patterns
Claude + Gemini Collaboration
echo "Claude, create a plan for refactoring auth module"
gemini -p "Execute this refactoring plan: [paste plan]"
Parallel Analysis
echo "Analyze security of auth.js" | tee \
>(claude-cli) \
>(gemini -p -)
Model Comparison
PROMPT="Generate unit tests for utils.js"
echo "Claude:" && claude-cli "$PROMPT"
echo "Gemini:" && gemini -p "$PROMPT"
Best Practices
Security
-
API Key Management
- Never commit API keys
- Use environment variables
- Rotate keys regularly
-
Tool Execution
- Avoid
--yolo for untrusted prompts
- Use
--sandbox for experiments
- Review tool calls before approval
-
MCP Server Trust
- Only trust known servers
- Use include/exclude tool lists
- Set appropriate timeouts
Performance
-
Model Selection
- Use
gemini-2.5-flash for quick tasks
- Use
gemini-2.5-pro for complex reasoning
- Consider token limits (1M context window)
-
Directory Management
- Exclude unnecessary directories
- Use specific includes for large projects
- Leverage checkpointing for long tasks
-
Rate Limiting
- OAuth: 60 req/min, 1000 req/day
- API Key: Varies by tier
- Implement retry logic
Workflow Optimization
-
Batch Operations
gemini -p "Analyze and improve: @./src/*.js"
-
Context Preservation
gemini -i "Let's refactor the auth system"
-
Output Formatting
gemini --json -p "List all functions in: @./utils.js"
Troubleshooting
Common Issues
-
Authentication Failed
rm -rf ~/.gemini/auth
gemini
-
Rate Limiting
gemini usage
-
Tool Execution Errors
gemini -i
/tools
-
MCP Server Issues
gemini mcp status
gemini mcp restart <name>
Examples
Complete Project Analysis (Automated)
#!/bin/bash
gemini --include-directories . \
--exclude-directories node_modules,.git,dist \
--checkpointing --yolo \
-p "Perform comprehensive analysis and create reports:
1. Code quality assessment with fixes
2. Security vulnerability scan and patches
3. Performance optimization suggestions
4. Generate missing tests
5. Create complete documentation
6. Update dependencies safely
7. Implement CI/CD pipeline"
Automated Documentation Suite
#!/bin/bash
gemini --yolo -p "Generate complete documentation ecosystem:
1. README.md with badges and quick start
2. API.md with OpenAPI specification
3. CONTRIBUTING.md with dev workflow
4. CHANGELOG.md with version history
5. JSDoc comments for all functions
6. Architecture diagrams in Mermaid
7. Test documentation and coverage reports
8. Deployment and operations guide"
Framework Migration (Auto-Pilot)
#!/bin/bash
gemini --checkpointing --yolo \
-p "Fully automated Express.js to Fastify migration:
1. Analyze current Express structure
2. Create detailed migration plan
3. Update package.json dependencies
4. Convert all routes and middleware
5. Update error handling patterns
6. Migrate and update all tests
7. Create docker configuration
8. Verify functionality with test suite
9. Generate migration report"
Daily Development Automation
#!/bin/bash
gemini --yolo -p "Execute daily development workflow:
1. Pull latest changes safely
2. Update dependencies to latest stable
3. Run full test suite and fix failures
4. Update documentation for any changes
5. Optimize code performance
6. Run security audit and fix issues
7. Generate daily progress report
8. Commit and push changes with proper messages"
Related Skills
gemini-auth: Authentication management
gemini-chat: Interactive chat sessions
gemini-tools: Tool execution workflows
gemini-mcp: MCP server management
gemini-code: Code-specific operations
Updates
This skill tracks Gemini CLI updates. Check for new features:
npm update -g @google/gemini-cli
gemini --version
gemini changelog