LLMs  

Gemini CLI Cheat Sheet

Your all-in-one reference for Google’s AI-powered terminal assistant.

🛠️ 1. Installation

Linux / macOS

# Install globally
npm install -g @google/gemini-cli

# OR run without install
npx https://github.com/google-gemini/gemini-cli

# Verify installation
gemini --version

💡 If you get permission errors, prepend sudo or install Node.js via nvm.

Windows (PowerShell / CMD)

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

# One-time run
npx https://github.com/google-gemini/gemini-cli

# Check version
gemini --version

⚠️ On Windows, ensure npm and node are in your PATH (node -v to verify).

🔐 2. First-Time Setup

Run and Configure

gemini

Then follow prompts:

  1. Choose color theme.

  2. Sign in with Google or paste API key.

  3. Confirm workspace directory permissions.

  4. Save settings (auto-created on first run).

Config file locations

OSConfig File Path
Linux~/.gemini/settings.json
macOS~/Library/Application Support/gemini/settings.json
WindowsC:\Users\<you>\AppData\Roaming\gemini\settings.json

🧩 Workspace settings override user-level configs (.gemini/settings.json inside project).

⚡ 3. Basic Usage

Start interactive session

gemini

One-off (non-interactive) prompt

gemini -p "Summarize this folder’s code structure"

Choose a specific model

gemini -m "gemini-2.5-pro"
gemini -m "gemini-2.5-flash"

🧠 Pro = higher accuracy / reasoning

Flash = faster, cheaper, lighter

💬 4. Everyday Commands

ActionCommand / Example
Ask a question> What does main.py do?
Generate code> Create a REST API using Flask
Refactor> Refactor login.js for async/await
Generate docs> Write documentation for utils/
Generate tests> Create Jest tests for helpers.js
Summarize files> Summarize key modules in src/
Fix bug> Find and fix undefined variable errors

🧰 5. Built-in Tools (Automated)

ToolDescription
read-fileReads a single file
write-fileEdits / writes files
read-many-filesScans multiple files
globFinds files by pattern
grepSearches text patterns
shellRuns terminal commands
memoryToolStores session memory
web-searchLooks up online info
web-fetchFetches URLs / APIs

Gemini automatically uses these tools when you give a natural-language command.

🧩 6. Slash Commands (Meta Controls)

CommandPurpose
/helpShow all commands
/toolsList available tools
/memoryView / clear memory
/statsCheck token & usage info
/themeChange CLI theme
/mcpManage connected MCP servers
/quit or /exitLeave session

🪄 7. Shell Integration

You can run native commands inside Gemini with a ! prefix:

ExampleDescription
!ls -alList directory (Linux/macOS)
!dirList directory (Windows)
!git statusShow Git changes
!npm testRun tests
!python app.pyRun Python app

📂 8. Typical Workflow

cd ~/projects/myapp
gemini

Then inside CLI:

> Explain architecture of this repo
> Fix bug in src/api/order.js
> Generate README.md with project overview
> !git diff
> Add error logging to server.js

🧠 9. Useful Flags

FlagDescriptionExample
-pRun one-time promptgemini -p "Summarize this repo"
-mChoose modelgemini -m gemini-2.5-flash
--helpShow help menugemini --help
--versionCheck versiongemini --version

🧩 10. Config Customization

Edit .gemini/settings.json in your project for defaults:

{
  "model": "gemini-2.5-flash",
  "theme": "dark",
  "autoApproveToolUse": true,
  "maxTokens": 8192
}

🪶 You can also set autoApproveToolUse to false for manual control.

🧭 11. Troubleshooting Quick Fixes

IssueFix
Permission error (Linux/macOS)Run with sudo or reinstall Node using nvm
Command not foundAdd npm global bin to PATH
Login redirect failsRetry or use API key from Google AI Studio
Quota exceededWait 24h or upgrade your API key
Cannot find modulenpm uninstall -g @google/gemini-cli && npm install -g @google/gemini-cli
Security prompt each timeAdd "autoApproveToolUse": true to config

🧩 12. Pro Tips & Tricks

  • 💾 Memory inspection: /memory show — view session context

  • 💻 Use in scripts:

gemini -p "Generate release notes for v2.0" > changelog.txt
  • 🪶 Quick file summary:

gemini -p "Summarize src/app.js"
  • 🧩 Connect MCP server:

/mcp connect http://localhost:8080
  • 🧠 Switch models mid-session:

/model gemini-2.5-pro
  • ⚙️ View usage stats:

/stats


🔒 13. Security & Safe Use

  • Run in trusted directories only.

  • Review diffs before accepting file changes.

  • Use isolated environments for sensitive projects.

  • Stay updated — run:

npm update -g @google/gemini-cli

🌈 14. Bonus Shortcuts

ActionLinux/macOSWindows
Clear terminalCtrl + LCtrl + L
Copy last outputCtrl + Shift + CCtrl + C (PowerShell)
Paste commandCtrl + Shift + VCtrl + V
Interrupt taskCtrl + CCtrl + C

🧭 15. Quick Reference Summary

CategoryCommand
Launchgemini
Prompt (inline)gemini -p "..."
Model selectgemini -m "gemini-2.5-pro"
Help/help
Tools list/tools
Check stats/stats
Quit/quit
Shell inside!ls, !git status
Update CLInpm update -g @google/gemini-cli