This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
copilot-api is a reverse proxy that exposes GitHub Copilot as OpenAI and Anthropic-compatible API endpoints. Built with Bun, TypeScript, Hono, and citty (CLI framework).
- Build:
bun run build(tsdown bundler, outputs todist/) - Dev:
bun run dev(watch mode viabun run --watch) - Start:
bun run start(production mode) - Lint:
bun run lint(ESLint with@echristian/eslint-config) - Typecheck:
bun run typecheck(tsc, no emit) - Test all:
bun test - Test single file:
bun test tests/<filename>.test.ts - Unused code detection:
bun run knip
Entry point uses citty to define subcommands: start, auth, check-usage, debug, console.
Hono app with routes mounted at both / and /v1/ prefixes for compatibility:
POST /v1/chat/completions— OpenAI-compatible chat completionsPOST /v1/messages— Anthropic-compatible messages APIPOST /v1/messages/count_tokens— Token countingGET /v1/models— Model listingPOST /v1/embeddings— EmbeddingsGET /usage,GET /token— Monitoring endpoints
src/routes/— Route handlers, each in its own directory withroute.ts+handler.tssrc/services/copilot/— GitHub Copilot API calls (completions, embeddings, models)src/services/github/— GitHub API calls (auth, tokens, usage)src/lib/— Shared utilities (state, tokens, rate limiting, error handling, proxy)src/console/— Multi-account management mode with load balancing and web UIweb/— React + Vite frontend for the console modetests/— Bun test runner, files named*.test.ts
Mutable singleton state object holds runtime config: GitHub/Copilot tokens, account type, cached models, rate limit settings.
Converts between Anthropic message format and Copilot's OpenAI-style API. Handles both streaming (stream-translation.ts) and non-streaming (non-stream-translation.ts) responses.
- ESM only, strict TypeScript — no
any, no unused variables/imports - Path alias:
~/*maps tosrc/*(e.g.,import { state } from "~/lib/state") - camelCase for variables/functions, PascalCase for types/classes
- Zod v4 for runtime validation
- Pre-commit hook runs lint-staged via simple-git-hooks