DEVELOPER INFRASTRUCTURE // LOCAL COMPATIBILITY PROXY

Claude Code. Powered by the Gemini CLI session you already have.

Route Claude Code requests through Gemini CLI authentication using a lightweight local compatibility proxy. No separate Gemini API key required.

Terminal Quickstart
$ git clone https://github.com/whysooraj/CodeWeaver.git && cd CodeWeaver && node proxy.js
Runs locally on loopback. Zero external npm dependencies. Requires Node.js 18+.
HERO ARCHITECTURE // LOOPBACK REQUEST DISPATCH FLOW 100% LOCALHOST (127.0.0.1)
01. INBOUND CLIENT
Claude Code CLI

Sends Anthropic-formatted /v1/messages requests with nested role blocks and tool schemas.

  • Target: localhost:8080
  • Schema: Anthropic Messages v1
  • Protocol: HTTP/1.1 SSE
→
02. COMPATIBILITY LAYER
CodeWeaver (localhost:8080)

Pure Node.js stdlib proxy translating multi-turn structures, uppercasing schemas, and wrapping responses into SSE streams.

  • Auth Check: ~/.pi/agent/auth.json
  • Schema: OpenAPI Type Normalizer
  • Resilience: Auto 429 → Flash Failover
→
03. UPSTREAM PROVIDER
Gemini CLI (OAuth)

Google Cloud Code Assist API executing reasoning models via the user's active Google OAuth session.

  • Primary: gemini-2.5-pro
  • Fallback: gemini-2.5-flash
  • Auth: Google PKCE Bearer
Inbound Request Handled
POST /v1/messages Host: localhost:8080 {"model":"claude-3-5-sonnet","messages":[...]}
Translated Upstream Call
POST /v1internal:streamGenerateContent Authorization: Bearer ya29.a0... {"contents":[{"role":"user","parts":[...]}]}
THE MOTIVATION

Why CodeWeaver exists

Claude Code provides one of the most effective developer agent experiences, but standard usage requires separate Anthropic platform billing. CodeWeaver bridges developer workflows without compromising agent autonomy.

THE BOTTLENECK

Separate API Billing

Developers frequently already have access to Google Workspace or Gemini CLI subscriptions, yet running Claude Code traditionally demands a separate paid Anthropic API account.

PROXIES TODAY

Heavyweight Dependencies

Standard multi-provider proxies require Python runtimes, 40+ npm dependencies, Docker daemon containers, or separate hosted relay infrastructure that complicates local setups.

THE SOLUTION

CodeWeaver Local Architecture

A single standalone script built strictly on Node.js core libraries (http, crypto, fs). Authenticate once with Google, set one environment variable, and start coding.

BELOW THE FOLD TECHNICAL DEPTH

OAuth session handoff & SSE request translation

CodeWeaver operates entirely on local loopback without third-party servers. Here is how Google OAuth token handoff and runtime translation function under the hood.

01. Google OAuth Session Handoff

CodeWeaver avoids static API keys by integrating with the same OAuth PKCE credentials used by Google's Gemini CLI tools.

  • Local PKCE Receiver: Running node proxy.js --login creates an ephemeral HTTP callback listener on localhost:8085 and generates a cryptographic SHA-256 code challenge.
  • Credential Storage: Successfully negotiated OAuth tokens are cached locally in ~/.pi/agent/auth.json or config.json with user-level read/write permissions.
  • Automatic Refresh: When an access token nears expiry (within 120 seconds of expires), CodeWeaver transparently contacts oauth2.googleapis.com/token with the refresh token and rewrites the cache file in background.
  • Project Provisioning: Queries Google's Cloud Code Assist endpoint (loadCodeAssist) to discover the target companion project ID automatically.

02. Protocol & Schema Translation

Claude Code and Gemini Cloud Code speak fundamentally different wire protocols. CodeWeaver transforms requests and streams without buffering latency.

  • Role Normalization: Maps Anthropic multi-turn messages (user, assistant) to Gemini's user and model structure, folding sequential turns cleanly.
  • Strict OpenAPI Sanitization: Google's endpoint rejects JSON schema specifications containing $schema, exclusiveMinimum, or lowercase type primitives. CodeWeaver uppercases all parameter types to OBJECT, STRING, INTEGER, etc.
  • SSE Stream Framing: Ingests raw Gemini chunked JSON from streamGenerateContent and formats Anthropic Server-Sent Events (message_start, content_block_delta, message_stop) in real time.
  • Self-Healing 429 Failover: If Gemini Pro returns a 429 RESOURCE_EXHAUSTED quota limit, CodeWeaver instantly re-routes the chunk to gemini-2.5-flash so the agent never aborts mid-task.
