Running Claude Code Through GitHub Copilot
Claude Code is Anthropic's CLI tool for working with Claude in the terminal. It's good for coding tasks, but it requires either a Claude subscription or an Anthropic API key.
GitHub copilot also supports Anthropic models. If you already have a GitHub Copilot subscription, there's a way to use those models with Claude Code. GitHub Copilot's API natively supports the Anthropic Messages format, so a thin local proxy can redirect Claude Code's requests to Copilot instead.
I wrote cc-gh-proxy for this. It's a single Python file with no dependencies beyond the standard library.
How It Works
The proxy sits between Claude Code and api.githubcopilot.com:
Claude Code --> localhost:4000 --> api.githubcopilot.com
All it does is:
- Swap the auth header to a GitHub CLI OAuth token
- Map model names (
claude-opus-4-6becomesclaude-opus-4.6) - Strip
cache_controlfields that Copilot doesn't support
No format conversion is needed for the Anthropic Messages path. Token counts and streaming work natively.
Copilot also exposes an OpenAI-compatible endpoint, which is used for models
other than Anthropic's, so the proxy translates those responses between OpenAI
and Anthropic formats. This lets you use models like gpt-4 with Claude Code,
albeit without streaming.
Setup
You need the GitHub CLI (gh) and a Copilot subscription:
gh auth login
gh auth refresh --hostname github.com -s copilot
Then point Claude Code at the proxy by adding this to
.claude/settings.json in your project:
{
"env": {
"ANTHROPIC_BASE_URL": "http://localhost:4000"
}
}
Start the proxy and run Claude Code as usual:
./cc-gh-proxy.py &
claude
Token Management
The proxy fetches an OAuth token from gh auth token at startup and refreshes
it automatically every hour. If a request gets a 401, the token is refreshed
immediately and the request retried. This is all thread-safe, so concurrent
Claude Code sessions work fine.
Logging
The proxy writes structured request logs to logs/requests.jsonl -- one
JSON object per request with model, messages, token usage, and timing.
Caveats
Copilot's API doesn't support Anthropic's prompt caching, so the cache_control
fields are stripped. This means slightly higher latency since nothing is cached
between requests.
This works today, but GitHub could change or restrict their Copilot API at any time. The proxy is experimental and may not support every edge case.
The log files may contain sensitive information, so be careful with them, and they also grow indefinitely. The proxy does not currently implement any log rotation or redaction.
The code is on GitHub: kortsi/cc-gh-proxy.
Comments
💬 Leave a comment