Skip to main content

Gemini CLI Cheatsheet

Gemini CLI is Google's open-source AI agent that brings the power of Gemini directly into your terminal. Supports interactive chat, code generation and understanding, file operations, shell commands, web search, MCP protocol extensions, and subagent orchestration. Free tier: 60 requests/min, 1,000 requests/day.

Updated: 2026-07-20·68 commands

Quick Start

``bash # Install npm install -g @google/gemini-cli

# Or run without installing npx @google/gemini-cli

# Start interactive session gemini

# Non-interactive mode gemini -p "What is the capital of Japan?"

# Use a specific model gemini -m gemini-2.5-flash -p "Write a Python script"

# Pipe input cat README.md | gemini `

Installation Options

MethodCommand
npm (global)npm install -g @google/gemini-cli
npx (no install)npx @google/gemini-cli
Homebrew (macOS/Linux)brew install gemini-cli
MacPorts (macOS)sudo port install gemini-cli
Preview channelnpm install -g @google/gemini-cli@preview
Nightly channelnpm install -g @google/gemini-cli@nightly

Authentication

MethodSetupBest For
Sign in with GoogleRun gemini, choose Sign in with GoogleIndividuals, free tier
Gemini API Keyexport GEMINI_API_KEY="YOUR_KEY"Developers, headless
Vertex AI (ADC)gcloud auth application-default login + export GOOGLE_CLOUD_PROJECT="..."Enterprise teams
Vertex AI (SA Key)export GOOGLE_APPLICATION_CREDENTIALS="/path/to/key.json"CI/CD, non-interactive
### Environment Persistence

Add to ~/.bashrc or ~/.zshrc: `bash export GEMINI_API_KEY="YOUR_KEY" # Or for Vertex AI: export GOOGLE_CLOUD_PROJECT="YOUR_PROJECT_ID" export GOOGLE_CLOUD_LOCATION="us-central1" `

Or use a .env file at ~/.gemini/.env (global) or ./.gemini/.env (project).

Command-Line Flags

FlagDescriptionExample
-m, --model Specify Gemini modelgemini -m gemini-2.5-pro -p "..."
-p, --prompt Non-interactive promptgemini -p "Explain this code"
-i, --prompt-interactive Start interactive with initial promptgemini -i "Refactor this module"
-d, --debugEnable debug modegemini -d
--sandboxIsolate tool execution (Docker/Podman)gemini --sandbox -p "rm test"
--yoloAuto-approve all tool callsgemini --yolo -p "Deploy"
--output-format jsonJSON output (scripting)gemini -p "..." --output-format json
--output-format stream-jsonReal-time JSON eventsgemini -p "..." --output-format stream-json
--include-directories Multi-directory workspacegemini --include-directories ../lib,../docs
--checkpointingEnable session checkpointinggemini --checkpointing

Configuration

### Settings Files (settings.json)

Precedence (highest to lowest): 1. Command-line arguments 2. Environment variables (including .env files) 3. System settings file/etc/gemini-cli/settings.json 4. Project settings file.gemini/settings.json 5. User settings file~/.gemini/settings.json 6. System defaults file/etc/gemini-cli/system-defaults.json

### Common Settings

`json { "theme": "GitHub", "vimMode": true, "autoAccept": false, "sandbox": "docker", "checkpointing": { "enabled": true }, "general": { "preferredEditor": "vscode", "defaultApprovalMode": "default", "plan": { "enabled": true } } } `

### Context Files (GEMINI.md)

GEMINI.md files provide hierarchical context — more specific files override general ones: 1. Global: ~/.gemini/GEMINI.md 2. Project: /.gemini/GEMINI.md 3. Sub-directory: Scanned for component-specific instructions

Generate starter: /init (inside CLI). Use @file.md for modular imports. View combined context: /memory show.

### Ignoring Files (.geminiignore)

Place .geminiignore in project root (syntax similar to .gitignore): `gitignore # .geminiignore /backups/ *.log secret-config.json `

Slash Commands Reference

### Session & Chat

CommandDescription
/help or /?Display help
/clearClear screen (or Ctrl+L)
/compressSummarize chat context to save tokens
/copyCopy last output to clipboard
/quit or /exitExit CLI
/quit --deleteExit and delete session data
/rewindNavigate backward through conversation (Esc Esc shortcut)
### Checkpoints & Session Management

