running-claude-code-via-litellm-copilot

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

Running Claude Code via LiteLLM and GitHub Copilot

通过LiteLLM和GitHub Copilot运行Claude Code

Overview

概述

Use this skill for the specific workaround where Claude Code keeps its Anthropic-shaped client behavior, but the actual backend traffic is sent to a local LiteLLM proxy and then forwarded to GitHub Copilot.
Treat this as an advanced workaround, not an officially guaranteed GitHub workflow. Help the user succeed technically, but do not promise GitHub support, policy approval, or long-term compatibility.
This skill is guidance-first but execution-aware:
  • If the user wants explanation only, provide the smallest correct set of files, commands, and checks.
  • If the user wants real setup work on the current machine, inspect first and adapt commands to the active shell and OS.
  • Pause before persistent edits such as
    ~/.claude/settings.json
    or shell profile files.
Read
references/doc-verified-notes.md
before answering if you need to justify which parts come from the article and which parts were tightened against current LiteLLM docs.
本技能适用于一种特定的变通方案:Claude Code保留其Anthropic风格的客户端行为,但实际后端流量会发送到本地LiteLLM代理,再转发至GitHub Copilot。
请将此视为高级变通方案,而非GitHub官方保障的工作流。在技术层面帮助用户成功实现,但不承诺GitHub会提供支持、政策许可或长期兼容性。
本技能以指导为核心,同时兼顾实操性:
  • 如果用户仅需要解释,提供最精简的正确文件、命令和检查项即可。
  • 如果用户需要在当前机器上完成实际设置,先检查环境,再根据当前Shell和操作系统调整命令。
  • 在对
    ~/.claude/settings.json
    或Shell配置文件进行持久化修改前,请先暂停确认。
如果需要区分哪些内容来自官方文档、哪些是基于最新LiteLLM文档优化的部分,请先阅读
references/doc-verified-notes.md
再作答。

When To Use

适用场景

Use this skill when the user wants any of the following:
  • Claude Code to run against GitHub Copilot through LiteLLM
  • lower direct Anthropic API spending while keeping the Claude Code workflow
  • a local
    config.yaml
    for LiteLLM's GitHub Copilot provider
  • ANTHROPIC_BASE_URL
    ,
    ANTHROPIC_MODEL
    , or
    CLAUDE_CODE_DISABLE_NONESSENTIAL_TRAFFIC
    setup
  • help understanding GitHub device authorization during LiteLLM startup
  • help with model mismatch, 404-like errors, no requests reaching LiteLLM, or GitHub 401/403 failures
Do not use this skill for:
  • deciding whether the workaround is allowed by GitHub terms
  • general LiteLLM architecture unrelated to Claude Code plus Copilot
  • direct Anthropic API setup with no Copilot or LiteLLM component
当用户有以下需求时,使用本技能:
  • 让Claude Code通过LiteLLM对接GitHub Copilot
  • 在保留Claude Code工作流的同时,降低直接调用Anthropic API的成本
  • 为LiteLLM的GitHub Copilot提供商配置本地
    config.yaml
  • 设置
    ANTHROPIC_BASE_URL
    ANTHROPIC_MODEL
    CLAUDE_CODE_DISABLE_NONESSENTIAL_TRAFFIC
    环境变量
  • 理解LiteLLM启动时的GitHub设备授权流程
  • 排查模型不匹配、类404错误、请求未到达LiteLLM或GitHub 401/403认证失败等问题
以下场景请勿使用本技能:
  • 判断该变通方案是否符合GitHub服务条款
  • 与Claude Code+Copilot无关的通用LiteLLM架构问题
  • 不涉及Copilot或LiteLLM的直接Anthropic API设置

Core Rules

核心规则

  1. Lead with a short compliance caveat. Explain that this is a workaround based on a local proxy path, not a GitHub-promoted workflow, and the user must evaluate the latest Copilot terms and limits for themselves.
  2. Prefer the minimum viable path first. Start with temporary environment variables and a local
    config.yaml
    unless the user explicitly wants a persistent setup.
  3. Keep
    ANTHROPIC_MODEL
    and LiteLLM
    model_name
    identical. Exact string match matters more than clever explanation.
  4. Treat
    ANTHROPIC_AUTH_TOKEN
    as a local placeholder. Claude Code expects a non-empty value locally, but it is not the GitHub Copilot credential and should not be presented as a reusable secret.
  5. Never overwrite
    ~/.claude/settings.json
    wholesale. Merge only the needed
    env
    keys and preserve unrelated settings.
  1. 首先给出简短的合规提示。 说明这是基于本地代理路径的变通方案,并非GitHub推广的工作流,用户需自行评估最新的Copilot条款和限制。
  2. 优先采用最简可行方案。 除非用户明确要求持久化设置,否则默认使用临时环境变量和本地
    config.yaml
  3. 保持
    ANTHROPIC_MODEL
    与LiteLLM的
    model_name
    完全一致。 字符串精确匹配比复杂解释更重要。
  4. ANTHROPIC_AUTH_TOKEN
    视为本地占位符。 Claude Code要求本地提供非空值,但它并非GitHub Copilot的凭证,请勿将其作为可复用密钥。
  5. 切勿完全覆盖
    ~/.claude/settings.json
    。 仅合并所需的
    env
    键,保留无关设置。

