AI > Claude Code >
Claude Code + Qwen的配置详细步骤
IT乐手
前言
由于 Claude Code 和 Qwen 的请求格式有点不兼容,需要另外写一个代理来确保正常地请求
使用代理拦截和修改请求
const http = require('http');
const https = require('https');
const targetHost = 'dashscope.aliyuncs.com';
const targetPath = '/apps/anthropic/v1/messages';
const server = http.createServer((req, res) => {
// 处理 OPTIONS 预检请求(CORS)
if (req.method === 'OPTIONS') {
res.writeHead(200, {
'Access-Control-Allow-Origin': '*',
'Access-Control-Allow-Methods': 'POST, OPTIONS',
'Access-Control-Allow-Headers': '*'
});
res.end();
return;
}
// 只处理 POST 请求
if (req.method !== 'POST') {
res.writeHead(405);
res.end('Method Not Allowed');
return;
}
let body = '';
req.on('data', chunk => { body += chunk; });
req.on('end', () => {
// 检查 body 是否为空
if (!body || body.trim() === '') {
console.error('收到空请求体');
res.writeHead(400);
res.end('Empty request body');
return;
}
try {
const originalReq = JSON.parse(body);
// 修改 max_tokens
if (originalReq.max_tokens > 8192) {
originalReq.max_tokens = 8192;
console.log(`✅ 调整 max_tokens 为 8192`);
}
// 确保 top_p 等参数也在范围内
if (originalReq.top_p && originalReq.top_p > 1) {
originalReq.top_p = 0.95;
console.log(`✅ 调整 top_p 为 0.95`);
}
const options = {
hostname: targetHost,
path: targetPath,
method: 'POST',
headers: {
...req.headers,
'host': targetHost,
'content-length': Buffer.byteLength(JSON.stringify(originalReq))
}
};
const proxyReq = https.request(options, (proxyRes) => {
res.writeHead(proxyRes.statusCode, proxyRes.headers);
proxyRes.pipe(res);
});
proxyReq.write(JSON.stringify(originalReq));
proxyReq.end();
console.log(`✅ 请求转发成功 - max_tokens: ${originalReq.max_tokens}`);
} catch(e) {
console.error('❌ Proxy error:', e.message);
console.error('原始 body 内容:', body.substring(0, 200));
res.writeHead(500);
res.end('Proxy error: ' + e.message);
}
});
});
server.listen(8080, () => {
console.log('✅ Proxy running on http://localhost:8080');
});然后修改settings.json:**
{
"env": {
"ANTHROPIC_AUTH_TOKEN": "你的apikey",
"ANTHROPIC_BASE_URL": "http://localhost:8080",
"ANTHROPIC_MODEL": "qwen3-coder-plus"
}
}如果还需要中文回答,可以配置提示词
在 claude 根目录下放 CLAUDE.md ( settings.json同级位置 )
# 语言规则
- 请始终使用简体中文回答我的所有问题和请求。
- 代码注释使用中文,但函数名和变量名保持英文。
- 技术术语可以保留英文,但需提供中文解释。
使用方法
先用 node 运行 proxy.js 最后再启动 claude 就可以用了
到此这篇关于Claude Code + Qwen 的配置方法的文章就介绍到这了,更多相关Claude Code Qwen配置内容请搜索脚本之家以前的文章或继续浏览下面的相关文章,希望大家以后多多支持脚本之家!