CommandDescription
/resume listList auto-saved sessions
/resume save Save checkpoint with tag
/resume resume Resume saved session
/resume delete Delete checkpoint
/resume share [filename]Export as Markdown/JSON
/resume debugExport API request JSON
/restoreUndo file changes from tool execution
### Model & Generation

CommandDescription
/model set [--persist]Switch model (optional persist)
/model manageOpen model config dialog
/planSwitch to Plan Mode (read-only)
/initGenerate GEMINI.md context file
/memory showShow combined context
/memory listList GEMINI.md files in use
/memory refreshReload context files
/statsSession statistics
/stats modelToken/quota usage stats
/stats toolsTool usage stats
### Agents & MCP

CommandDescription
/agents listList all subagents
/agents enable Enable subagent
/agents disable Disable subagent
/agents config Configure subagent
/agents reloadRescan agents directories
/mcp listList MCP servers/tools
/mcp descList MCP with descriptions
/mcp enable Enable MCP server
/mcp disable Disable MCP server
/mcp reloadReload MCP servers
/mcp schemaList MCP with schemas
/mcp auth Initiate MCP OAuth flow
### Extensions & Custom Commands

CommandDescription
/extensions listList installed extensions
/extensions install Install extension from git
/extensions update Update extension
/extensions uninstall Uninstall extension
/commands listList custom commands
/commands reloadReload custom commands
### Configuration & Tools

CommandDescription
/settingsOpen settings editor
/authChange auth method
/themeChange visual theme
/vimToggle vim mode
/editorSelect preferred editor
/directory add Add workspace directory
/directory showShow workspace dirs
/toolsList available tools
/tools descList tools with descriptions
/permissions trust Trust directory
/setup-githubSetup GitHub Actions CI
### System

CommandDescription
/aboutShow version info
/bugFile a bug report
/docsOpen docs in browser
/upgradeUpgrade to Code Assist
/hooks listList lifecycle hooks
/privacyShow privacy notice
/shellsToggle background shells view
/terminal-setupConfigure multiline keybindings

Configuration File Examples

### Minimal .gemini/settings.json

`json { "theme": "GitHub Dark", "vimMode": false, "autoAccept": true, "general": { "preferredEditor": "cursor" }, "checkpointing": { "enabled": true } } `

### MCP Server Config

`json { "mcpServers": { "my-tools": { "command": "node", "args": ["path/to/mcp-server.js"], "env": { "API_KEY": "$MY_API_TOKEN" } } } } `

Built-in Tools

Gemini CLI includes these built-in capabilities:

CategoryTools
File Systemlist_directory, glob, read_file, write_file, replace, search_file_content
Shellrun_shell_command (executes shell commands — restrict with excludeTools in settings)
Webgoogle_web_search, web_fetch
Memorysave_memory(fact="...") — persist information across sessions

Tips & Tricks