Workflow

工作流程

1. Preflight

1. 预检

Check these first when the user wants real setup work:
  • claude --help
    succeeds
  • uv --version
    or
    pip --version
    succeeds
  • the user has GitHub Copilot access
  • the intended LiteLLM port is available, usually
    4000
If the user only wants instructions, state the prerequisites instead of running them.
当用户需要实际设置时,首先检查以下项:
  • claude --help
    可正常执行
  • uv --version
    pip --version
    可正常执行
  • 用户拥有GitHub Copilot访问权限
  • LiteLLM的目标端口可用,通常为
    4000
如果用户仅需要操作说明,只需列出前提条件,无需实际执行检查。

2. Choose Temporary vs Persistent Setup

2. 选择临时或持久化设置

Use this rule:
  • Temporary setup: preferred default for first-time setup, debugging, and low-risk trials
  • Persistent setup: only when the user explicitly wants the proxy path to apply every time Claude Code starts
For persistent setup, confirm the target file and then merge keys into
~/.claude/settings.json
. Do not replace the file contents.
遵循以下规则:
  • 临时设置:首次设置、调试和低风险试用的首选默认方案
  • 持久化设置:仅当用户明确要求每次启动Claude Code时都应用代理路径时使用
对于持久化设置,确认目标文件后,将相关键合并到
~/.claude/settings.json
中,请勿替换文件内容。

3. Create LiteLLM
config.yaml

3. 创建LiteLLM的
config.yaml

Start from the article's flow, but keep the provider naming aligned with LiteLLM docs:
yaml
model_list:
  - model_name: claude-opus-4.5
    litellm_params:
      model: github_copilot/claude-opus-4.5
      drop_params: true
Explain the fields:
  • model_name
    : the logical name Claude Code will request
  • model
    : the LiteLLM provider route, using
    github_copilot/<model>
  • drop_params: true
    : strips unsupported Anthropic-specific fields before forwarding to Copilot
If the user wants a different Copilot-backed model, keep the same pattern:
yaml
model_list:
  - model_name: <logical-name>
    litellm_params:
      model: github_copilot/<copilot-model>
      drop_params: true
Do not hardcode extra headers into the default path unless the user already hit a rejection that suggests header overrides are needed.
以官方文档流程为基础,但保持提供商命名与LiteLLM文档一致:
yaml
model_list:
  - model_name: claude-opus-4.5
    litellm_params:
      model: github_copilot/claude-opus-4.5
      drop_params: true
字段说明:
  • model_name
    :Claude Code将请求的逻辑模型名称
  • model
    :LiteLLM提供商路由,格式为
    github_copilot/<model>
  • drop_params: true
    :转发至Copilot前,移除不支持的Anthropic特定字段
如果用户需要对接其他Copilot支持的模型,遵循相同格式:
yaml
model_list:
  - model_name: <逻辑模型名>
    litellm_params:
      model: github_copilot/<copilot模型名>
      drop_params: true
除非用户遇到明确需要覆盖请求头的错误,否则默认路径中不要硬编码额外请求头。

4. Install and Start LiteLLM

4. 安装并启动LiteLLM

Preferred install:
bash
uv tool install "litellm[proxy]"
Fallback:
bash
pip install "litellm[proxy]"
Start the proxy from the directory containing
config.yaml
:
bash
litellm --config config.yaml --port 4000
Tell the user to keep that terminal open because the logs are the fastest truth source during verification.
推荐安装方式:
bash
uv tool install "litellm[proxy]"
备选安装方式:
bash
pip install "litellm[proxy]"
在包含
config.yaml
的目录中启动代理:
bash
litellm --config config.yaml --port 4000
告知用户保持该终端窗口打开,因为日志是验证过程中最直接的问题来源。

5. Explain GitHub Device Authorization

5. 解释GitHub设备授权流程

On the first successful request to the GitHub Copilot provider, LiteLLM may open a device authorization flow:
  1. LiteLLM prints a verification URL and device code
  2. the user opens the URL and approves the request
  3. LiteLLM stores the resulting credential locally for future use
Optional token-location overrides exist:
  • GITHUB_COPILOT_TOKEN_DIR
  • GITHUB_COPILOT_ACCESS_TOKEN_FILE
