Google's Gemini CLI is a powerful AI coding assistant that runs directly in your terminal. After using it daily for months, here are the tips and tricks that made the biggest difference in my workflow.
1. Use Plan Mode for Complex Refactoring
Instead of letting Gemini CLI modify files immediately, use Plan Mode to preview changes first:
gemini plan "Refactor the auth module to use OAuth 2.0"
Plan Mode generates a step-by-step execution plan that you can review, edit, and approve before any files are touched. This is a lifesaver for multi-file refactoring where you want to see the full picture before committing.
When to use it: Database migrations, API redesigns, or any change touching 3+ files.
2. Pipe Files for Instant Code Reviews
Don't just describe your code - pipe it directly:
cat src/auth.py | gemini "Review this code for security vulnerabilities"
Or review an entire directory:
find src/ -name "*.py" -exec cat {} + | gemini "Find bugs in this codebase"
This gives Gemini CLI the full context instead of relying on descriptions.
3. Save Output to Files
Stop copying from the terminal. Redirect output directly:
gemini "Write unit tests for this function" < utils.py > tests/test_utils.py
Combine with Plan Mode for even more control:
gemini plan --save refactor-plan.md "Migrate from Express callbacks to async/await"
4. Switch Models Based on Task Complexity
Not every task needs the most powerful model. Use Flash Lite for quick tasks:
# Quick question - use the fast model
gemini -m flash-lite "What does the -g flag do in npm install?"
# Complex refactoring - use the powerful model
gemini -m pro "Redesign the database schema for multi-tenancy support"
Flash Lite responds 3-5x faster and costs significantly less. For code completion, quick Q&A, and batch processing, it's the better choice.
5. Fix "Not Responding" Issues Fast
This is the #1 issue developers hit. When Gemini CLI hangs or freezes:
# Step 1: Kill the hanging process
pkill -f gemini
# Step 2: Clear the cache
gemini cache clear
# Step 3: Check your API key is valid
echo $GEMINI_API_KEY
# Step 4: Test with a simple command
gemini "Hello"
Common causes: expired API key, network timeout behind corporate proxy, or Node.js version < 16.
I wrote a comprehensive troubleshooting guide covering all the edge cases if you're still stuck.
6. Use Subagents for Parallel Work
Gemini CLI can spawn subagents to handle multiple tasks simultaneously:
gemini "Run tests, fix linting errors, and update documentation - do these in parallel"
Gemini CLI automatically detects that these are independent tasks and spawns a subagent for each one. The results are merged when all subagents complete.
Control concurrency with:
gemini config set maxSubagents 4
7. Set Up Governance Files for Team Consistency
Create a GEMINI.md file at your project root to enforce coding standards:
# Project Rules for Gemini CLI
- Use TypeScript strict mode
- Follow the repository's existing naming conventions
- Never modify files in the /config directory without approval
- Write tests for all new functions
- Use async/await, never callbacks
Every team member's Gemini CLI instance will follow these rules automatically. This prevents the "AI wrote inconsistent code" problem that plagues team projects.
Resources
If you're getting started with Gemini CLI or running into issues, I built GeminiCLI.one as a comprehensive resource hub. It covers:
- Installation guides for all platforms (Windows, macOS, Linux, Docker)
- Troubleshooting solutions for common errors
- First command guide with practical examples
- Guides for latest features like Plan Mode, Subagents, and Sandbox
All free, no signup required.
What Gemini CLI tips have saved you the most time? Drop them in the comments!
Top comments (0)