解决 VS Code 中 Claude Code 新版插件无法使用

751 字
4 分钟
解决 VS Code 中 Claude Code 新版插件无法使用

前言#

现在 AI 发展的是真的快,甚至有点担心未来就业等问题。

群友们天天在聊 Vibe Coding,我也跟上了脚步,使用起来是真的舒服,至于 API 主要还是找的公益的。就在最近一个月发现 VS Code 中的 Claude Code 更新2.0新版本了且有个重要的问题就是部分 API 无法在插件中使用,但在 CLI 终端中却能正常使用,且明显状况就是响应很慢,然后报错(不同站点报错不同)。

之前刷帖的时候记得有人说过和 UA 有关系,但是后面找不到了。通过 CCR 的 自定义转换器功能发现他会替换所有请求头,就索性放弃了。

隔了几天发现某群的大佬发布了 CCR 的修改代码,后面经过测试确实能成功,但是某 API 是检测系统提示词,而大佬的代码的这部分不生效,我从另一个群友那索要了一份(因为他是直接把代码丢给 AI 去定位修改的,然后 AI 顺便修复了这个 BUG😂)。 还有一种适合不使用 CCR 的方法,经过群主给的 AI 回复,通过 Nginx 反向代理解决 UA 问题,我也试了确实能成功(我当时居然没想到用这种方法)。

故此有了这篇文章(不会特别详细,需要淘汰部分人。因为发现使用 Vibe Coding 门槛太低了,经常发现群里很多人连环境都配不好…)

方法#

1. 通过 Nginx 反代配置#

提示

仅支持判断 UA 的中转 API

使用这段反代配置反代 CCR,然后记得修改 Claude Code 配置文件的 API 为反代服务的地址

判断 UA 是否为 Claude CLI,自动替换新版本号

location / {
set $new_user_agent $http_user_agent;
if ($http_user_agent ~* "claude-cli/([0-9]+\.[0-9]+\.[0-9]+) \(external, claude-vscode\)") {
set $new_user_agent "claude-cli/$1 (external, cli)";
}
proxy_pass http://你的 CCR 服务IP:CCR 端口;
proxy_set_header User-Agent $new_user_agent;
proxy_http_version 1.1;
proxy_buffering off;
}

2. 修改 CCR 文件#

这个需要我们手动修改 CCR 的一个叫 cli.js 的文件,这玩意是构建完后的文件,很大,最好在本地 IDE 编辑(其实可以修改 CCR 源代码构建,但是觉得有些许麻烦,干脆等待作者更新或者后面有需求再看把)

我们首先得找到 cli.js文件,我这里是 docker 部署的,位置是 /app/node_modules/@musistudio/claude-code-router/dist/cli.js

打开文件,直接搜索 asyncauth(e, t) {,然后把这段代码替换成以下代码即可

async auth(e, t) {
let n = {
"user-agent": "claude-cli/2.0.19 (external, cli)"
};
if(e.system && Array.isArray(e.system) && e.system.length && e.system[0].text !== "You are Claude Code, Anthropic's official CLI for Claude."){
if(e.system[0].text.startsWith("You are Claude Code, Anthropic's official CLI for Claude")){
e.system[0].text = "You are Claude Code, Anthropic's official CLI for Claude.";
}else{
// Replace the first system item with the canonical system prompt
e.system[0] = ({ type: "text", text: "You are Claude Code, Anthropic's official CLI for Claude.", cache_control: e.system[0].cache_control});
}
}
return this.useBearer ? (n.authorization = `Bearer ${t.apiKey}`, n["x-api-key"] = void 0) : (n["x-api-key"] = t.apiKey, n.authorization = void 0), { body: e, config: { headers: n } };
}

文章分享

如果这篇文章对你有帮助,欢迎分享给更多人!

解决 VS Code 中 Claude Code 新版插件无法使用
https://blog.nwn.moe/posts/14/
作者
籽夏
发布于
2025-10-17
许可协议
CC BY-NC-SA 4.0

评论区

Profile Image of the Author
籽夏
谎言的代价是什么?
公告
欢迎来到我的博客!
分类
标签
站点统计
文章
15
分类
3
标签
12
总字数
34,084
运行时长
0
最后活动
0 天前
站点信息
文章许可
CC BY-NC-SA 4.0
构建时间
2026年8月29日 00:03:12