ClaudeProxy
Multi-provider reverse proxy, payload sanitizer, and request router for Claude Code
Architecture overview
ClaudeProxy is an API routing proxy built for developers running Claude Code and terminal AI agent workflows.
By pointing Claude Code’s base URL endpoint to http://localhost:8082, requests route to upstream providers (Anthropic, Google Gemini via Antigravity, OpenAI GPT-4o, GitHub Copilot, DeepSeek, or local Ollama instances) without breaking agentic tool calling, parameter schemas, or thinking token headers.
Request flow and translation pipeline
The proxy operates across four stages:
| Stage | Component | Technical action |
|---|---|---|
| 1. Client ingress | HTTP server (0.0.0.0:8082) |
Accepts Anthropic Messages API requests (/v1/messages, /v1/messages/count_tokens, /v1/models) |
| 2. Reactor router | Rules engine | Categorizes models into reactors (haiku, sonnet, opus, research) and matches provider endpoints |
| 3. Schema adapter | Payload sanitizer | Converts Anthropic message schemas and tool_use/tool_result blocks into OpenAI function calls |
| 4. Stream transformer | SSE chunk normalizer | Converts downstream token streams into Anthropic SSE wire events (content_block_delta, text_delta, input_json_delta) |
Key technical implementations
1. Server-Sent Events (SSE) stream transformation
Different LLM providers emit distinct streaming token schemas. The stream transformer parses incoming chunks from providers like OpenAI and converts them into the exact sequence of Anthropic SSE events expected by Claude Code:
View TypeScript implementation: pipeOpenAiStreamToAnthropic
import { Response } from 'express';
export async function pipeOpenAiStreamToAnthropic(
openAiStream: AsyncIterable<any>,
res: Response,
modelName: string
): Promise<void> {
res.setHeader('Content-Type', 'text/event-stream');
res.setHeader('Cache-Control', 'no-cache');
res.setHeader('Connection', 'keep-alive');
const sendEvent = (event: string, data: object) => {
res.write(`event: ${event}\ndata: ${JSON.stringify(data)}\n\n`);
};
sendEvent('message_start', {
type: 'message_start',
message: {
id: `msg_${Date.now()}`,
type: 'message',
role: 'assistant',
model: modelName,
content: [],
usage: { input_tokens: 0, output_tokens: 0 }
}
});
sendEvent('content_block_start', {
type: 'content_block_start',
index: 0,
content_block: { type: 'text', text: '' }
});
for await (const chunk of openAiStream) {
const deltaText = chunk.choices?.[0]?.delta?.content;
if (deltaText) {
sendEvent('content_block_delta', {
type: 'content_block_delta',
index: 0,
delta: { type: 'text_delta', text: deltaText }
});
}
}
sendEvent('content_block_stop', { type: 'content_block_stop', index: 0 });
sendEvent('message_delta', {
type: 'message_delta',
delta: { stop_reason: 'end_turn', stop_sequence: null },
usage: { output_tokens: 0 }
});
sendEvent('message_stop', { type: 'message_stop' });
res.end();
}
2. Tool calling and schema sanitization
Anthropic tools use tool_use and tool_result content blocks inside the message history array, whereas OpenAI expects a top-level tool_calls array with function signatures. The schema adapter normalizes these payloads bidirectionally and repairs malformed JSON before handing execution back to the client:
View TypeScript implementation: adaptAnthropicToolsToOpenAi
export function adaptAnthropicToolsToOpenAi(anthropicTools: any[]): any[] {
return anthropicTools.map((tool) => ({
type: 'function',
function: {
name: tool.name,
description: tool.description ?? '',
parameters: {
type: 'object',
properties: tool.input_schema?.properties ?? {},
required: tool.input_schema?.required ?? []
}
}
}));
}
3. GitHub Copilot OAuth device-code authentication
To enable developers to use Copilot model subscriptions directly within Claude Code, the proxy implements the GitHub device-code OAuth flow:
- Initiates authentication via
https://github.com/login/device/codeto obtain a user verification code and URI. - Polls GitHub’s OAuth endpoint until authentication completes, securely caching the resulting access token in local configuration.
- Automatically handles token expiration and upstream rate-limiting headers.
4. Web management dashboard
The proxy includes a built-in web management interface providing:
- Real-time provider latency monitoring across upstream backends.
- Interactive token counter and request payload visualizer.
- Model routing toggles to redirect specific workloads (e.g., routing thinking-heavy tasks to Sonnet or Gemini 3 Pro and quick completions to Flash).