# samarth777/claude-code-copilot architecture

> Architecture diagram of the GitHub repository samarth777/claude-code-copilot, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-11-12). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/samarth777/claude-code-copilot
- Repository: https://github.com/samarth777/claude-code-copilot

## Overview

This repository runs a local compatibility proxy so Claude Code can use GitHub Copilot without an Anthropic API key. The main workflow is GitHub device-code authentication, then Claude Code sends Anthropic Messages API requests to the proxy, which translates them for Copilot and converts responses back. The proxy also supports streaming, token-count requests, and emulated web search; a launcher and Docker deployment are documented. Some proxy internals are excerpted only partially, so edges between internal stages follow the README’s workflow description where noted.

Main entry points: [`scripts/proxy.mjs`](https://github.com/samarth777/claude-code-copilot/blob/main/scripts/proxy.mjs) (Request Routing), [`scripts/auth.mjs`](https://github.com/samarth777/claude-code-copilot/blob/main/scripts/auth.mjs) (Device Auth), [`scripts/launch.sh`](https://github.com/samarth777/claude-code-copilot/blob/main/scripts/launch.sh) (One-command Launcher), [`docker-compose.yml`](https://github.com/samarth777/claude-code-copilot/blob/main/docker-compose.yml) (Docker Runtime)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_auth["Authentication"]
  node_auth_flow["Device Auth<br/>[auth.mjs]"]
  node_token_file[("Saved Token")]
end

subgraph group_proxy["API Proxy"]
  node_proxy_server["HTTP Server<br/>[proxy.mjs]"]
  node_request_route["Request Routing<br/>[proxy.mjs]"]
  node_request_translate["Request Translation<br/>[proxy.mjs]"]
  node_response_translate["Response Translation<br/>[proxy.mjs]"]
  node_streaming["Streaming SSE<br/>[proxy.mjs]"]
  node_token_count["Token Counting<br/>[proxy.mjs]"]
end

subgraph group_search["Web Search"]
  node_search_loop["Search Loop<br/>[proxy.mjs]"]
  node_brave{{"Brave Search"}}
  node_duckduckgo{{"DuckDuckGo Lite"}}
end

subgraph group_runtime["Runtime"]
  node_launcher["One-command Launcher<br/>[launch.sh]"]
  node_docker["Docker Runtime<br/>[docker-compose.yml]"]
end

node_user(("User"))
node_claude(("Claude Code"))
node_github_oauth{{"GitHub OAuth"}}
node_copilot{{"Copilot API"}}

node_user -->|"starts authentication"| node_auth_flow
node_auth_flow -->|"requests device code"| node_github_oauth
node_github_oauth -->|"returns token"| node_auth_flow
node_auth_flow -->|"saves token"| node_token_file
node_auth_flow -->|"checks access"| node_copilot
node_user -->|"starts"| node_launcher
node_launcher -.->|"starts proxy"| node_proxy_server
node_user -->|"starts container"| node_docker
node_claude -->|"sends messages"| node_proxy_server
node_proxy_server -->|"dispatches requests"| node_request_route
node_request_route -->|"loads token"| node_token_file
node_request_route -->|"handles token counts"| node_token_count
node_request_route -->|"translates messages"| node_request_translate
node_request_translate -->|"forwards completion"| node_copilot
node_copilot -->|"returns response"| node_response_translate
node_response_translate -->|"returns Anthropic format"| node_claude
node_request_route -->|"emits SSE"| node_streaming
node_request_route -->|"handles web search"| node_search_loop
node_search_loop -.->|"searches optionally"| node_brave
node_search_loop -->|"searches fallback"| node_duckduckgo

click node_auth_flow "https://github.com/samarth777/claude-code-copilot/blob/main/scripts/auth.mjs"
click node_proxy_server "https://github.com/samarth777/claude-code-copilot/blob/main/scripts/proxy.mjs"
click node_request_route "https://github.com/samarth777/claude-code-copilot/blob/main/scripts/proxy.mjs"
click node_request_translate "https://github.com/samarth777/claude-code-copilot/blob/main/scripts/proxy.mjs"
click node_response_translate "https://github.com/samarth777/claude-code-copilot/blob/main/scripts/proxy.mjs"
click node_streaming "https://github.com/samarth777/claude-code-copilot/blob/main/scripts/proxy.mjs"
click node_token_count "https://github.com/samarth777/claude-code-copilot/blob/main/scripts/proxy.mjs"
click node_search_loop "https://github.com/samarth777/claude-code-copilot/blob/main/scripts/proxy.mjs"
click node_launcher "https://github.com/samarth777/claude-code-copilot/blob/main/scripts/launch.sh"
click node_docker "https://github.com/samarth777/claude-code-copilot/blob/main/docker-compose.yml"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_auth_flow,node_token_file,node_user toneBlue
class node_proxy_server,node_request_route,node_request_translate,node_response_translate,node_streaming,node_token_count toneAmber
class node_search_loop,node_brave,node_duckduckgo,node_copilot toneMint
class node_launcher,node_docker toneRose
class node_claude,node_github_oauth toneIndigo
```

## Components

### Authentication

- [Device Auth](https://github.com/samarth777/claude-code-copilot/blob/main/scripts/auth.mjs): `scripts/auth.mjs`
- **Saved Token**

### API Proxy

- [HTTP Server](https://github.com/samarth777/claude-code-copilot/blob/main/scripts/proxy.mjs): `scripts/proxy.mjs`
- [Request Routing](https://github.com/samarth777/claude-code-copilot/blob/main/scripts/proxy.mjs): `scripts/proxy.mjs`
- [Request Translation](https://github.com/samarth777/claude-code-copilot/blob/main/scripts/proxy.mjs): `scripts/proxy.mjs`
- [Response Translation](https://github.com/samarth777/claude-code-copilot/blob/main/scripts/proxy.mjs): `scripts/proxy.mjs`
- [Streaming SSE](https://github.com/samarth777/claude-code-copilot/blob/main/scripts/proxy.mjs): `scripts/proxy.mjs`
- [Token Counting](https://github.com/samarth777/claude-code-copilot/blob/main/scripts/proxy.mjs): `scripts/proxy.mjs`

### Web Search

- [Search Loop](https://github.com/samarth777/claude-code-copilot/blob/main/scripts/proxy.mjs): `scripts/proxy.mjs`
- **Brave Search**
- **DuckDuckGo Lite**

### Runtime

- [One-command Launcher](https://github.com/samarth777/claude-code-copilot/blob/main/scripts/launch.sh): `scripts/launch.sh`
- [Docker Runtime](https://github.com/samarth777/claude-code-copilot/blob/main/docker-compose.yml): `docker-compose.yml`

### Other components

- **User**
- **Claude Code**
- **GitHub OAuth**
- **Copilot API**

## Connections

- User → Device Auth: starts authentication (evidence: `README.md`)
- Device Auth → GitHub OAuth: requests device code (evidence: `scripts/auth.mjs`)
- GitHub OAuth → Device Auth: returns token (evidence: `scripts/auth.mjs`)
- Device Auth → Saved Token: saves token (evidence: `scripts/auth.mjs`)
- Device Auth → Copilot API: checks access (evidence: `scripts/auth.mjs`)
- User → One-command Launcher: starts (evidence: `README.md`)
- One-command Launcher → HTTP Server: starts proxy (evidence: `README.md`)
- User → Docker Runtime: starts container (evidence: `README.md`)
- Claude Code → HTTP Server: sends messages (evidence: `README.md`)
- HTTP Server → Request Routing: dispatches requests (evidence: `scripts/proxy.mjs`)
- Request Routing → Saved Token: loads token (evidence: `scripts/proxy.mjs`)
- Request Routing → Token Counting: handles token counts (evidence: `scripts/proxy.mjs`)
- Request Routing → Request Translation: translates messages (evidence: `README.md`)
- Request Translation → Copilot API: forwards completion (evidence: `README.md`)
- Copilot API → Response Translation: returns response (evidence: `README.md`)
- Response Translation → Claude Code: returns Anthropic format (evidence: `README.md`)
- Request Routing → Streaming SSE: emits SSE (evidence: `scripts/proxy.mjs`)
- Request Routing → Search Loop: handles web search (evidence: `scripts/proxy.mjs`)
- Search Loop → Brave Search: searches optionally (evidence: `scripts/proxy.mjs`)
- Search Loop → DuckDuckGo Lite: searches fallback (evidence: `scripts/proxy.mjs`)
