🤖 Intelligent integration between Claude Code and Google Gemini for large-scale code analysis
The Claude-Gemini Bridge automatically delegates complex code analysis tasks from Claude Code to Google Gemini, combining Claude's reasoning capabilities with Gemini's large context processing power.
# Clone and install for all projects in one simple process
git clone https://github.com/your-username/claude-gemini-bridge.git
cd claude-gemini-bridge
./install.sh
# IMPORTANT: Restart Claude Code to load the new hooks# (Hooks are only loaded once at startup)# Test the installation
./test/test-runner.sh
# Use Claude Code normally - large analyses will automatically use Gemini!
claude "analyze all Python files in this project"
The installer:
✅ Works in the current directory (no separate installation location)
✅ Automatically merges with existing Claude hooks in ~/.claude/settings.json
graph TB
subgraph "Claude Code"
CC[Claude Code CLI]
TC[Tool Call]
end
subgraph "Claude-Gemini Bridge"
HS[Hook System]
DE[Decision Engine]
PC[Path Converter]
CH[Cache Layer]
end
subgraph "External APIs"
GC[Gemini CLI]
GA[Gemini API]
end
CC -->|PreToolUse Hook| HS
HS --> PC
PC --> DE
DE -->|Delegate?| CH
CH -->|Yes| GC
GC --> GA
GA -->|Analysis| CH
CH -->|Response| HS
HS -->|Result| CC
DE -->|No| CC
style CC fill:#e1f5fe
style HS fill:#f3e5f5
style GC fill:#e8f5e8
style DE fill:#fff3e0
Loading
The bridge operates through Claude Code's hook system, intelligently deciding when to delegate tasks to Gemini:
sequenceDiagram
participant User
participant Claude as Claude Code
participant Bridge as Gemini Bridge
participant Gemini as Gemini API
User->>Claude: "Analyze these 20 Python files"
Claude->>Bridge: PreToolUse Hook (Glob *.py)
Bridge->>Bridge: Convert @ paths to absolute
Bridge->>Bridge: Count files (20 files)
Bridge->>Bridge: Calculate total size (500KB)
Bridge->>Bridge: Estimate tokens (~125k)
alt Token limit exceeded (>50k)
Bridge->>Bridge: Check if within Gemini limits (<800k)
Bridge->>Gemini: Analyze 20 files with context
Gemini->>Bridge: Structured analysis result
Bridge->>Claude: Replace tool call with Gemini result
Claude->>User: Comprehensive analysis from Gemini
else Multi-file Task (≥3 files)
Bridge->>Bridge: Check if Task operation
Bridge->>Gemini: Delegate multi-file analysis
Gemini->>Bridge: Analysis result
Bridge->>Claude: Replace with Gemini result
Claude->>User: Multi-file analysis from Gemini
else Small content (<50k tokens, <3 files)
Bridge->>Claude: Continue with normal execution
Claude->>Claude: Process files normally
Claude->>User: Standard Claude response
end
Currently Configurable (edit hooks/config/debug.conf):
# Debug configuration (WORKING)
DEBUG_LEVEL=2 # 0=off, 1=basic, 2=verbose, 3=trace
CAPTURE_INPUTS=true # Save hook inputs for analysis
MEASURE_PERFORMANCE=true # Enable timing measurements
DRY_RUN=false # Test mode without Gemini calls# Gemini API settings (WORKING)
GEMINI_CACHE_TTL=3600 # Cache responses for 1 hour
GEMINI_RATE_LIMIT=1 # 1 second between API calls
GEMINI_TIMEOUT=30 # 30 second API timeout
GEMINI_MAX_FILES=20 # Maximum files per Gemini call# File security (WORKING)
GEMINI_EXCLUDE_PATTERNS="*.secret|*.key|*.env|*.password|*.token|*.pem|*.p12"# Automatic maintenance (WORKING)
AUTO_CLEANUP_CACHE=true # Enable cache cleanup
CACHE_MAX_AGE_HOURS=24 # Clean cache older than 24h
AUTO_CLEANUP_LOGS=true # Enable log rotation
LOG_MAX_AGE_DAYS=7 # Keep logs for 7 days
Delegation Settings (configurable via debug.conf):
# Delegation thresholds (CONFIGURABLE)
MIN_FILES_FOR_GEMINI=3 # At least 3 files for Task operations
CLAUDE_TOKEN_LIMIT=50000 # Token limit for Claude delegation (~200KB)
GEMINI_TOKEN_LIMIT=800000 # Max tokens Gemini can handle
MAX_TOTAL_SIZE_FOR_GEMINI=10485760 # Max 10MB total size
Current Implementation:
Single global configuration file: hooks/config/debug.conf
All settings configurable via environment variables
Full project-specific configuration support
Simply use Claude Code normally - the bridge works transparently:
# These commands will automatically use Gemini for large analyses:
claude "analyze all TypeScript files and identify patterns"
claude "find security issues in @src/ directory"
claude "summarize the architecture of this codebase"
Project-Specific Configuration
The bridge currently uses a single configuration source:
Global Configuration: hooks/config/debug.conf (in bridge installation directory)
Runtime Overrides: Environment variables can override all config values including delegation thresholds
Project-Specific Settings
All delegation thresholds can now be overridden via environment variables.
What you CAN configure per project:
# project-claude-setup.shexport DEBUG_LEVEL=3 # Increase logging for this projectexport DRY_RUN=true # Disable Gemini calls (testing)export GEMINI_TIMEOUT=60 # Longer timeout for complex analysisexport CAPTURE_INPUTS=true # Save inputs for debugging# Override delegation thresholdsexport MIN_FILES_FOR_GEMINI=5 # Require more files before delegatingexport CLAUDE_TOKEN_LIMIT=30000 # Delegate earlier (smaller limit)export MAX_TOTAL_SIZE_FOR_GEMINI=5242880 # 5MB limit for this project# Source before using Claudesource ./project-claude-setup.sh
claude "analyze this project"
# Enable verbose debuggingecho"DEBUG_LEVEL=3">>${CLAUDE_GEMINI_BRIDGE_DIR:-~/.claude-gemini-bridge}/hooks/config/debug.conf
# Test without calling Geminiecho"DRY_RUN=true">>${CLAUDE_GEMINI_BRIDGE_DIR:-~/.claude-gemini-bridge}/hooks/config/debug.conf
# View live logs
tail -f ${CLAUDE_GEMINI_BRIDGE_DIR:-~/.claude-gemini-bridge}/logs/debug/$(date +%Y%m%d).log
🔍 Verifying Gemini Integration
How to See if Gemini is Actually Called
1. Real-time Log Monitoring
# Monitor live logs while using Claude Code
tail -f ${CLAUDE_GEMINI_BRIDGE_DIR:-~/.claude-gemini-bridge}/logs/debug/$(date +%Y%m%d).log
# Filter for Gemini-specific entries
tail -f ${CLAUDE_GEMINI_BRIDGE_DIR:-~/.claude-gemini-bridge}/logs/debug/$(date +%Y%m%d).log | grep -i gemini
2. Enable Verbose Debug Output
# Set maximum debug levelecho"DEBUG_LEVEL=3">>${CLAUDE_GEMINI_BRIDGE_DIR:-~/.claude-gemini-bridge}/hooks/config/debug.conf
# Now run a Claude command that should trigger Gemini
claude "analyze all Python files in @src/ directory"
[INFO] Processing tool: Read
[DEBUG] File count: 1 (minimum: 3)
[DEBUG] Not enough files for Gemini delegation
[INFO] Continuing with normal tool execution
4. Force Gemini Delegation for Testing
# Temporarily lower thresholds to force delegationecho"MIN_FILES_FOR_GEMINI=1">> hooks/config/debug.conf
echo"MIN_FILE_SIZE_FOR_GEMINI=1">> hooks/config/debug.conf
# Test with a simple file
claude "analyze @README.md"# Reset thresholds afterwardsecho"MIN_FILES_FOR_GEMINI=3">> hooks/config/debug.conf
echo"MIN_FILE_SIZE_FOR_GEMINI=10240">> hooks/config/debug.conf
5. Check Cache for Gemini Responses
# List cached Gemini responses
ls -la cache/gemini/
# View a cached response
find cache/gemini/ -name "*" -type f -exec echo"=== {} ==="\; -exec cat {} \; -exec echo\;
Cache hits: "Using cached result" for repeated queries
7. Test with Interactive Tool
# Use the interactive tester to simulate Gemini calls${CLAUDE_GEMINI_BRIDGE_DIR:-~/.claude-gemini-bridge}/test/manual-test.sh
# Choose option 3 (Multi-File Glob) or 2 (Task Search) to trigger Gemini
8. Dry Run Mode for Debugging
# Enable dry run to see decision logic without calling Geminiecho"DRY_RUN=true">>${CLAUDE_GEMINI_BRIDGE_DIR:-~/.claude-gemini-bridge}/hooks/config/debug.conf
# Run Claude command - you'll see "DRY RUN: Would call Gemini" instead of actual calls
claude "analyze @src/ @docs/ @test/"# Disable dry run
sed -i '''/DRY_RUN=true/d'${CLAUDE_GEMINI_BRIDGE_DIR:-~/.claude-gemini-bridge}/hooks/config/debug.conf
# Run full test suite${CLAUDE_GEMINI_BRIDGE_DIR:-~/.claude-gemini-bridge}/test/test-runner.sh
# Test individual components${CLAUDE_GEMINI_BRIDGE_DIR:-~/.claude-gemini-bridge}/hooks/lib/path-converter.sh
${CLAUDE_GEMINI_BRIDGE_DIR:-~/.claude-gemini-bridge}/hooks/lib/json-parser.sh
${CLAUDE_GEMINI_BRIDGE_DIR:-~/.claude-gemini-bridge}/hooks/lib/gemini-wrapper.sh
# Interactive test tool${CLAUDE_GEMINI_BRIDGE_DIR:-~/.claude-gemini-bridge}/test/manual-test.sh
# Fork and clone
git clone https://github.com/your-username/claude-gemini-bridge.git
cd claude-gemini-bridge
# Run tests before committing
./test/test-runner.sh