ClaudeCode部署配置

Claude Code

Claude Code中文网 - AI编程助手完整教程

安装

Node.js ≥ 18

1
2
C:\Users\Administrator>node --version
v20.18.0

NPM安装

1
npm install -g @anthropic-ai/claude-code
1
2
3
4
5
6
7
8
9
10
11
C:\Users\Administrator>npm install -g @anthropic-ai/claude-code

added 2 packages in 15s

1 package is looking for funding
run `npm fund` for details
npm notice
npm notice New major version of npm available! 10.8.2 -> 11.6.2
npm notice Changelog: https://github.com/npm/cli/releases/tag/v11.6.2
npm notice To update run: npm install -g npm@11.6.2
npm notice

开始第一个会话

在任何项目目录中打开终端并启动 Claude Code:

1
2
cd /path/to/your/project
claude
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
Welcome to Claude Code v2.0.22
…………………………………………………………………………………………………………………………………………………………

* █████▓▓░
* ███▓░ ░░
░░░░░░ ███▓░
░░░ ░░░░░░░░░░ ███▓░
░░░░░░░░░░░░░░░░░░░ * ██▓░░ ▓
░▓▓███▓▓░
* ░░░░
░░░░░░░░
░░░░░░░░░░░░░░░░
█████████ *
██▄█████▄██ *
█████████ *
…………………█ █ █ █………………………………………………………………………………………………………………

Let's get started.

Choose the text style that looks best with your terminal
To change this later, run /theme

> 1. Dark mode √
2. Light mode
3. Dark mode (colorblind-friendly)
4. Light mode (colorblind-friendly)
5. Dark mode (ANSI colors only)
6. Light mode (ANSI colors only)
1
2
3
4
5
6
7
Claude Code can be used with your Claude subscription or billed based on API usage through your Console account.

Select login method:

> 1. Claude account with subscription · Pro, Max, Team, or Enterprise

2. Anthropic Console account · API usage billing

如何选择:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
选择 1:Claude 订阅账户(推荐给大多数用户)
适合: 如果你有 Claude Pro、Max、Team 或 Enterprise 订阅
优点:

包含在订阅费用中,无需额外付费
使用量通常更划算(特别是 Claude Max)
计费简单,每月固定费用

如何选择:

输入 1 然后回车
使用你的 claude.ai 账户登录

选择 2:Anthropic Console API 账户
适合: 如果你是开发者,有 Anthropic Console 账户并想按 API 使用量付费
优点:

按实际使用付费
适合偶尔使用或测试

缺点:

需要配置 API 密钥
对于频繁使用,成本可能更高

如何选择:

输入 2 然后回车
需要提供 API 密钥

使用claude-code-router配置api

由于Claude Code 使用的是 Anthropic 协议,而 OpenRouter 用的是 OpenAI 协议,因此使用claude-code-router来进行配置以兼容。

https://github.com/musistudio/claude-code-router/blob/main/README_zh.md

功能:

  • 模型路由: 根据您的需求将请求路由到不同的模型(例如,后台任务、思考、长上下文)。
  • 多提供商支持: 支持 OpenRouter、DeepSeek、Ollama、Gemini、Volcengine 和 SiliconFlow 等各种模型提供商。
  • 请求/响应转换: 使用转换器为不同的提供商自定义请求和响应。
  • 动态模型切换: 在 Claude Code 中使用 /model 命令动态切换模型。
  • GitHub Actions 集成: 在您的 GitHub 工作流程中触发 Claude Code 任务。
  • 插件系统: 使用自定义转换器扩展功能。

配置文件示例:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
{
"LOG": false,
"LOG_LEVEL": "debug",
"CLAUDE_PATH": "",
"HOST": "127.0.0.1",
"PORT": 3456,
"APIKEY": "",
"API_TIMEOUT_MS": "600000",
"PROXY_URL": "",
"transformers": [],
"Providers": [
{
"name": "openrouter",
"api_base_url": "https://openrouter.ai/api/v1/chat/completions",
"api_key": "你的key",
"models": [
"google/gemini-2.5-pro-preview",
"anthropic/claude-sonnet-4",
"anthropic/claude-3.5-sonnet",
"anthropic/claude-3.7-sonnet:thinking",
"qwen/qwen3-coder"
],
"transformer": {
"use": []
}
}
],
"StatusLine": {
"enabled": false,
"currentStyle": "default",
"default": {
"modules": []
},
"powerline": {
"modules": []
}
},
"Router": {
"default": "openrouter,qwen/qwen3-coder",
"background": "openrouter,qwen/qwen3-coder",
"think": "openrouter,qwen/qwen3-coder",
"longContext": "openrouter,qwen/qwen3-coder",
"longContextThreshold": 60000,
"webSearch": "openrouter,qwen/qwen3-coder",
"image": "openrouter,qwen/qwen3-coder"
},
"CUSTOM_ROUTER_PATH": ""
}

开始使用

使用claude-code-router后,利用ccr code命令启动claude code

image.png

用claude-code写一个贪吃蛇小游戏:

image.png


ClaudeCode部署配置
https://hxxyy.info/2025/10/19/ClaudeCode部署配置/
作者
HXXYY
发布于
2025年10月19日
许可协议