Run Claude Code CLI on Your GitHub Copilot Subscription
A quick tip on using Claude Code CLI with your existing GitHub Copilot subscription to access Claude models without a separate Anthropic subscription.
The Situation
If you’re on a GitHub Copilot subscription — individual, Pro, or through your organization — you already have access to Claude models. GitHub Copilot’s Agent HQ brings Claude directly into your IDE (VS Code, JetBrains, etc.) as an in-editor AI agent.
That’s great for quick questions and inline edits. But it’s not Claude Code CLI.
Claude Code CLI is a different beast. It’s a terminal-first AI coding agent with:
- Your own MCP servers, skills, and plugins configured in
~/.claude/ - Session history and context continuity across conversations
- Access to your project’s full file tree and shell environment
- Custom hooks, memory, and project-specific instructions
The question is: can you point Claude Code CLI at your existing Copilot subscription instead of paying for a separate Anthropic API subscription?
Yes. Here’s how.
The Proxy: copilot-api
The key tool is copilot-api — an open-source reverse-engineered proxy that exposes GitHub Copilot as both an OpenAI-compatible and an Anthropic-compatible API endpoint.
Once running, it listens on localhost:4141 and forwards requests to GitHub Copilot on your behalf, translating the API format along the way. Claude Code (which talks to Anthropic’s API) can then be pointed at this local proxy instead.
⚠️ Note:
copilot-apiis not officially supported by GitHub and is a community project. Use it responsibly and in accordance with GitHub’s acceptable use policies. Avoid excessive automated use.
Step 1: Install copilot-api
You’ll need Bun (≥1.2.x) installed first:
1
curl -fsSL https://bun.sh/install | bash
Then install copilot-api globally:
1
npm install -g copilot-api
Or run it directly without installing:
1
npx copilot-api@latest start
Step 2: Authenticate with GitHub
On first run, copilot-api will prompt you to authenticate with your GitHub account:
1
copilot-api start
Follow the device code flow — it opens a browser prompt to authorize the app against your GitHub account. Your Copilot subscription is then used to generate tokens for the proxy.
Step 3: Set Environment Variables
With the proxy running on port 4141, tell Claude Code to use it by setting these environment variables before launching:
1
2
3
4
5
6
export ANTHROPIC_BASE_URL="http://localhost:4141"
export ANTHROPIC_MODEL="claude-sonnet-4.6"
export ANTHROPIC_API_KEY="placeholder"
export ANTHROPIC_DEFAULT_OPUS_MODEL="claude-opus-4.6"
export ANTHROPIC_DEFAULT_SONNET_MODEL="claude-sonnet-4.6"
export ANTHROPIC_DEFAULT_HAIKU_MODEL="claude-haiku-4.5"
Then launch Claude Code normally:
1
claude
Claude Code will route all API calls through the local proxy, which forwards them to GitHub Copilot — using your existing subscription.
Step 4: Make It Convenient with an Alias
Typing all of that manually each time gets old fast. The alias below starts the proxy in the background if it isn’t already running, then launches Claude Code with all the necessary environment variables set:
Add this to your ~/.zshrc (or ~/.bashrc):
1
2
3
4
5
6
7
8
9
alias claude-ghc='\
if ! lsof -ti:4141 > /dev/null 2>&1; then nohup copilot-api start > /dev/null 2>&1 & sleep 2; fi; \
ANTHROPIC_BASE_URL="http://localhost:4141" \
ANTHROPIC_MODEL="claude-sonnet-4.6" \
ANTHROPIC_API_KEY="placeholder" \
ANTHROPIC_DEFAULT_OPUS_MODEL="claude-opus-4.6" \
ANTHROPIC_DEFAULT_SONNET_MODEL="claude-sonnet-4.6" \
ANTHROPIC_DEFAULT_HAIKU_MODEL="claude-haiku-4.5" \
claude'
Reload your shell config:
1
source ~/.zshrc
From now on, just type:
1
claude-ghc
The alias:
- Checks if port
4141is already in use (proxy already running) - If not, starts
copilot-apiin the background and waits 2 seconds for it to initialize - Launches Claude Code with all the required environment variables inline
Your ~/.claude/ setup — MCP servers, skills, hooks, memory, project instructions — all works exactly as normal. The only difference is where the API calls go.
Why Not Just Use Agent HQ in the IDE?
Agent HQ (Copilot’s Claude integration inside VS Code or JetBrains) is useful for in-editor tasks. But it’s isolated to the IDE — it doesn’t have access to your MCP servers, custom skills, ~/.claude/ configuration, or session history.
Claude Code CLI is designed for deeper, longer-horizon work: multi-file refactors, shell-integrated workflows, background agents, and project-specific context that builds up over time. If you’ve invested in setting up your ~/.claude/ environment, using Claude Code CLI means that investment carries over to every project you work on.
With this setup, you get both: the in-IDE convenience of Agent HQ and the full power of Claude Code CLI — all on the same Copilot subscription.
Tips
Check which process holds port 4141:
1
lsof -ti:4141
Stop the background proxy manually:
1
kill $(lsof -ti:4141)
Verify the proxy is responding:
1
curl http://localhost:4141/v1/models
Rate limiting: If you hit usage limits, copilot-api supports a --rate-limit flag to throttle requests:
1
copilot-api start --rate-limit 10