Live Wire Translation Inspection
Claude Code Inbound (Anthropic Format) HTTP POST
{
  "model": "claude-3-5-sonnet",
  "messages": [
    {
      "role": "user",
      "content": "List files in directory"
    }
  ],
  "tools": [{ "name": "ls", "input_schema": { "type": "object" } }],
  "stream": true
}
CodeWeaver Outbound (Gemini Format) Cloud Code Assist
{
  "project": "cloudaicompanion-prod-...",
  "model": "gemini-2.5-pro",
  "request": {
    "contents": [
      {
        "role": "user",
        "parts": [{ "text": "List files in directory" }]
      }
    ],
    "tools": [{ "functionDeclarations": [...] }]
  }
}
MODEL RESOLUTION

Claude Code to Gemini Model Routing

Claude Code enforces a client-side whitelist in its interactive model selector. CodeWeaver resolves these requests to the appropriate Gemini enterprise engine with automatic quota failover.

Claude Code Model Flag Target Gemini Engine Automatic 429 Fallback Recommended Use Case
claude-3-7-sonnet / claude-3-5-sonnet gemini-2.5-pro gemini-2.5-flash Deep multi-file reasoning, refactors, and architectural plans
claude-3-5-haiku gemini-2.5-flash Primary Tier High-throughput tasks, fast completions, unit test runs
claude-3-opus gemini-3.1-pro-preview gemini-2.5-flash High-depth algorithmic synthesis and extended context evaluation
claude-fable gemini-3.1-flash-lite gemini-2.5-flash Atomic linting checks and sub-second terminal feedback
GETTING STARTED

Quickstart Configuration

Set up CodeWeaver in less than 2 minutes. Requires Node.js 18 or higher. No npm install required.

STEP 01

Clone Repository

Clone the repository. Zero external npm dependencies are required.

git clone https://github.com/whysooraj/CodeWeaver.git && cd CodeWeaver
STEP 02

Authenticate Google Session

Starts local OAuth receiver on port 8085 to save credentials to local config.

node proxy.js --login
STEP 03

Start Proxy Gateway

Starts the reverse proxy listening on port 8080 (or port 8099 by default).

PORT=8080 node proxy.js
STEP 04

Launch Claude Code

Point Claude Code's base URL environment variable to your local proxy.

export ANTHROPIC_BASE_URL="http://localhost:8080" && claude
Option B: Persistent Configuration via ~/.claude/settings.json

Avoid exporting environment variables each session by setting CodeWeaver in your Claude Code settings file:

{
  "env": {
    "ANTHROPIC_BASE_URL": "http://localhost:8080",
    "ANTHROPIC_AUTH_TOKEN": "sk-local-proxy"
  }
}
ENGINEERING SPECIFICATIONS

Architectural Comparison

How CodeWeaver compares to standard multi-provider proxy solutions.

Architecture Property CodeWeaver Official Anthropic LiteLLM / Multi-Proxies
Runtime Dependencies ✓ 0 npm packages (Node stdlib only) × Proprietary client × 40+ Python / Node packages
Authentication Model ✓ Google OAuth (Gemini CLI session) Anthropic API Key ($$$) Per-provider API Keys
Vertex Schema Translation ✓ Automated uppercase sanitization N/A Manual mapping
Quota Failover ✓ Pro → Flash auto fallback on 429 × Process fails Custom retry policy needed
Host Footprint ✓ Lightweight script (~28 KB) CLI installation Docker / Virtualenv required
PROJECT ARCHIVAL & HISTORICAL CONTEXT NOTE

Google restricted certain Cloud Code Assist Gemini CLI OAuth endpoints to enterprise/workspace subscriptions. CodeWeaver remains a completely open-source educational reference for high-performance Node.js proxy architectures, showing how to achieve SSE streaming translation and OpenAPI schema sanitization with zero runtime npm dependencies.

✓ COPIED TO CLIPBOARD