Gemini CLI Integration
Connect Plexus with Google Gemini CLI to monitor AI-powered terminal sessions.
Gemini CLI is Google's open-source AI terminal assistant that brings the power of Gemini directly into your command line. Plexus can monitor your Gemini CLI sessions, tracking AI interactions, tool usage, and costs across all your projects.
What is Gemini CLI?
Gemini CLI is an open-source AI agent that runs in your terminal, powered by Google's Gemini 2.5 Pro model. Key features include:
- 1M Token Context Window - Process large codebases and documentation in a single session
- Built-in Tools - Google Search grounding, file operations, shell commands, and web fetching
- MCP Support - Model Context Protocol integration for custom tools and data sources
- GEMINI.md Files - Project-specific instructions that tailor AI behavior
- Hooks System - Lifecycle event hooks for customizing agent behavior
- Free Tier - 60 requests per minute and 1,000 requests per day at no cost
Gemini CLI is fully open-source under the Apache 2.0 license.
How Plexus Integrates with Gemini CLI
Plexus monitors Gemini CLI through its native hooks system, capturing AI interactions in real-time:
┌─────────────────────────────────────────────────┐
│ Terminal Session │
│ │
│ ┌──────────────────────────────────────────┐ │
│ │ Gemini CLI Agent │ │
│ │ │ │
│ │ ┌────────────┐ ┌────────────────────┐ │ │
│ │ │ Model │ │ Built-in Tools │ │ │
│ │ │ Request │ │ (Shell, Files, │ │ │
│ │ │ │ │ Search, etc.) │ │ │
│ │ └─────┬──────┘ └────────┬───────────┘ │ │
│ │ │ │ │ │
│ │ └────────┬─────────┘ │ │
│ │ ▼ │ │
│ │ ┌──────────────────────────────────┐ │ │
│ │ │ Gemini CLI Hooks Layer │ │ │
│ │ │ (BeforeTool, AfterTool, etc.) │ │ │
│ │ └──────────────────────────────────┘ │ │
│ └──────────────────┼───────────────────────┘ │
│ │ │
└─────────────────────┼───────────────────────────┘
▼
┌───────────────┐
│ Plexus │
│ Dashboard │
└───────────────┘Monitored Events
| Lifecycle Event | What Plexus Tracks |
|---|---|
| SessionStart | New session initialization, project context |
| BeforeModel | Prompts sent to Gemini, context size |
| AfterModel | AI responses, token usage |
| BeforeTool | Tool arguments, validation |
| AfterTool | Tool results, execution time |
| SessionEnd | Session duration, total usage |
Installing Gemini CLI
Prerequisites
- Node.js 20 or later - Required to run Gemini CLI
- Plexus - Already installed on your system
Installation via npm
npm install -g @google/gemini-cliInstallation via Other Package Managers
Using pnpm:
pnpm add -g @google/gemini-cliUsing yarn:
yarn global add @google/gemini-cliUsing Homebrew (macOS):
brew install gemini-cliVerify Installation
gemini --versionAuthentication Setup
After installation, run gemini in your terminal to start the setup wizard:
Option 1: Login with Google (Recommended)
- Run
geminiin your terminal - Select Login with Google when prompted
- A browser window opens for Google authentication
- Complete the login process
- Return to your terminal - you're ready to go
This method provides free access with:
- 60 requests per minute
- 1,000 requests per day
- Access to Gemini 2.5 Pro
Option 2: API Key Authentication
For higher limits or enterprise use, authenticate with an API key:
- Visit Google AI Studio
- Create or select an API key
- Set the environment variable:
export GEMINI_API_KEY="your-api-key-here"Add to your shell profile (~/.zshrc, ~/.bashrc, etc.) for persistence:
echo 'export GEMINI_API_KEY="your-api-key-here"' >> ~/.zshrc
source ~/.zshrcOption 3: Vertex AI (Enterprise)
For Google Cloud users with Vertex AI access:
export GOOGLE_API_KEY="your-api-key"
export GOOGLE_GENAI_USE_VERTEXAI=true
export GOOGLE_CLOUD_PROJECT="your-project-id"Setting Up the Plexus Integration
Automatic Setup
When you first launch Plexus with Gemini CLI installed, the integration is configured automatically:
- Launch Plexus from your Applications folder
- Plexus detects Gemini CLI and installs the necessary hooks
- Open a terminal and run
gemini- sessions will appear in Plexus
Manual Setup
If automatic setup doesn't work, configure the integration manually:
- Open Plexus and go to Settings > Agents
- Find Gemini CLI in the list and click Configure
- Follow the on-screen instructions to install hooks
Verifying the Integration
To verify Plexus is connected to Gemini CLI:
- Open a terminal and run
gemini - Send a test message like "Hello, what can you do?"
- Check the Plexus dashboard - a new Gemini session should appear
Gemini CLI Configuration Files
Gemini CLI uses several configuration files that Plexus respects and monitors:
Configuration Locations
| File | Location | Purpose |
|---|---|---|
| settings.json | ~/.gemini/settings.json | Global user preferences |
| GEMINI.md | ~/.gemini/GEMINI.md | Global AI instructions |
| Project settings | .gemini/settings.json | Project-specific configuration |
| Project GEMINI.md | GEMINI.md or .gemini/GEMINI.md | Project-specific AI instructions |
Settings Structure
The settings.json file uses a structured format:
{
"theme": "dark",
"model": {
"default": "gemini-2.5-pro"
},
"tools": {
"enabled": ["run_shell_command", "read_file", "write_file"]
},
"hooks": {
"BeforeTool": [],
"AfterTool": []
}
}GEMINI.md Context Files
GEMINI.md files provide instructions that customize AI behavior for your projects:
# Project Guidelines
This is a TypeScript project using React and Next.js.
## Coding Standards
- Use functional components with hooks
- Prefer TypeScript strict mode
- Follow the existing code style
## File Structure
- Components in `src/components/`
- Pages in `app/`
- Utilities in `src/lib/`Generate a starter GEMINI.md file:
gemini /initHooks Configuration for Plexus
Plexus uses Gemini CLI's hooks system to monitor sessions. The hooks are configured in ~/.gemini/settings.json:
Plexus Hook Configuration
{
"hooks": {
"SessionStart": [
{
"name": "plexus-session-start",
"type": "command",
"command": "~/.plexus/hooks/gemini/session-start.sh",
"timeout": 5000
}
],
"BeforeTool": [
{
"name": "plexus-before-tool",
"type": "command",
"command": "~/.plexus/hooks/gemini/before-tool.sh",
"timeout": 5000
}
],
"AfterTool": [
{
"name": "plexus-after-tool",
"type": "command",
"command": "~/.plexus/hooks/gemini/after-tool.sh",
"timeout": 5000
}
],
"SessionEnd": [
{
"name": "plexus-session-end",
"type": "command",
"command": "~/.plexus/hooks/gemini/session-end.sh",
"timeout": 5000
}
]
}
}Note: Plexus automatically manages these hooks. You don't need to configure them manually unless troubleshooting.
Monitoring AI Features
Session Tracking
Plexus monitors all Gemini CLI sessions including:
- Session start and end times
- Active project/directory
- Total requests and token usage
- Cost estimation
Tool Usage
When Gemini CLI uses built-in tools, Plexus tracks:
| Tool | What Plexus Tracks |
|---|---|
run_shell_command | Commands executed, output, exit codes |
read_file | Files accessed, content size |
write_file | Files modified, changes made |
search_web | Search queries, sources used |
read_url | URLs fetched, content retrieved |
Context Window Usage
Plexus monitors your context window utilization:
- Input tokens per request
- Output tokens generated
- Total context size
- Remaining capacity in 1M token window
Cost Tracking
Plexus tracks API costs for Gemini CLI sessions:
Free Tier Limits
| Limit | Value |
|---|---|
| Requests per minute | 60 |
| Requests per day | 1,000 |
| Model | Gemini 2.5 Pro |
| Context Window | 1M tokens |
API Key Pricing (Pay-as-you-go)
| Model | Input (per 1M tokens) | Output (per 1M tokens) |
|---|---|---|
| Gemini 2.5 Pro | $1.25 - $2.50 | $5.00 - $10.00 |
| Gemini 2.5 Flash | $0.075 | $0.30 |
Note: Pricing may vary. Check Google AI pricing for current rates.
Viewing Cost Breakdown
- Click on a Gemini session in the dashboard
- Select the Costs tab
- View token usage and estimated costs
MCP Server Integration
Gemini CLI supports MCP (Model Context Protocol) servers for extended functionality. Plexus monitors these connections.
MCP Configuration
Configure MCP servers in ~/.gemini/settings.json:
{
"mcpServers": {
"github": {
"command": "npx",
"args": ["-y", "@modelcontextprotocol/server-github"],
"env": {
"GITHUB_TOKEN": "${GITHUB_TOKEN}"
}
},
"filesystem": {
"command": "npx",
"args": ["-y", "@modelcontextprotocol/server-filesystem", "/path/to/allowed/dir"]
}
}
}What Plexus Monitors
- Active MCP server connections
- Tool calls made through MCP
- Data retrieved from external sources
- Connection status and errors
Troubleshooting
Gemini CLI Sessions Not Appearing
If Gemini CLI sessions don't appear in Plexus:
- Verify Plexus is running - Check your system tray/menu bar
- Check Gemini CLI installation - Run
gemini --version - Restart Gemini CLI - Exit and run
geminiagain - Reinstall hooks - Go to Plexus Settings > Agents > Gemini CLI > Reinstall
Hook Installation Failed
If Plexus can't install hooks:
-
Check that
~/.gemini/directory exists:ls -la ~/.gemini/ -
Verify settings.json is writable:
touch ~/.gemini/settings.json -
Manually verify hooks in settings:
cat ~/.gemini/settings.json | grep -A 10 "hooks"
Authentication Issues
If Gemini CLI won't authenticate:
-
Clear cached credentials:
rm -rf ~/.gemini/credentials gemini -
Try API key authentication:
export GEMINI_API_KEY="your-key" gemini -
Check network access to Google services
High Token Usage
If you're hitting rate limits:
- Use
/compactcommand to compress conversation history - Start new sessions for unrelated tasks
- Use specific file references instead of reading entire directories
- Consider upgrading to API key authentication for higher limits
Tool Execution Errors
If tools fail to execute:
- Check sandbox mode isn't blocking operations
- Verify file permissions for read/write operations
- Ensure shell commands have proper PATH access
- Check Gemini CLI logs for detailed errors
MCP Servers Not Connecting
If MCP servers aren't working:
- Verify MCP server packages are installed
- Check environment variables are set correctly
- Test MCP server independently:
npx -y @modelcontextprotocol/server-github - Review Gemini CLI output for connection errors
Best Practices
Optimize Your Workflow
- Use GEMINI.md files - Provide project context to reduce repeated explanations
- Leverage the 1M context - Reference large files directly instead of summarizing
- Use specific prompts - Clear instructions reduce back-and-forth
Manage Token Usage
- Use
/compactregularly in long sessions - Start fresh sessions for new tasks
- Reference specific files with
@filenamesyntax - Monitor usage in Plexus dashboard
Security Considerations
- Review shell commands before execution
- Use sandbox mode for untrusted operations
- Be cautious with API keys in environment variables
- Monitor MCP server access through Plexus
CLI Commands Reference
Common Gemini CLI commands:
| Command | Description |
|---|---|
gemini | Start interactive session |
gemini "prompt" | Run single prompt |
gemini -m gemini-2.5-flash | Use specific model |
/help | Show available commands |
/settings | Open settings interface |
/compact | Compress conversation history |
/init | Generate GEMINI.md file |
/hooks | Manage hooks configuration |
/memory refresh | Reload GEMINI.md files |
Next Steps
- Learn about Webhook Notifications for team alerts
- Explore Configuration Options for advanced settings
- Check Keyboard Shortcuts for faster navigation