- Multi-directory projects: Use --include-directories flag or /directory add in CLI. - Token efficiency: Run /compress when the conversation gets long. - Subagents: Create sub-directories in ~/.gemini/agents/ for specialized subagent configs. - Checkpoint before risky operations: Enable checkpointing and save with /resume save before-risky-op. - Sandbox for dangerous commands: Use --sandbox flag to isolate tool execution in Docker/Podman. - Custom commands: Create .toml files in ~/.gemini/commands/ for reusable slash commands. - JSON scripting: Use --output-format json` to parse Gemini CLI output programmatically.

Setup & Auth(6)

CommandLevel
npm install -g @google/gemini-cli
Install Gemini CLI globally
Basic
npx @google/gemini-cli
Run Gemini CLI directly without installation
Basic
brew install gemini-cli
Install Gemini CLI via Homebrew
Basic
export GEMINI_API_KEY="YOUR_KEY"
Set Gemini API key environment variable
Basic
export GOOGLE_CLOUD_PROJECT="YOUR_PROJECT_ID"
Set Google Cloud project ID (for Vertex AI auth)
Intermediate
export GOOGLE_APPLICATION_CREDENTIALS="/path/to/key.json"
Set service account JSON key path (Vertex AI service account auth)
Intermediate

Basic Usage(16)

CommandLevel
gemini
Start interactive Gemini CLI session (default mode)
Basic
gemini -p "prompt"
Run in non-interactive mode with a single prompt
Basic
gemini -m gemini-2.5-flash
Specify Gemini model to use
Basic
gemini --include-directories ../lib,../docs
Include multiple directories in workspace
Intermediate
gemini --sandbox -p "prompt"
Run in sandboxed environment (requires Docker/Podman)
Intermediate
gemini --output-format json
Output in JSON format (for scripting)
Intermediate
gemini --output-format stream-json
Output as real-time event stream JSON
Intermediate
gemini --yolo
Auto-approve all tool calls (no confirmation)
Expert
gemini -d
Enable debug mode
Intermediate
gemini -i "initial prompt"
Start interactive mode with an initial prompt
Basic
echo "Count to 10" | gemini
Pipe input to Gemini CLI
Basic
/help
Display built-in help
Basic
/clear
Clear terminal screen (Ctrl+L shortcut)
Basic
/about
Show version info
Basic
/quit
Exit the CLI
Basic
/quit --delete
Exit and permanently delete session data
Intermediate

Generation(12)

CommandLevel
/init
Analyze current directory and generate a tailored GEMINI.md context file
Basic
/model set gemini-2.5-pro [--persist]
Switch model and optionally persist the setting
Basic
/model manage
Open model configuration dialog
Basic
/compress
Replace chat context with a summary to save tokens
Intermediate
/plan
Switch to Plan Mode (read-only)
Basic
/memory show
Display full concatenated GEMINI.md context content
Basic
/memory list
List all GEMINI.md file paths in use
Basic
/memory refresh
Reload all GEMINI.md context files
Basic
/stats
Show current session statistics (duration, tool calls, etc.)
Basic
/stats model
Show model token usage and quota stats
Intermediate
/stats tools
Show tool usage frequency statistics
Intermediate
/copy
Copy last CLI output to clipboard
Basic

Chat & Stream(7)

CommandLevel
/resume list
List auto-saved session history
Basic
/resume save <tag>
Create a checkpoint tag for the current session
Basic
/resume resume <tag>
Resume a previously saved session
Basic
/resume delete <tag>
Delete a saved checkpoint
Basic
/resume share <filename>
Export session to Markdown or JSON file
Intermediate
/resume debug
Export most recent API request as JSON payload
Expert
/rewind
Navigate backward through conversation history
Basic

Configuration(10)

CommandLevel
/editor
Open editor selection dialog
Basic
/settings
Open settings editor (settings.json)
Basic
/auth
Change authentication method
Basic
/theme
Change visual theme
Basic
/vim
Toggle vim mode on/off
Intermediate
/directory add <path>
Add a workspace directory
Intermediate
/directory show
Show all added workspace directories
Basic
/commands list
List all custom slash commands
Intermediate
/commands reload
Reload custom commands without restarting
Intermediate
/permissions trust <path>
Trust a directory for tool access
Intermediate

Model Management(16)

CommandLevel
/agents list
List all subagents (built-in, local, remote)
Intermediate
/agents enable <name>
Enable a specific subagent
Intermediate
/agents disable <name>
Disable a specific subagent
Intermediate
/agents config <name>
Configure subagent (model, temperature, limits)
Expert
/agents reload
Rescan ~/.gemini/agents and .gemini/agents
Intermediate
/mcp list
List all MCP servers and tools
Intermediate
/mcp desc
List MCP servers with descriptions
Intermediate
/mcp enable <name>
Enable a specific MCP server
Intermediate
/mcp disable <name>
Disable a specific MCP server
Intermediate
/mcp reload
Reload MCP servers
Intermediate
/mcp schema
List MCP servers with descriptions and JSON Schemas
Expert
/extensions list
List installed extensions
Intermediate
/extensions install <repo>
Install extension from git repo
Intermediate
/tools
List all available tools
Basic
/tools desc
List tools with descriptions
Basic
/setup-github
Set up GitHub Actions automation (issue triage/PR review)
Intermediate

File Management(1)

CommandLevel
/restore
Restore project files to state before tool execution
Intermediate

FAQ

This cheatsheet is compiled from official tool documentation. Last updated: 2026-07-20.