平时做技术实践时,很多问题不是概念不会,而是细节没串起来。拿“Claude Code + Qwen的配置详细步骤”来说,它看着像小点,放到项目里常会牵出环境、配置、兼容性和维护成本。下面按实际使用顺序,把思路、关键写法和容易踩坑的地方讲清楚,方便你直接对照操作。
前言
在这个场景下,由于 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这部分内容适合结合实际项目边做边理解。先抓住核心思路,再逐步补上细节和边界处理,最后效果会更稳定,也更容易复用。