DEV Community

muzhihao1
muzhihao1

Posted on

7 Gemini CLI Tips That Save Me Hours Every Week

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"
Enter fullscreen mode Exit fullscreen mode

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"
Enter fullscreen mode Exit fullscreen mode

Or review an entire directory:

find src/ -name "*.py" -exec cat {} + | gemini "Find bugs in this codebase"
Enter fullscreen mode Exit fullscreen mode

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
Enter fullscreen mode Exit fullscreen mode

Combine with Plan Mode for even more control:

gemini plan --save refactor-plan.md "Migrate from Express callbacks to async/await"
Enter fullscreen mode Exit fullscreen mode

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"
Enter fullscreen mode Exit fullscreen mode

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"
Enter fullscreen mode Exit fullscreen mode

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"
Enter fullscreen mode Exit fullscreen mode

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
Enter fullscreen mode Exit fullscreen mode

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
Enter fullscreen mode Exit fullscreen mode

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:

All free, no signup required.


What Gemini CLI tips have saved you the most time? Drop them in the comments!

Top comments (0)