Appearance
♊ Gemini CLI Reference Guide
Gemini CLI is an interactive, terminal-based developer tool designed to interface directly with Google Gemini models. It allows developers to run prompt templates, pipe terminal outputs to LLMs, and register custom slash commands for automated workspace workflow steps.
📊 Tool Datasheet
| Metric | Details |
|---|---|
| Tool Name | Gemini CLI |
| Category | Interactive Developer CLI Assistant |
| Purpose | To provide rapid, shell-integrated prompting, context building, and command automation directly from your terminal session. |
| Developer | |
| License | Apache 2.0 |
| CLI Commands | gemini (initialized via npx @google/gemini-cli) |
🛠️ Capabilities
- Shell Output Piping: Pipe code, logs, and directory structures directly into prompts using standard redirection (
cat file.py | gemini). - Slash Command TOML Mappings: Map complex system instructions and prompt templates to simple slash commands defined in the local
.gemini/commands/workspace directory. - Active Workspace Context: Automatically loads rules and metadata defined in the local
.gemini/GEMINI.mdcontext file. - Local Shell Passthrough: Execute system commands and shell scripts directly from the interactive REPL prompt using the
!prefix. - Autonomous Tool Execution (YOLO Mode): Execute shell operations and script generations autonomously on behalf of the developer.
- State Checkpointing: Automatically logs snapshots of files before execution, allowing rollback operations.
🧭 Step-by-Step Tutorial & Setup
This tutorial guides you through setting up a workspace-specific context, registering custom commands, and leveraging shell passthrough utilities.
1. Initialize the Workspace Context
Create the required local settings folder at the root of your workspace:
bash
cd ~/AI_BOOTCAMP
npx @google/gemini-cli
gemini> /initThis command generates a .gemini/GEMINI.md context file at the root of your workspace. Overwrite it with your specific tech stack rules:
markdown
### AI_BOOTCAMP - Workspace Context
## Dev Environment
- **Primary Env**: Conda environment `ai_dev`
- **Package Manager**: `uv` (Rust-based)
- **Database**: PostgreSQL (port 5432)2. Register a Custom Slash Command
Create a configuration file at ~/AI_BOOTCAMP/.gemini/commands/explain/explain.toml using the placeholder for arguments:
toml
### Invoked inside Gemini CLI as: /explain "src/utils/jwt.py"
description = "Analyze a local file and generate a high-level architectural walkthrough."
prompt = """
Analyze the target code below:
{{args}}
Provide a high-level summary of the file's architectural purpose, major classes, and dependencies.
"""3. Inject Context & Run Passthroughs
Restart or refresh your Gemini session inside your workspace folder, then leverage context injection (@) and terminal passthrough (!):
bash
geminiWithin the interactive prompt:
text
### Query the custom command with target file context
gemini> /explain @./01_cli_tools/WorkflowOrchestrator_agent.py
### Run tests directly in the REPL session without exiting
gemini> !pytest -v 01_cli_tools/4. Enable YOLO & Checkpoint Recovery
Run the CLI in YOLO mode to allow autonomous edits, and list checkpoints to restore states if necessary:
bash
### Enable autonomous script updates
gemini --yolo --checkpointing
### Inside the session, if an edit is undesirable, check history and restore
gemini> /restore list
gemini> /restore 0💡 Sample Ideation to Test
Try these ideas to expand your Gemini CLI integration:
- Git Commit Generator: Configure a custom slash command
/committhat runs!git diffand pipes the resulting codebase changes into a prompt to output structured conventional commit messages. - Telemetry Tracer: Create a custom slash command
/trace:auditthat loads your telemetry spans and queries Gemini to pinpoint latency hotspots or unhandled exceptions.