Aquib Haq

github.com/Clufy/claude-code-gateway · open source · MIT

Run Claude Code on any LLM with one Cloudflare Worker

claude-code-gateway speaks the Anthropic Messages API, so Claude Code talks to it as if it were Anthropic. Behind it, each model routes to open models on Cloudflare Workers AI, OpenAI, Gemini or Anthropic, and every session passes a security layer built for AI-assisted red and purple teaming.

  • Claude Code
  • Cloudflare Workers AI
  • OpenAI
  • Gemini
  • DeepSeek
  • MCP
  • TypeScript

Features

Multi-provider routing

Workers AI, OpenAI Chat Completions and Responses, Gemini and the Anthropic Messages API, with up to 3 fallback models per route.

Full Claude Code experience

Streaming, tool use, extended thinking, vision for flagged models, token counting and /v1/models with real context windows.

Secure by default

Required proxy key, provider host allowlist, body caps, rate limits and provider keys scrubbed from every response.

Session guard

Flags prompt injection, secrets and risky tool calls in each turn, with your own rules in GUARD_RULES.

Red-team harness

70 canary-based attack cases in 7 suites, mapped to the OWASP Top 10 for LLM Applications.

MCP server and purple loop

engagement, logs, redteam and purple tools at /mcp, plus Sigma rules drafted from findings and promoted to guard rules.

How it works

Claude Code ──Anthropic Messages API──▶ claude-code-gateway ──▶ Workers AI · OpenAI · Gemini · Anthropic
                                        (your Worker)
                                        auth · routing · fallbacks · session guard · scope check · /mcp

Quick start

Deploy with the button above, or from your machine:

npx wrangler login
npm install && npm run check
npm run deploy
npx wrangler secret put PROXY_KEY

Then point Claude Code at the Worker in ~/.claude/settings.json:

{
  "env": {
    "ANTHROPIC_BASE_URL": "https://<worker-subdomain>.workers.dev",
    "ANTHROPIC_CUSTOM_HEADERS": "x-api-key: your-proxy-key-value",
    "ANTHROPIC_MODEL": "@cf/zai-org/glm-5.3",
    "ANTHROPIC_SMALL_FAST_MODEL": "@cf/moonshotai/kimi-k2.6"
  }
}

Full configuration, engagements, guard rules and the red-team harness are documented in the repository docs.

FAQ

Can I use Claude Code with other models?

Yes. Point ANTHROPIC_BASE_URL at your claude-code-gateway Worker and each model name routes to the backend you choose: Workers AI, OpenAI, Gemini, DeepSeek, Groq, OpenRouter or Anthropic.

Which open-source models does it ship with?

It ships configured for GLM-5.3, Kimi K2.6 and DeepSeek V4 Pro on Cloudflare Workers AI, with no GPU of your own.

Is the gateway secure by default?

A proxy key is required, provider hosts must be on an allowlist, bodies are size-capped, requests are rate limited and provider keys are scrubbed from every upstream response.

What does not work through the gateway?

WebSearch, prompt caching, the Files API, the Batches API and managed-agent features are not implemented.

How do I deploy it?

Use the one-click Deploy to Cloudflare button, or run npm install and npm run deploy with Wrangler, then set the PROXY_KEY secret.