Overview
The Gemini bridge wraps thegemini CLI (from @google/gemini-cli), Google’s terminal-based coding agent. Gemini CLI supports model aliases, approval modes (default, auto_edit, yolo, plan), sandbox isolation, extensions, MCP servers, policy files, session management, and stream-json event streaming. It provides token usage data including cached token counts.
The bridge is implemented by GeminiBridge and configured through GeminiBridgeBuilder. Access the builder through the AgentCtrl facade:
Prerequisites
Install Gemini CLI globally:Basic Usage
Model Selection
Gemini CLI supports model aliases and full model names:Approval Modes
Gemini CLI supports four approval modes that control how tool execution is approved:Sandbox Mode
Enable sandboxed execution for process isolation:sandbox-exec). Docker, Podman, and gVisor are also supported.
System Prompt
Gemini CLI reads instructions from aGEMINI.md file in the project root (similar to CLAUDE.md). You can also set the GEMINI_SYSTEM_MD environment variable to point to a custom system prompt file.
Include Directories
Add additional workspace directories for the agent to access:Extensions
Use specific extensions:MCP Servers
Restrict which MCP servers are available:Policy Files
Load additional policy files for fine-grained tool approval rules:Allowed Tools
Restrict which tools the agent can use:Debug Mode
Enable debug output for troubleshooting CLI behavior:Streaming with Gemini
Gemini streams output as JSONL with thestream-json format. The bridge normalizes these into the standard callback API:
Event Normalization
Gemini emits stream-json events that are normalized:message(role=assistant, delta=true) — Text deltas delivered throughonText().tool_result— Tool results delivered throughonToolUse()with tool name, input (from pairedtool_useevent), result, and error status.error— Errors delivered throughonError()with severity and message.init,tool_use,result— Lifecycle events available through thewiretap()event system.
Session Management
Gemini CLI maintains session history. Agent-Ctrl extracts session IDs from theinit event:
Usage Data
Gemini provides token usage data from theresult event stats:
Data Availability
| Data Point | Available | Notes |
|---|---|---|
| Text output | Yes | Extracted from message events (role=assistant, delta=true) |
| Tool calls | Yes | Normalized from tool_use + tool_result event pairs |
| Session ID | Yes | Extracted from init event |
| Token usage | Yes | Input, output, cached tokens from result stats |
| Cost | No | Gemini CLI does not expose cost data |
| Parse diagnostics | Yes | Malformed JSON line counts and samples |
Complete Example
Comparison with Other Bridges
| Feature | Claude Code | Codex | OpenCode | Pi | Gemini |
|---|---|---|---|---|---|
| System prompts | Yes (replace + append) | No | No | Yes (replace + append) | Yes (GEMINI.md file) |
| Permission modes | Yes (4 levels) | No | No | No | Yes (4 modes) |
| Turn limits | Yes | No | No | No | Yes (via settings) |
| Sandbox modes | No | Yes (3 levels) | No | No | Yes (Seatbelt/Docker/Podman/gVisor) |
| Image input | No | Yes | No | No | No |
| Thinking levels | No | No | No | Yes (6 levels) | No |
| Named agents | No | No | Yes | No | No |
| File attachments | No | No | Yes | Yes (@-prefix) | No |
| Extensions | No | No | No | Yes (TypeScript) | Yes |
| Skills | No | No | No | Yes | No |
| Tool control | No | No | No | Yes (select/disable) | Yes (allowlist) |
| MCP servers | No | No | No | No | Yes |
| Policy engine | No | No | No | No | Yes |
| Session sharing | No | No | Yes | No | No |
| Session titles | No | No | Yes | No | No |
| Ephemeral mode | No | No | No | Yes | No |
| API key override | No | No | No | Yes | No |
| Token usage | No | Yes (partial) | Yes (full) | Yes | Yes |
| Cost tracking | No | No | Yes | Yes | No |
| Multi-provider models | No | No | Yes | Yes | No |
| Include directories | No | No | No | No | Yes |
| Debug mode | No | No | No | No | Yes |
| Free tier | No | No | No | No | Yes |
Environment Variables
| Variable | Description |
|---|---|
GEMINI_API_KEY | Gemini API key |
GOOGLE_API_KEY | Google Cloud API key |
GOOGLE_APPLICATION_CREDENTIALS | Service account JSON path |
GOOGLE_CLOUD_PROJECT | Project ID for Code Assist |
GOOGLE_GENAI_USE_VERTEXAI | Enable Vertex AI |
GEMINI_SANDBOX | Enable sandbox without CLI flag |