Use Claude Code with Google OAuth Login β No API key billing required
A blazing-fast proxy that lets you use Claude Code with Google's Gemini models through OAuth authentication. No API keys required, just your Google account, whether on free tier or Google AI Pro/Ultra Subscription.
- π Free Tier Access β Use Gemini through Google Cloud's OAuth, no API billing
- π Google AI Pro/Ultra Access β Access to higher limits and latest flagship models
- π Full Claude Code Support β Streaming, tool calls, vision, extended thinking
- β‘ Optimized Performance β Connection pooling, TCP keep-alive, minimal latency
- π§ Extended Thinking β Adaptive thinking (Claude 4.6)
- ποΈ Vision Support β Image analysis (JPEG, PNG, WebP, GIF, HEIC up to 100MB)
- π§ Tool Execution β File operations, bash commands, browser automation
- πΎ Context Caching β Reduce costs and latency with LRU-backed translation caching
- π Secure β OAuth with automatic token refresh, no credentials in code
- π Observable β Prometheus metrics endpoint for monitoring cache hit rates and API usage
Note
User Story
So, here's the deal: I have a Google Pro plan from last year, which gives you access to Google's latest models (including flagship models like the all-new Gemini 3 Pro/Flash). I want to use AI agents in my local terminal, but the problem is:
- Google's Gemini CLI is not cutting it for me, and I've heard Claude Code is the king of terminal agents, plus it has a vast tool library, plugins, and community support (led by Anthropic itself).
- Claude Code requires either a paid plan or API subscription which are costly (although worth it), and since I already have a Gemini Pro plan, buying API access or a paid plan on Claude would burn a hole in my pocket (yes, I am that broke) and is kind of a waste of money since I'd be paying twice.
So here's where my idea comes in: Claude Code already supports routing API calls to custom endpoints. My plan: Create a tool that serves a Claude Code-compatible API endpoint and routes the API call to Google's Gemini API via OAuth (not the traditional generative API endpoint). The tool connects to the same endpoint that Gemini Code Assist or Gemini CLI uses when authenticated via OAuth. What came out of the plan?: Gemini to Claude Code Proxy (gem2claude) that runs locally and route claude codes api calls to gemini models on google servers and the cycle continues.
| Claude Model | Gemini Backend | Context Caching | Best For |
|---|---|---|---|
claude-opus-4-6 |
gemini-3-pro-preview |
β | Top reasoning, adaptive thinking |
claude-sonnet-4-6 |
gemini-3-flash-preview |
β | Fastest reasoning, code review |
claude-haiku-4-6 |
gemini-2.5-flash |
β | fast responses |
claude-opus-4-5 |
gemini-3-pro-preview |
β | Complex reasoning, analysis, Coding |
claude-sonnet-4-5 |
gemini-3-flash-preview |
β | Fast responses & code review |
claude-haiku-4-5 |
gemini-2.5-pro |
β | Past Flagship Model |
git clone https://github.com/kelexine/gem2claude
cd gem2claude
cargo build --releaseYou need OAuth credentials your Google Account
After Build is complete: Simply Run:
./target/release/gem2claude --login- Follow the authentication flow
After authenticating, ~/.gemini/oauth_creds.json will be created automatically and proxy will start on it's own.
On subsiquent runs just run:
./target/release/gem2claudeProxy starts on http://127.0.0.1:8080
OAuth lifecycle is Managed by tge proxy, login once login forever.
export ANTHROPIC_BASE_URL="http://localhost:8080"
export ANTHROPIC_AUTH_TOKEN="dummy"Add to ~/.bashrc or ~/.zshrc for persistence.
Full support for Claude 4.6 Adaptive Thinking via the effort parameter:
- Smart Mapping:
lowβ Gemini 3.0LOW/ Gemini 2.55k tokensmediumβ Gemini 3.0MEDIUM/ Gemini 2.512k tokenshigh/maxβ Gemini 3.0HIGH/ Gemini 2.524k tokens
- Native: Uses Gemini's
thinking_levelfor 3.0 models.
Analyze images directly in your conversations:
claude "What's in this image? @screenshot.png"Supports JPEG, PNG, WebP, GIF, HEIC up to 100MB. The proxy handles base64 encoding and MIME type detection automatically.
Reduce costs by 75-90% on repeated prompts:
# Enable caching
export ENABLE_CONTEXT_CACHING=true
# First request creates cache
claude "Review this large codebase @src/**/*.rs"
# Subsequent requests hit cache (90% cost reduction)
claude "Now check for security issues"Cache automatically expires after 5 minutes.
Full support for Claude Code's tool ecosystem:
- File read/write operations
- Bash command execution
- Browser automation (via Claude Code's browser tool)
- Multi-turn conversations with tool results
- Automatic thought signature management for Gemini 3.x
Comprehensive Prometheus metrics available at /metrics:
gemini_api_calls_total: API call counts by model and statusrequest_duration_seconds: Latency histogramstranslation_cache_operations_total: Hit/miss/eviction rates for the internal translation cachecache_operations_total: Gemini context cache hit/miss/create rates
Optional environment variables:
| Variable | Default | Description |
|---|---|---|
GEM2CLAUDE_PORT |
8080 |
Proxy server port |
RUST_LOG |
info |
Log level (debug, info, warn, error) |
ENABLE_CONTEXT_CACHING |
false |
Enable context caching for cost savings |
Claude Code CLI
β
βΌ
ββββββββββββββββββββββ
β gem2claude β
β (Rust Proxy) β
ββββββββββββββββββββββ€
β β’ Request Translation β
β β’ SSE Streaming β
β β’ OAuth Management β
β β’ Extended Thinking β
β β’ Context Caching β
β β’ Vision Processing β
ββββββββββββββββββββββ
β
βΌ
Google Gemini API
The proxy is built for performance:
- Connection Pooling β 10 idle connections kept warm per host
- TCP Keep-Alive β 60-second intervals prevent connection drops
- TCP_NODELAY β Nagle's algorithm disabled for low latency
- 90s Idle Timeout β Connections reused between requests
- Minimal Logging β Hot path optimized for speed
- Immediate SSE Flushing β Real-time streaming with keepalive comments
- Smart Caching β LRU in-memory translation cache to skip redundant processing
- Deterministic Hashing β SHA256 cache keys normalized for tool ordering and capability toggles
Check that the proxy is running and ANTHROPIC_BASE_URL is set correctly:
curl http://localhost:8080/healthEnable detailed logging:
RUST_LOG=debug ./target/release/gem2claudeIf you hit Gemini API quota limits, the proxy will return HTTP 429 with details:
Error: Gemini API quota exceeded: Resource exhausted (quota)
Wait a moment and retry, or use a different model.
Apache 2.0 β See LICENSE
If you find this project useful, consider supporting its development:
- β Star this repository
- π Report issues and suggest features
- π΅ Buy me a coffee
- π° Sponsor on GitHub
kelexine β GitHub
- Google Gemini CLI β For OAuth implementation reference
- Anthropic Claude β For the amazing Claude Code CLI
- The Rust community for excellent tooling and libraries
Star History