Gemini CLI
Table of Contents
- Overview
- When to Use This Skill
- Core Command Pattern
- Model Selection
- Command Patterns
- Prompt Engineering for Gemini
- Common Use Cases
- Combining Claude + Gemini
- Advanced Patterns
- Error Handling
- Quick Reference
Overview
Execute tasks using Google's gemini command-line tool to leverage Gemini 2.5 Pro alongside Claude. This skill enables headless (non-interactive) execution where content is piped to Gemini, processed with custom prompts, and results are saved directly to files.
When to Use This Skill
Invoke this skill when:
- Alternative perspective: Get Gemini's viewpoint on a problem Claude is solving
- Parallel analysis: Run Claude and Gemini analysis side-by-side for comparison
- Specific Gemini strengths: Leverage capabilities where Gemini excels
- Headless processing: Need non-interactive AI execution that saves to files
- Batch processing: Process multiple inputs through Gemini
- Second opinion: Validate Claude's analysis with Gemini's assessment
When NOT to use: Tasks Claude can handle directly without needing a second AI perspective.
Core Command Pattern
The fundamental pattern for using gemini CLI:
cat [input-files] | gemini "[PROMPT]" --model gemini-2.5-pro > [output-file]
Components:
cat [input-files]- Concatenate input content (optional if prompt-only)| gemini "[PROMPT]"- Pipe to gemini with custom instructions--model gemini-2.5-pro- Specify the model> [output-file]- Redirect output to a file
Model Selection
| Model | Use For | Speed |
|---|---|---|
gemini-2.5-pro | Complex reasoning, deep analysis, multi-step tasks | Slower |
gemini-2.5-flash | Quick processing, simple transformations, batch jobs | Faster |
Specify with: --model gemini-2.5-pro or --model gemini-2.5-flash
Command Patterns
Single File Input
cat document.md | gemini "Summarize in 3 bullet points" --model gemini-2.5-pro > summary.md
Multiple File Input
cat file1.txt file2.txt | gemini "Find common themes" --model gemini-2.5-pro > themes.md
Prompt-Only (No Input)
gemini "Create a 10-item code review checklist" --model gemini-2.5-pro > checklist.md
Prompt Engineering for Gemini
Define Role and Task
gemini "You are an expert [ROLE]. [TASK]. Format as [FORMAT]." --model gemini-2.5-pro
Multi-Part Instructions
gemini "Task:
1. [First step]
2. [Second step]
3. [Third step]
Format: Markdown with headings" --model gemini-2.5-pro
Common Use Cases
Alternative Perspective
Get Gemini's viewpoint alongside Claude's:
cat analysis.md | gemini "Review this analysis. Identify gaps or alternative viewpoints." --model gemini-2.5-pro > gemini_perspective.md
Verify output: head -20 gemini_perspective.md to confirm format matches expectations.
Comparative Analysis
Compare two approaches:
cat approach_a.md approach_b.md | gemini "Compare these approaches. Create pros/cons table, recommend when to use each." --model gemini-2.5-pro > comparison.md
Verify output: Check comparison.md contains expected table structure.
Code Review
Review code with Gemini:
cat code_file.py | gemini "Review for: 1) Design patterns, 2) Potential issues, 3) Security concerns. Provide specific examples." --model gemini-2.5-pro > code_review.md
Sample Output (code_review.md):
## Code Review
### Design Patterns: 7/10
- Uses functional approach appropriately
- Consider adding type hints
### Potential Issues
1. No input validation on line 15
2. Missing error handling for empty lists
### Security Concerns
- None identified for this scope
Verify output: grep "##" code_review.md to confirm sections exist.
Research Synthesis
Synthesize multiple sources:
cat source1.md source2.md source3.md | gemini "Synthesize key insights. Create executive summary followed by detailed findings." --model gemini-2.5-pro > synthesis.md
Batch Processing
Process multiple files:
for file in *.md; do
cat "$file" | gemini "Summarize this document" --model gemini-2.5-flash > "summaries/${file%.md}_summary.md"
done
Combining Claude + Gemini
Sequential Processing
Claude processes first, Gemini refines:
- Claude creates initial analysis, saves to file
- Gemini reviews and enhances, saves refinement
- Compare both results
Parallel Analysis
Both analyze the same input:
- Claude analyzes in conversation
- Gemini analyzes same content, saves to file
- Compare perspectives, synthesize insights
Division of Labor
- Claude: Interactive exploration, code generation
- Gemini: Batch processing, alternative perspectives
Advanced Patterns
Iterative Refinement
# First pass
cat input.md | gemini "Analyze..." --model gemini-2.5-pro > v1.md
# Second pass with feedback
cat v1.md | gemini "Review and improve this analysis..." --model gemini-2.5-pro > v2.md
Chaining with CLI Tools
cat document.md | gemini "Extract key points" --model gemini-2.5-pro | grep "##" > headings.txt
Environment Variables for Reusable Prompts
PROMPT="Analyze for security vulnerabilities. Format as Markdown."
cat code.py | gemini "$PROMPT" --model gemini-2.5-pro > security_review.md
Error Handling
If command fails:
- Verify
geminiCLI is installed:which gemini - Check file paths exist:
ls -la input.md - Ensure prompt is properly quoted
- Verify model flag:
--model gemini-2.5-pro
If output is poor:
- Make prompt more specific
- Add role definition
- Request structured format
- Try
gemini-2.5-proinstead offlash
Quote escaping:
gemini 'Say "Hello World"' --model gemini-2.5-pro
Quick Reference
Prompt Template:
"You are [ROLE].
Task: [WHAT TO DO]
Input: [WHAT YOU'RE ANALYZING]
Output: [DESIRED FORMAT]
Context: [CONSTRAINTS/AUDIENCE]"
Best Practices:
- Always specify model with
--model - Define role in prompt
- Request structured output format
- Use descriptive output filenames
- Verify output with
headorgrepafter generation
