前序

通过订阅的GitHub Copilot使用强大开源的 Claude Code,原理就是 GitHub Copilot 提供了一个标准的 OpenAI 格式 API 端点:,这意味着支持 OpenAI API 的 Agent 工具理论上都能接入!

不过Claude Code 只接受 Anthropic API 格式,而 GitHub Copilot 提供的是 OpenAI 格式,可使用 github.com/ericc-ch/co… 完成接口的转换,可通过其--claude-code参数一键配置。

配置 Claude Code

打开终端,安装copilot-api,前提是系统已经安装好了Node.js.

#安装Copilot-api
 > npm install -g copilot-api

启动copilot-api代理服务

# --claude-code  Generate a command to launch Claude Code with Copilot API config
copilot-api start --claude-code

这时候会提示你进行 GitHub 授权,一定要注意这一步

Please visit https://github.com/login/device and enter code XXXX-XXXX to authenticate

按照提示访问 GitHub 登录页面,输入设备码完成授权。成功后你会看到可用模型列表以及 API 调用地址。

i Using VSCode version: 1.113.0                                                                               22:14:53
i Logged in as xxxxxxx                                                                                        22:14:54
i Available models:                                                                                           22:14:56
- gemini-3.1-pro-preview
- gpt-5.2-codex
- gpt-5.3-codex
- gpt-5.4-mini
- gpt-5.4
- gpt-5-mini
- gpt-4o-mini-2024-07-18
- gpt-4o-2024-11-20
- gpt-4o-2024-08-06
- grok-code-fast-1
- gpt-5.1
- text-embedding-3-small
- text-embedding-3-small-inference
- gemini-3-flash-preview
- gemini-2.5-pro
- gpt-4.1-2025-04-14
- gpt-5.2
- gpt-41-copilot
- gpt-3.5-turbo-0613
- gpt-4
- gpt-4-0613
- gpt-4-0125-preview
- gpt-4o-2024-05-13
- gpt-4-o-preview
- gpt-4.1
- gpt-3.5-turbo
- gpt-4o-mini
- gpt-4
- gpt-4o
- gpt-4-o-preview
- text-embedding-ada-002
undefined
√ Select a model to use with Claude Code
undefined gemini-3.1-pro-preview
undefined
√ Select a small model to use with Claude Code
undefined gpt-5.4
√ Copied Claude Code command to clipboard!                                                                    22:15:26

配置Claude Code

如果还没安装Claude Code, 同样可以用npm安装。

npm install -g @anthropic-ai/claude-code

打开Claude Code 配置文件,在 ~/.claude/settings.json 中添加以下配置:

{
  "env": {
    "ANTHROPIC_BASE_URL": "http://localhost:4141",
    "ANTHROPIC_AUTH_TOKEN": "dummy",
    "ANTHROPIC_MODEL": "gemini-3.1-pro-preview",
    "ANTHROPIC_SMALL_FAST_MODEL": "gpt-5.4",
    "DISABLE_NON_ESSENTIAL_MODEL_CALLS": "1",
    "CLAUDE_CODE_DISABLE_NONESSENTIAL_TRAFFIC": "1"
  }
}

注意:

  1. 如果你是windows系统,请修改`C:Users.claudesettings.json
    文件。
  2. ANTHROPIC_MODELANTHROPIC_SMALL_FAST_MODEL模型名选择在copilot-api start --claude-code阶段配置的模型。

验证

保持copilot-api启动状态,切换一个命令控制台,启动Claude。

> Claude

进行如下对话,即配置成功,你已成功用上了由Github Copilot 提供的模型的Cluade Code。



╭─── Claude Code v2.1.59 ───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╮
│                                                │ Tips for getting started                                                                                         │
│                  Welcome back!                 │ Run /init to create a CLAUDE.md file with instructions for Claude                                                │
│                                                │ Note: You have launched claude in your home directory. For the best experience, launch it in a project director… │
│                                                │ ──────────────────────────────────────────────────────────────────────────────────────────────────────────────── │
│                     ▐▛███▜▌                    │ Recent activity                                                                                                  │
│                    ▝▜█████▛▘                   │ No recent activity                                                                                               │
│                      ▘▘ ▝▝                     │                                                                                                                  │
│   gemini-3.1-pro-preview · API Usage Billing   │                                                                                                                  │
│               C:Usersleilei                  │                                                                                                                  │
╰───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯


 Auth conflict: Both a token (ANTHROPIC_AUTH_TOKEN) and an API key (ANTHROPIC_API_KEY) are set. This may lead to unexpected behavior.
    • Trying to use ANTHROPIC_AUTH_TOKEN? Unset the ANTHROPIC_API_KEY environment variable, or claude /logout then say "No" to the API key approval before login.
    • Trying to use ANTHROPIC_API_KEY? Unset the ANTHROPIC_AUTH_TOKEN environment variable.
  /model to try Opus 4.6

 你好

● 你好!有什么我可以帮你的吗?

 你是哪个模型

● 我是 Claude Code,Anthropic 官方出品的命令行工具。根据当前的运行环境,我由 gemini-3.1-pro-preview 模型提供支持。有什么我可以帮你的吗?

 帮我获取今天热度最高的新闻

● Web Search("今日热点新闻 2026年4月2日")
  ⎿  Did 0 searches in 7s

● Web Search("今日新闻 2026年4月2日")
  ⎿  Did 0 searches in 9s

● Web Search("top news today April 2 2026")
  ⎿  Did 0 searches in 9s

● 抱歉,我目前无法获取到今天的热点新闻。搜索结果没有返回相关的具体新闻信息。
本站提供的所有下载资源均来自互联网,仅提供学习交流使用,版权归原作者所有。如需商业使用,请联系原作者获得授权。 如您发现有涉嫌侵权的内容,请联系我们 邮箱:alixiixcom@163.com