Only mention these when the user needs custom token storage, shared environments, or troubleshooting around expired or misplaced credentials.
首次成功请求GitHub Copilot提供商时,LiteLLM可能会触发设备授权流程:
  1. LiteLLM打印验证URL和设备码
  2. 用户打开该URL并授权请求
  3. LiteLLM将生成的凭证存储在本地,供后续使用
可选的令牌存储路径覆盖项:
  • GITHUB_COPILOT_TOKEN_DIR
  • GITHUB_COPILOT_ACCESS_TOKEN_FILE
仅当用户需要自定义令牌存储、共享环境或排查令牌过期/丢失问题时,才提及这些变量。

6. Configure Claude Code

6. 配置Claude Code

For a temporary PowerShell session:
powershell
$env:ANTHROPIC_AUTH_TOKEN = "sk-any-string"
$env:ANTHROPIC_BASE_URL = "http://localhost:4000"
$env:ANTHROPIC_MODEL = "claude-opus-4.5"
$env:CLAUDE_CODE_DISABLE_NONESSENTIAL_TRAFFIC = "1"
claude
For a temporary Bash or Zsh session:
bash
export ANTHROPIC_AUTH_TOKEN="sk-any-string"
export ANTHROPIC_BASE_URL="http://localhost:4000"
export ANTHROPIC_MODEL="claude-opus-4.5"
export CLAUDE_CODE_DISABLE_NONESSENTIAL_TRAFFIC=1
claude
For persistent configuration, merge these keys into
~/.claude/settings.json
:
json
{
  "env": {
    "ANTHROPIC_AUTH_TOKEN": "sk-any-string",
    "ANTHROPIC_BASE_URL": "http://localhost:4000",
    "ANTHROPIC_MODEL": "claude-opus-4.5",
    "CLAUDE_CODE_DISABLE_NONESSENTIAL_TRAFFIC": "1"
  }
}
Merge-safe behavior:
  • if the file does not exist, create it
  • if it exists, preserve all unrelated top-level keys
  • preserve existing
    env
    entries that are unrelated to this workflow
  • update only the four keys above
  • if the JSON is malformed, stop and report the parse problem instead of overwriting the file
临时PowerShell会话配置:
powershell
$env:ANTHROPIC_AUTH_TOKEN = "sk-any-string"
$env:ANTHROPIC_BASE_URL = "http://localhost:4000"
$env:ANTHROPIC_MODEL = "claude-opus-4.5"
$env:CLAUDE_CODE_DISABLE_NONESSENTIAL_TRAFFIC = "1"
claude
临时Bash或Zsh会话配置:
bash
export ANTHROPIC_AUTH_TOKEN="sk-any-string"
export ANTHROPIC_BASE_URL="http://localhost:4000"
export ANTHROPIC_MODEL="claude-opus-4.5"
export CLAUDE_CODE_DISABLE_NONESSENTIAL_TRAFFIC=1
claude
持久化配置:将以下键合并到
~/.claude/settings.json
中:
json
{
  "env": {
    "ANTHROPIC_AUTH_TOKEN": "sk-any-string",
    "ANTHROPIC_BASE_URL": "http://localhost:4000",
    "ANTHROPIC_MODEL": "claude-opus-4.5",
    "CLAUDE_CODE_DISABLE_NONESSENTIAL_TRAFFIC": "1"
  }
}
合并规则:
  • 如果文件不存在,创建该文件
  • 如果文件已存在,保留所有无关的顶级键
  • 保留与本工作流无关的现有
    env
    条目
  • 仅更新上述四个键
  • 如果JSON格式错误,停止操作并报告解析问题,请勿覆盖文件

7. Verify The Request Chain

7. 验证请求链路

Use two terminals when possible:
  • Terminal A runs LiteLLM
  • Terminal B runs
    claude
Ask for one small prompt such as a short script or code review request, then verify:
  • Claude Code starts normally
  • LiteLLM logs show an inbound request
  • LiteLLM logs indicate the GitHub Copilot model route, typically
    github_copilot/<model>
The healthy path is:
text
Claude Code -> LiteLLM -> GitHub Copilot -> LiteLLM -> Claude Code
尽可能使用两个终端:
  • 终端A运行LiteLLM
  • 终端B运行
    claude
让用户输入一个简单的提示(如简短脚本或代码审查请求),然后验证:
  • Claude Code正常启动
  • LiteLLM日志显示有入站请求
  • LiteLLM日志中出现GitHub Copilot模型路由,格式通常为
    github_copilot/<model>
健康的请求链路为:
text
Claude Code -> LiteLLM -> GitHub Copilot -> LiteLLM -> Claude Code

8. Troubleshooting

8. 故障排查

If Claude Code reports model-not-found, 404-like failures, or LiteLLM says the model does not exist:
  • compare
    ANTHROPIC_MODEL
    to
    model_name
    exactly
  • check case, punctuation, and hyphens
If LiteLLM never receives a request:
  • confirm
    ANTHROPIC_BASE_URL
    points to http://localhost:4000
  • confirm LiteLLM is still running on that port
  • confirm the environment variables were set in the same shell session that launched
    claude
  • check local firewall or port conflicts if the URL is correct but still silent
If LiteLLM reaches GitHub Copilot but gets 401 or 403 responses:
  • repeat the device authorization flow by restarting LiteLLM and retrying
  • confirm the GitHub account still has Copilot access
  • if custom token-directory variables are set, verify they point to the intended files
如果Claude Code报告模型未找到、类404错误,或LiteLLM提示模型不存在:
  • 检查
    ANTHROPIC_MODEL
    model_name
    是否完全一致
  • 注意大小写、标点符号和连字符
如果LiteLLM从未收到请求:
  • 确认
    ANTHROPIC_BASE_URL
    指向
    http://localhost:4000
  • 确认LiteLLM仍在该端口运行
  • 确认环境变量是在启动
    claude
    的同一个Shell会话中设置的
  • 如果URL正确但仍无流量,检查本地防火墙或端口冲突
如果LiteLLM连接到GitHub Copilot但收到401或403响应:
  • 重启LiteLLM并重试,重新触发设备授权流程
  • 确认GitHub账户仍拥有Copilot访问权限
  • 如果设置了自定义令牌目录变量,验证其指向的文件是否正确

Advanced Fallback: Header Overrides

高级备选方案:请求头覆盖

The article uses explicit Copilot-style headers. Current LiteLLM docs expose GitHub Copilot as a provider and also document header override support.
Only reach for explicit
extra_headers
when:
  • the basic provider flow reaches Copilot but still needs client-shape overrides
  • the user already has evidence that a specific environment behaves better with editor-style headers
Example fallback:
yaml
model_list:
  - model_name: claude-opus-4.5
    litellm_params:
      model: github_copilot/claude-opus-4.5
      drop_params: true
      extra_headers:
        editor-version: "vscode/1.85.1"
        editor-plugin-version: "copilot/1.155.0"
        Copilot-Integration-Id: "vscode-chat"
        user-agent: "GithubCopilot/1.155.0"
Present this as an advanced fallback, not the universal default.
官方文档中使用了Copilot风格的显式请求头。当前LiteLLM文档将GitHub Copilot作为提供商,并支持请求头覆盖。
仅在以下情况使用显式
extra_headers
  • 基础提供商流程已连接到Copilot,但仍需要调整客户端请求格式
  • 用户有证据表明特定环境使用编辑器风格的请求头表现更好
备选示例:
yaml
model_list:
  - model_name: claude-opus-4.5
    litellm_params:
      model: github_copilot/claude-opus-4.5
      drop_params: true
      extra_headers:
        editor-version: "vscode/1.85.1"
        editor-plugin-version: "copilot/1.155.0"
        Copilot-Integration-Id: "vscode-chat"
        user-agent: "GithubCopilot/1.155.0"
请将此作为高级备选方案,而非通用默认配置。

Output Checklist

输出检查清单

When answering a real user request with this skill, include:
  • the brief compliance caveat
  • the exact
    config.yaml
    or the delta to apply
  • shell-appropriate commands
  • whether the setup is temporary or persistent
  • the verification path
  • the smallest relevant troubleshooting section if something failed
使用本技能响应用户实际请求时,需包含:
  • 简短的合规提示
  • 完整的
    config.yaml
    或需修改的内容
  • 适配当前Shell的命令
  • 说明设置是临时还是持久化的
  • 验证流程
  • 如果出现问题,提供最精简的相关故障排查内容

Safety Reminders

安全提醒

  • Do not state that GitHub officially supports this workaround.
  • Do not imply that a dummy
    ANTHROPIC_AUTH_TOKEN
    is a real Copilot credential.
  • Do not recommend replacing
    ~/.claude/settings.json
    wholesale.
  • Do not present stale model names as guaranteed current availability; if the user asks for a specific model, keep the
    github_copilot/<model>
    pattern and note that Copilot-exposed model availability may change.
  • 请勿声明GitHub官方支持此变通方案。
  • 请勿暗示虚构的
    ANTHROPIC_AUTH_TOKEN
    是真实的Copilot凭证。
  • 请勿建议完全替换
    ~/.claude/settings.json
  • 请勿将过时的模型名称作为当前可用的保证;如果用户询问特定模型,保持
    github_copilot/<model>
    格式,并注明Copilot提供的模型列表可能会变化。