claude-gemini-bridge
CLAUDE.md408 starsChanged 17 months agoMITView on GitHub
This file provides guidance to Claude Code (claude.ai/code) when working with the Claude-Gemini Bridge repository. The Claude-Gemini Bridge is an intelligent hook system that seamlessly integrates Claude Code with Google Gemini for large-scale code analysis tasks. When Claude Code encounters complex analysis requests, the bridge automatically delegates appropriate tasks to Gemini while maintaining Claude's control over the conversation flow. The bridge delegates to Gemini when: - Token Limit: Content exceeds ~50k tokens (~200KB, optimized for Claude's 200k context) - Multi-File…
- Reads credentials
- Deletes or force-pushes
The file
Show its rules and text
We split this CLAUDE.md into the rules it gives an agent
14 rules. About 0 are common, 9 are distinctive, and 5 are very specific to this project.
≈0
Common · estimate
Many files like this have a rule of this kind.
≈9
Distinctive · estimate
This author's own choices. Worth a look.
5
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Distinctive: line 57
All shell scripts use bash and follow POSIX compliance where possible
- Very specific: line 63
Use test/test-runner.sh for automated testing
- Very specific: line 64
Use test/manual-test.sh for interactive debugging
- Distinctive: line 65
All library functions include self-tests
- Very specific: line 70
Use DRY_RUN=true to test delegation logic without calling Gemini
- Distinctive: line 86
No elevated privileges required
- Distinctive: line 116
No modification of Claude Code required
- Very specific: line 127
Hook not executing: Check ~/.claude/settings.json configuration
- Very specific: line 128
Gemini not found: Verify gemini CLI is in PATH
- Distinctive: line 130
Permission errors: Ensure scripts are executable
- Distinctive: line 167
Update documentation for API changes
- Distinctive: line 168
Follow existing code style conventions
- Distinctive: line 169
Add debug logging for new components
- Distinctive: line 175
Test with latest version before reporting
≈ “Common” is an estimate: at least 1 in 5 of the 12,729 CLAUDE.md files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
CLAUDE.md
This file provides guidance to Claude Code (claude.ai/code) when working with the Claude-Gemini Bridge repository.
Project Overview
The Claude-Gemini Bridge is an intelligent hook system that seamlessly integrates Claude Code with Google Gemini for large-scale code analysis tasks. When Claude Code encounters complex analysis requests, the bridge automatically delegates appropriate tasks to Gemini while maintaining Claude's control over the conversation flow.
Architecture
Core Components
- Hook System: Uses Claude Code's PreToolUse hooks to intercept tool calls
- Path Converter: Translates Claude's
@notation to absolute file paths - Decision Engine: Intelligently determines when to delegate tasks to Gemini
- Caching Layer: Avoids redundant API calls with content-aware caching
- Debug System: Comprehensive logging and performance monitoring
How It Works
- Interception: Hook catches Claude's tool calls (Read, Glob, Grep, Task)
- Analysis: Decision engine evaluates file count, size, and task complexity
- Delegation: Large or complex tasks are sent to Gemini for processing
- Integration: Gemini's analysis is seamlessly returned to Claude
- Fallback: Failed delegations continue with normal Claude execution
Usage Patterns
Automatic Delegation Triggers
The bridge delegates to Gemini when:
- Token Limit: Content exceeds ~50k tokens (~200KB, optimized for Claude's 200k context)
- Multi-File Tasks: ≥3 files for Task operations (configurable)
- Safety Limits: Content must be ≤10MB and ≤800k tokens for Gemini processing
- File Exclusions: Automatically excludes sensitive files (*.secret, *.key, *.env, etc.)
Configuration
Key settings in hooks/config/debug.conf:
# Delegation thresholds (optimized for Claude 200k context)
MIN_FILES_FOR_GEMINI=3 # Delegate Task operations with ≥3 files
MIN_FILE_SIZE_FOR_GEMINI=5120 # Minimum 5KB total size
MAX_TOTAL_SIZE_FOR_GEMINI=10485760 # Maximum 10MB total size
# Debug and performance
DEBUG_LEVEL=2 # 0=off, 1=basic, 2=verbose, 3=trace
DRY_RUN=false # Test mode without Gemini callsSee README.md for complete configuration reference.
Development Guidelines
Code Style
- All shell scripts use bash and follow POSIX compliance where possible
- Comments are in English
- Functions include single-line ABOUTME comments explaining purpose
- Error handling with proper exit codes and logging
Testing
- Use
test/test-runner.shfor automated testing - Use
test/manual-test.shfor interactive debugging - All library functions include self-tests
Debugging
- Set
DEBUG_LEVEL=3for maximum verbosity - Enable
CAPTURE_INPUTS=trueto save tool calls for replay - Use
DRY_RUN=trueto test delegation logic without calling Gemini
Security Considerations
File Exclusions
The bridge automatically excludes sensitive files:
*.secret,*.key,*.env*.password,*.token,*.pem,*.p12
Rate Limiting
- 1 second between Gemini API calls (configurable)
- 100 requests/day quota monitoring
- Automatic cache cleanup to prevent data accumulation
Permissions
- Scripts run with user permissions only
- No elevated privileges required
- Logs stored in user directory
Performance Optimization
Delegation Strategy (Optimized 2024)
- Early delegation: Content >50k tokens (~200KB) goes to Gemini
- Multi-file threshold: Task operations with ≥3 files delegate automatically
- Efficient context usage: Claude reserves capacity for response generation
- Gemini utilization: Leverages 1M token capacity for large analysis tasks
Caching Strategy
- Content-aware cache keys based on file contents and metadata
- 1-hour default TTL with automatic cleanup
- Cache invalidation on file modifications
Resource Management
- Automatic memory cleanup after processing
- Background cache and log rotation
- Configurable file size limits
Performance Impact (2024 Optimization)
- Early delegation: Content >50k tokens (~200KB) → Gemini
- Multi-file threshold: ≥3 files for Task operations → Gemini
- Better coverage: Minimum size reduced to 5KB
Integration Points
Claude Code Integration
- Seamless hook integration via
settings.json - No modification of Claude Code required
- Preserves all existing Claude functionality
Gemini API Integration
- Direct CLI integration (no custom API wrappers)
- Automatic error handling and fallbacks
- Structured prompt generation based on task type
Troubleshooting
Common Issues
- Hook not executing: Check
~/.claude/settings.jsonconfiguration - Gemini not found: Verify
geminiCLI is in PATH - Cache issues: Clear cache with
rm -rf cache/gemini/* - Permission errors: Ensure scripts are executable
Debug Commands
# View recent logs
tail -f logs/debug/$(date +%Y%m%d).log
# Test individual components
hooks/lib/path-converter.sh
hooks/lib/json-parser.sh
hooks/lib/gemini-wrapper.sh
# Run full test suite
test/test-runner.sh
# Interactive testing
test/manual-test.shMonitoring
Performance Metrics
- Hook execution time
- Gemini processing duration
- Cache hit/miss ratios
- File processing statistics
Health Checks
- Automated testing in CI/CD
- Component-level validation
- API connectivity verification
- Resource usage monitoring
Contribution Guidelines
Pull Requests
- Include test coverage for new features
- Update documentation for API changes
- Follow existing code style conventions
- Add debug logging for new components
Issue Reporting
- Include debug logs and reproduction steps
- Specify Claude Code and Gemini CLI versions
- Provide sample inputs when possible
- Test with latest version before reporting
Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

