Skip to content
This repository was archived by the owner on May 18, 2026. It is now read-only.

kelexine/gem2claude

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

69 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

gem2claude

Use Claude Code with Google OAuth Login β€” No API key billing required

Author License Rust

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.

✨ Features

  • πŸ†“ 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

Why gem2claude?

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:

  1. 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).
  2. 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.

πŸ“‹ Supported Models

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

πŸš€ Quick Start

1. Build from Source

git clone https://github.com/kelexine/gem2claude
cd gem2claude
cargo build --release

2. Login to Get OAuth Credentials

You 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.

3. Running the Proxy:

On subsiquent runs just run:

./target/release/gem2claude

Proxy starts on http://127.0.0.1:8080 OAuth lifecycle is Managed by tge proxy, login once login forever.

4. Configure Claude Code

export ANTHROPIC_BASE_URL="http://localhost:8080"
export ANTHROPIC_AUTH_TOKEN="dummy"

Add to ~/.bashrc or ~/.zshrc for persistence.

🎯 Key Features

Adaptive Thinking (Claude 4.6)

Full support for Claude 4.6 Adaptive Thinking via the effort parameter:

  • Smart Mapping:
    • low β†’ Gemini 3.0 LOW / Gemini 2.5 5k tokens
    • medium β†’ Gemini 3.0 MEDIUM / Gemini 2.5 12k tokens
    • high/max β†’ Gemini 3.0 HIGH / Gemini 2.5 24k tokens
  • Native: Uses Gemini's thinking_level for 3.0 models.

Vision Support

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.

Context Caching (NEW!)

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.

Agentic Tool Calls

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

Observability

Comprehensive Prometheus metrics available at /metrics:

  • gemini_api_calls_total: API call counts by model and status
  • request_duration_seconds: Latency histograms
  • translation_cache_operations_total: Hit/miss/eviction rates for the internal translation cache
  • cache_operations_total: Gemini context cache hit/miss/create rates

βš™οΈ Configuration

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

πŸ—οΈ Architecture

Claude Code CLI
      β”‚
      β–Ό
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚    gem2claude      β”‚
β”‚   (Rust Proxy)     β”‚
β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€
β”‚ β€’ Request Translation β”‚
β”‚ β€’ SSE Streaming       β”‚
β”‚ β€’ OAuth Management    β”‚
β”‚ β€’ Extended Thinking   β”‚
β”‚ β€’ Context Caching     β”‚
β”‚ β€’ Vision Processing   β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
      β”‚
      β–Ό
Google Gemini API

⚑ Performance Optimizations

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

πŸ”§ Troubleshooting

Connection Issues

Check that the proxy is running and ANTHROPIC_BASE_URL is set correctly:

curl http://localhost:8080/health

Debug Mode

Enable detailed logging:

RUST_LOG=debug ./target/release/gem2claude

Rate Limiting

If 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.

πŸ“„ License

Apache 2.0 β€” See LICENSE

πŸ’– Support

If you find this project useful, consider supporting its development:

πŸ‘€ Author

kelexine β€” GitHub

πŸ™ Acknowledgments

  • 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

Star History Chart

About

A high-performance Rust proxy bridging the Anthropic Messages API to the Google Gemini API with support for streaming, thinking, and context caching.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Sponsor this project

  •  

Packages

 
 
 

Contributors

Languages