李强 发表于 2025-7-16 15:43:57

【Claude Code】使用 claude-code-router 快速配置第三方模型

<h2><code>claude-code-router</code> 项目地址</h2>
<p>GitHub - musistudio/claude-code-router: Use Claude Code as the foundation for coding👇</p>
<blockquote>
<p>https://github.com/musistudio/claude-code-router</p>
</blockquote>
<h2>使用步骤</h2>
<h3>1. 安装 Claude 代码</h3>
<pre><code class="language-shell">npm install -g @anthropic-ai/claude-code
</code></pre>
<h3>2. 安装 claude-code-router</h3>
<pre><code class="language-shell">npm install -g @musistudio/claude-code-router
</code></pre>
<h3>3. 生成初始配置</h3>
<pre><code class="language-shell">ccr start
</code></pre>
<p><strong>提示:</strong> 暂时随意输入值,因为我们将在下一步直接编辑配置文件,完成后按 <code>Ctrl+C</code> 退出终端。</p>
<h3>4. 编辑配置文件</h3>
<p>打开配置文件(可以直接copy我的配置)</p>
<ul>
<li><strong>linux/mac:</strong><code>~/.claude-code-router/config.json</code></li>
<li><strong>Windows:</strong><code>C:/User/用户/.claude-code-router/config.json</code></li>
</ul>
<p>这是一个 Moonshot (Kimi k2) 官方模型和 siliconflow硅基流动 的简单配置示例:</p>
<pre><code class="language-yaml">{
&quot;LOG&quot;: false,
&quot;OPENAI_API_KEY&quot;: &quot;&quot;,
&quot;OPENAI_BASE_URL&quot;: &quot;&quot;,
&quot;OPENAI_MODEL&quot;: &quot;&quot;,
&quot;Providers&quot;: [
    {
      &quot;name&quot;: &quot;siliconflow&quot;,
      &quot;api_base_url&quot;: &quot;https://api.siliconflow.cn/v1/chat/completions&quot;,
      &quot;api_key&quot;: &quot;sk-xxx&quot;,
      &quot;models&quot;: [
      &quot;moonshotai/Kimi-K2-Instruct&quot;
      ],
      &quot;transformer&quot;: {
      &quot;use&quot;: [
          [
            &quot;maxtoken&quot;,
            {
            &quot;max_tokens&quot;: 16384
            }
          ]
      ]
      }
    },
    {
      &quot;name&quot;: &quot;moonshot&quot;,
      &quot;api_base_url&quot;: &quot;https://api.moonshot.cn/v1/chat/completions&quot;,
      &quot;api_key&quot;: &quot;sk-xxx&quot;,
      &quot;models&quot;: [
      &quot;kimi-k2-0711-preview&quot;
      ],
      &quot;transformer&quot;: {
      &quot;use&quot;: [
          &quot;openrouter&quot;
      ]
      }
    }
],
&quot;Router&quot;: {
    &quot;default&quot;: &quot;siliconflow,moonshotai/Kimi-K2-Instruct&quot;
}
}
</code></pre>
<h3>6. 启动</h3>
<p>配置完成后,使用 ccr code 命令替代原来的 claude 命令来启动您的项目</p>
<pre><code class="language-css">ccr code
</code></pre>
<p><strong>注意:</strong></p>
<ul>
<li><code>transformer</code> 是一个关键参数,用于解决不同 LLM 提供商之间 API 格式的兼容性问题。</li>
<li><strong>更多参数可以去项目中查看</strong></li>
</ul>
<p>配置起来很方便,分享给大家!</p>

longxx888 发表于 2025-7-16 15:44:40

感谢分享

winpe 发表于 2025-7-16 15:44:56

感谢分享,部署了试试看

ss20052008 发表于 2025-7-16 15:45:11

上半年刷了一些硅基流动的key,一直没有用。
感谢,可以尝试一下k2了。

xzshengli 发表于 2025-7-16 15:45:33

ss20052008 发表于 2025-7-16 15:45
上半年刷了一些硅基流动的key,一直没有用。
感谢,可以尝试一下k2了。

K2可以直接上了,不用这么麻烦了

ghgh456 发表于 2025-7-16 15:46:34

claude code 强,不是他的模型强吗? 换了模型 还能那么厉害吗?

李强 发表于 2025-7-16 15:47:09

ghgh456 发表于 2025-7-16 15:46
claude code 强,不是他的模型强吗? 换了模型 还能那么厉害吗?

各有长短,搭配使用更佳

cirock 发表于 2025-7-16 17:30:02

感谢分享项目步骤

hslxwu 发表于 2025-7-28 19:30:02

这配置看着不难嘛
页: [1]
查看完整版本: 【Claude Code】使用 claude-code-router 快速配置第三方模型