Hunter的大杂烩 技术学习笔记

2026-04-01

windows下使用claude code cli + openrouter

Filed under: 技术话题 — hunter @ 4:22 pm
  • 找个代理
  • 安装V2rayN 或clash,配置代理为 TUN 模式

参考 https://wstormai.store/posts/claude-anti-ban/

  • 执行claude code安装脚本
  • 申请openrouterkey
  • 运行claude code前,设置环境变量:
# 指向 OpenRouter 的兼容端点
$env:ANTHROPIC_BASE_URL=http://localhost:8080

# 使用 OpenRouter 的 API Key(ANTHROPIC_API_KEY必须设置,否则claude code需要你登录)
$env:ANTHROPIC_API_KEY="sk-or-v1-你的KEY"
$env:ANTHROPIC_AUTH_TOKEN=="sk-or-v1-你的KEY"
$env:OR_KEY="sk-or-v1-你的KEY"

# 指定要调用的具体模型
$env:ANTHROPIC_MODEL="z-ai/glm-5-turbo"
  • 配置代理脚本,用来注入authorize key
const http = require('http');
const https = require('https');

const server = http.createServer((req, res) => {
  const options = {
    hostname: 'openrouter.ai',
    path: '/api/v1/messages', // 确保路径匹配
    method: req.method,
    headers: {
      ...req.headers,
      'host': 'openrouter.ai',
      'Authorization': `Bearer ${process.env.OR_KEY}`, // 强制注入
    }
  };

  const proxy = https.request(options, (remoteRes) => {
    res.writeHead(remoteRes.statusCode, remoteRes.headers);
    remoteRes.pipe(res);
  });

  req.pipe(proxy);
});

server.listen(8080, () => console.log('Proxy running on http://localhost:8080'));
  • 进入项目目录
  • 先运行代理脚本
set OR_KEY="sk-or-v1-你的KEY"
node proxy.js
  • 开新窗口,运行claude code
set ANTHROPIC_BASE_URL=...
set ANTHROPIC_API_KEY=...
set ANTHROPIC_MODEL=...
claude.exe

No Comments

No comments yet.

RSS feed for comments on this post.

Sorry, the comment form is closed at this time.

Powered by WordPress