This python program allows you to use Claude Code with Google's Gemini models.
# Add to your Claude Code skills
git clone https://github.com/coffeegrind123/gemini-for-claude-codeThis server acts as a bridge, enabling you to use Claude Code with Google's powerful Gemini models. It translates API requests and responses between the Anthropic format (used by Claude Code) and the Gemini format (via LiteLLM), allowing seamless integration.

haiku, sonnet, opus aliases) to your chosen Gemini models./health and /test-connection for easier troubleshooting of your setup.No comments yet. Be the first to share your thoughts!
/v1/messages/count_tokensnpm install -g @anthropic-ai/claude-code).Clone the repository:
git clone https://github.com/coffeegrind123/gemini-code.git # Or your fork
cd gemini-code
Create and activate a virtual environment (recommended):
python3 -m venv .venv
source .venv/bin/activate
Install dependencies:
pip install -r requirements.txt
Configure Environment Variables: Copy the example environment file:
cp .env.example .env
Edit .env and add your Gemini API key. You can also customize model mappings and server settings:
# Required: Your Google AI Studio API key
GEMINI_API_KEY="your-google-ai-studio-key"
# Optional: Model mappings for Claude Code aliases
BIG_MODEL="gemini-1.5-pro-latest" # For 'sonnet' or 'opus' requests
SMALL_MODEL="gemini-1.5-flash-latest" # For 'haiku' requests
# Optional: Server settings
HOST="0.0.0.0"
PORT="8082"
LOG_LEVEL="WARNING" # DEBUG, INFO, WARNING, ERROR, CRITICAL
# Optional: Performance and reliability settings
MAX_TOKENS_LIMIT="8192" # Max tokens for Gemini responses
REQUEST_TIMEOUT="90" # Request timeout in seconds
MAX_RETRIES="2" # LiteLLM retries to Gemini
MAX_STREAMING_RETRIES="12" # Streaming-specific retry attempts
# Optional: Streaming control (use if experiencing issues)
FORCE_DISABLE_STREAMING="false" # Disable streaming globally
EMERGENCY_DISABLE_STREAMING="false" # Emergency streaming disable
Run the server:
The server.py script includes a main() function that starts the Uvicorn server:
python server.py
For development with auto-reload (restarts when you save changes to server.py):
uvicorn server:app --host 0.0.0.0 --port 8082 --reload
You can view all startup options, including configurable environment variables, by running:
python server.py --help
Start the Proxy Server: Ensure the Gemini proxy server (this application) is running (see step 5 above).
Configure Claude Code to Use the Proxy:
Set the ANTHROPIC_BASE_URL environment variable when running Claude Code:
ANTHROPIC_BASE_URL=http://localhost:8082 claude
Replace localhost:8082 if your proxy is running on a different host or port.
Utilize CLAUDE.md for Optimal Gemini Performance (Crucial):
This repository includes a CLAUDE.md file. This file contains specific instructions and best practices tailored to help Gemini effectively understand and respond to Claude Code's unique command structure, tool usage patterns, and desired output formats.
Copy CLAUDE.md into your project directory:
cp /path/to/gemini-code/CLAUDE.md /your/project/directory/
When starting a new conversation with Claude Code in that directory, begin with:
First read and process CLAUDE.md with intent. After understanding and agreeing to use the policies and practices outlined in the document, respond with YES
This ensures Gemini receives important context and instructions for better assistance.
If Gemini still fucks up, ask it to read CLAUDE.md again. This might or might not help!
http://localhost:8082).claude-3-sonnet...) to the corresponding Gemini model specified in your .env (e.g., gemini-1.5-pro-latest).GEMINI_API_KEY.To ensure Claude Code's model requests are handled correctly by Gemini:
claude-3-haiku-20240307) are mapped to the Gemini model specified by your SMALL_MODEL environment variable (default: gemini-1.5-flash-latest).claude-3-sonnet-20240229, claude-3-opus-20240229) are mapped to the Gemini model specified by your BIG_MODEL environment variable (default: gemini-1.5-pro-latest).gemini/gemini-1.5-pro-latest), the proxy will use that directly.The server maintains a list of known Gemini models. If a recognized Gemini model is requested by the client without the gemini/ prefix, the proxy will add it.
POST /v1/messages: The primary endpoint for Claude Code to send messages to Gemini. It's fully compatible with the Anthropic Messages API specification that Claude Code uses.POST /v1/messages/count_tokens: Allows Claude Code to estimate the token count for a set of messages, using Gemini's tokenization.GET /health: Returns the health status of the proxy, including API key configuration, streaming settings, and basic API key validation.GET /test-connection: Performs a quick API call to Gemini to verify connectivity and that your GEMINI_API_KEY is working.GET /: Root endpoint providing a welcome message, current configuration summary (models, limits), and available endpoints.Streaming Errors (malformed chunks):
FORCE_DISABLE_STREAMING=true as a temporary fixMAX_STREAMING_RETRIES for more resilient streamingGemini 500 Internal Server Errors:
/health endpoint to monitor API statusConnection Timeouts:
REQUEST_TIMEOUT if experiencing frequent timeouts/test-connection endpoint to verify API connectivityRate Limiting: