# 如何使用 Claude Code 运行本地 LLM

本分步指南将向你展示如何将开放式 LLM 和 API 完全在本地连接到 Claude Code，并附带截图。可使用任何开放模型运行，例如 Qwen3.6、DeepSeek 和 Gemma。

在本教程中，我们将使用这些开放模型： [Gemma 4](/docs/zh/mo-xing/gemma-4.md) 和 [Qwen3.5](/docs/zh/mo-xing/qwen3.5.md) 它们是强大的智能体与代码模型（可在 24GB RAM/统一内存设备上运行）。对于推理，我们将使用 [Unsloth Studio](https://github.com/unslothai/unsloth) 和 [`llama.cpp`](https://github.com/ggml-org/llama.cpp) 它使你能够在 macOS、Linux 和 Windows 上运行/提供 LLM 服务。你也可以替换为 [任何其他模型](/docs/zh/mo-xing/tutorials.md)，只需更新脚本中的模型名称。

<a href="/pages/1a707991086189a8e5cd8374f3ce1b81915bc159#claude-code-setup" class="button primary" data-icon="claude">Claude Code 设置</a><a href="/pages/1a707991086189a8e5cd8374f3ce1b81915bc159#quickstart-tutorials" class="button primary">📖 本地模型设置教程</a>

对于模型量化版本，我们将使用 Unsloth [动态 GGUF](/docs/zh/ji-chu/unsloth-dynamic-2.0-ggufs.md) 来运行任何量化后的 LLM，同时尽可能保留准确性。

## <i class="fa-claude">:claude:</i> Claude Code 设置

在设置本地 LLM 之前，我们需要安装 Claude Code。Claude Code 是一个基于终端的编码代理，它能够理解你的代码库，并使用自然语言处理复杂的 Git 工作流。

{% tabs %}
{% tab title="macOS、Linux、WSL" %}

#### **安装 Claude Code：**

将以下内容粘贴到终端中以安装 Claude Code：

```bash
curl -fsSL https://claude.ai/install.sh | bash
```

安装完成后，进入你的项目文件夹。然后输入 `claude` 到 `shell` 中开始。

```bash
cd ~/projects/my-project 
claude
```

{% endtab %}

{% tab title="Windows" %}

#### **安装 Claude Code：**

进入 `PowerShell` 以安装 Claude Code：

```powershell
irm https://claude.ai/install.ps1 | iex
```

安装完成后，进入你的项目文件夹。然后输入 `claude` 到 `powershell` 中开始。

<pre class="language-powershell"><code class="lang-powershell"><strong>cd /path/to/your/project
</strong>claude
</code></pre>

<div data-with-frame="true"><figure><img src="/files/7fbec167ff74cf9abb427048194317d761229e04" alt="" width="563"><figcaption></figcaption></figure></div>
{% endtab %}
{% endtabs %}

### :detective:修复 Claude Code 中推理速度慢 90% 的问题

{% hint style="warning" %}
Claude Code 最近会预置并添加一个 Claude Code Attribution 标头，这会 **使 KV Cache 失效，导致本地模型的推理速度慢 90%**.
{% endhint %}

为了解决这个问题，编辑 `~/.claude/settings.json` 以包含 `CLAUDE_CODE_ATTRIBUTION_HEADER` 并在 `"env"`

{% hint style="info" %}
使用 `export CLAUDE_CODE_ATTRIBUTION_HEADER=0` **不起** 作用！
{% endhint %}

例如这样做 `cat > ~/.claude/settings.json` 然后添加下面内容（粘贴后，按 ENTER，再按 CTRL+D 保存）。如果你已有之前的 `~/.claude/settings.json` 文件，只需添加 `"CLAUDE_CODE_ATTRIBUTION_HEADER" : "0"` 到“env”部分，其余设置文件内容保持不变。

<pre class="language-json"><code class="lang-json">{
  "promptSuggestionEnabled": false,
  "env": {
    "CLAUDE_CODE_ENABLE_TELEMETRY": "0",
    "CLAUDE_CODE_DISABLE_NONESSENTIAL_TRAFFIC": "1",
    <a data-footnote-ref href="#user-content-fn-1">"CLAUDE_CODE_ATTRIBUTION_HEADER" : "0"</a>
  },
  "attribution": {
    "commit": "",
    "pr": ""
  },
  "plansDirectory" : "./plans",
  "prefersReducedMotion" : true,
  "terminalProgressBarEnabled" : false,
  "effortLevel" : "high"
}
</code></pre>

## 📖 快速开始教程

{% columns %}
{% column %}
在开始之前，我们首先需要完成你将要使用的特定模型的设置。我们使用 [Unsloth](/docs/zh/xin/studio.md) （一个 Web UI）和 llama.cpp，它们都是可在你的 Mac、Linux、Windows 设备上运行和提供 LLM 服务的开源框架。

Unsloth 还具有独特的自我修复 [工具调用](/docs/zh/xin/studio/chat.md#auto-healing-tool-calling) 和 [网页搜索](/docs/zh/xin/studio/chat.md#code-execution) 能力。右侧可见 Claude Code 连接到 Unsloth：
{% endcolumn %}

{% column %}

<div data-with-frame="true"><figure><img src="/files/c633f6e5a61522d2d7fa76b1c6c3376b956d223d" alt=""><figcaption></figcaption></figure></div>
{% endcolumn %}
{% endcolumns %}

<a href="/pages/1a707991086189a8e5cd8374f3ce1b81915bc159#connect-claude-code" class="button primary" data-icon="claude">连接 Claude Code</a><a href="/pages/1a707991086189a8e5cd8374f3ce1b81915bc159#unsloth-tutorial" class="button primary">🦥 Unsloth 教程</a><a href="/pages/1a707991086189a8e5cd8374f3ce1b81915bc159#llama.cpp-tutorial" class="button primary"> llama.cpp 教程</a>

## 🦥 Unsloth 教程

在本教程中，我们将通过使用 [Unsloth](https://github.com/unslothai/unsloth)，经由 UI 将本地模型提供/连接给 Claude Code。Unsloth 可在 Windows、WSL、Linux 和 MacOS 上运行。&#x20;

{% columns %}
{% column %}

* 搜索、下载、 [运行 GGUF](/docs/zh/xin/studio.md#run-models-locally) 和 safetensor 模型
* [**自愈式** 工具调用](/docs/zh/xin/studio.md#execute-code--heal-tool-calling) + **网页搜索**
* [**代码执行**](/docs/zh/xin/studio.md#run-models-locally) （Python、Bash）
* [自动推理](/docs/zh/xin/studio.md#model-arena) 参数选择（temp、top-p 等）
* 通过 llama.cpp 实现快速 CPU + GPU 推理
* [训练 LLM](/docs/zh/xin/studio.md#no-code-training) 速度提升 2 倍，VRAM 减少 70%

安装说明见下：
{% endcolumn %}

{% column %}

<div data-with-frame="true"><figure><img src="/files/f8801eb887a6a996de4f745df66b4617f383d216" alt=""><figcaption><p>Qwen3.6 2-bit 在 Unsloth 中运行的示例。</p></figcaption></figure></div>
{% endcolumn %}
{% endcolumns %}

{% tabs %}
{% tab title="MacOS" %}

#### 第 1 步：设置 Unsloth

启动 `终端` 在 Mac 上，然后输入以下命令安装 Unsloth。

```bash
curl -fsSL https://unsloth.ai/install.sh | sh
```

Unsloth 将开始设置环境并安装所需软件包，如下所示。当询问你是否要现在允许 Studio 启动时，输入 **Y** 并按 `Enter` 。这将在你的本地 **8888** 端口上启动 Unsloth。

<figure><img src="/files/5f519c6be67e8e04d146b8890e77a97ea1d57b24" alt="" width="375"><figcaption></figcaption></figure>

{% hint style="info" %}
如果你在安装过程中选择不启动 Unsloth，之后也始终可以使用 `unsloth studio -p 8888` 来启动 Unsloth 应用。如果你希望你的 Unsloth 实例可被 PC/计算机外部的客户端访问，请添加 `-H 0.0.0.0` 到 `unsloth studio` 命令中。
{% endhint %}

#### 第 2 步：启动 Unsloth

打开你选择的浏览器并输入 `http://127.0.0.1:8888`  到 URL 输入框中。如果这是你第一次安装 Unsloth，你将被转到密码页面，在那里需要创建一个新密码。之后，Unsloth 应该会如下面所示打开到聊天页面。

<figure><img src="/files/752cee75840c3ad7dcf1d7c341a194e63895ac0e" alt="" width="375"><figcaption></figcaption></figure>
{% endtab %}

{% tab title="Windows" %}

#### 第 1 步：设置 Unsloth

打开开始菜单，搜索 `PowerShell`，并启动它。复制并输入安装命令：

```powershell
irm https://unsloth.ai/install.ps1 | iex
```

它将自动开始安装。安装完成后，PowerShell 会询问你是否要启动 Unsloth Studi&#x6F;**.**

<figure><img src="/files/5f519c6be67e8e04d146b8890e77a97ea1d57b24" alt="" width="375"><figcaption></figcaption></figure>

你也可以使用以下命令启动它：

```bash
unsloth studio -H 0.0.0.0 -p 8888
```

{% hint style="info" %}
如果你希望你的实例可被 PC/计算机外部的客户端访问。\
添加 `-H 0.0.0.0` 到 `unsloth studio` 命令中。
{% endhint %}

#### 第 2 步：启动 Unsloth

打开 `http://127.0.0.1:8888` 在浏览器中。首次启动时，创建一个新密码以继续进入聊天页面。 **Unsloth Studio** 现已安装完成并可供使用。

<figure><img src="/files/752cee75840c3ad7dcf1d7c341a194e63895ac0e" alt="" width="375"><figcaption></figcaption></figure>
{% endtab %}

{% tab title="Linux、WSL" %}

#### 第 1 步：设置 Unsloth

{% tabs %}
{% tab title="Linux" %}
打开你的终端应用程序。你可以按 `Ctrl + Alt + T`启动它，或在系统的应用程序菜单中搜索 `Terminal` 。
{% endtab %}

{% tab title="WSL" %}
点击 Windows 开始菜单，输入你已安装发行版的名称（例如 `Ubuntu`），然后打开它。

{% hint style="warning" %}
在 **WSL**上，确保你的 **NVIDIA 驱动** 已安装在 **Windows** （而不是在 WSL 内部），并且 **CUDA 工具包** 已安装在你的 WSL 发行版内部。详情请参阅下方的系统要求。
{% endhint %}
{% endtab %}
{% endtabs %}

要安装，请复制并运行安装命令：

```bash
curl -fsSL https://unsloth.ai/install.sh | sh
```

然后：

1. 点击终端窗口内部
2. 使用 `Ctrl + Shift + V`
3. 粘贴命令后按 `Enter`

Unsloth 将开始设置环境并安装所需软件包，如下所示。当询问你是否要现在允许 Studio 启动时，输入 **Y** 并按 `Enter` 。这将在你的本地 **8888** 端口上启动 Unsloth。

<figure><img src="/files/6f5baa1b6cb53a7720aa0f8a23166f0ba32cb456" alt=""><figcaption></figcaption></figure>

{% hint style="info" %}
如果你在安装过程中选择不启动 Unsloth，之后也始终可以使用 `unsloth studio -p 8888` 来启动 Unsloth 应用。如果你希望你的 Unsloth 实例可被 PC/计算机外部的客户端访问，请添加 `-H 0.0.0.0` 到 `unsloth studio` 命令中。
{% endhint %}

#### 第 2 步：启动 Unsloth

打开你选择的浏览器并输入 `http://127.0.0.1:8888`  到 URL 输入框中。如果这是你第一次安装 Unsloth，你将被转到密码页面，在那里需要创建一个新密码。之后，Unsloth 应该会如下面所示打开到聊天页面。

<figure><img src="/files/2426649b2fc23e17ba8d2ed31e9afcf2ccc21ee0" alt="" width="375"><figcaption></figcaption></figure>
{% endtab %}
{% endtabs %}

### 模型加载 + API 指南

{% stepper %}
{% step %}

#### 选择模型

在使用 API 之前，请先从 **选择模型** 下拉菜单（位于聊天页面左上角）中加载一个模型。

<figure><img src="/files/e7c1a267b0c4f58689066eddfc57a2c2211f1e13" alt=""><figcaption></figcaption></figure>

在本指南中，我们将使用： `unsloth/gemma-4-26B-A4B-it-GGUF` 以及推荐的 `UD-Q4_K_XL` 量化版本。
{% endstep %}

{% step %}

#### 测试模型

在使用客户端之前，先发送一条简短消息：

<div data-with-frame="true"><figure><img src="/files/d1ef1d199c3aee2da86cc3da46a133801d2683ad" alt="" width="563"><figcaption></figcaption></figure></div>

{% hint style="info" %}
这可确认模型已正确加载并准备好响应。
{% endhint %}
{% endstep %}

{% step %}

#### **Unsloth API 密钥**

在 Studio 中，打开 **设置 → API** 以查看或创建你的 API 密钥。

<figure><img src="/files/7d43e8763d1ae72290485151822b1ea2e4fce42a" alt=""><figcaption></figcaption></figure>

请像对待密码一样对待你的 API 密钥，并避免在截图或代码仓库中暴露它。
{% endstep %}
{% endstepper %}

## ⚙️ 连接 Claude Code

现在我们已经为 Claude Code 设置好了本地 LLM，接下来配置 Claude Code 以配合 Unsloth 或 llama.cpp 工作。我们先设置以下环境变量。默认情况下，这些变量不会在会话之间持久保留。&#x20;

{% tabs %}
{% tab title="MacOS、Linux、WSL" %}
**配置：** 设置本地 API URL：

```bash
export ANTHROPIC_BASE_URL="http://localhost:8888"
```

从 Unsloth Studio → 设置 → API 复制你的密钥，然后设置它：

```bash
export ANTHROPIC_AUTH_TOKEN="sk-unsloth-xxxxxxxxxxxx"
```

可选：使用当前在 Unsloth 中加载的模型名称作为默认值。

```bash
export ANTHROPIC_MODEL="gemma-4-26B-A4B-it-GGUF"
```

模型名称应与当前在 Unsloth Studio 中加载的模型一致。
{% endtab %}

{% tab title="Windows" %}
**配置：** 在 Powershell 中设置本地 API URL：

```powershell
$env:ANTHROPIC_BASE_URL = "http://localhost:8888"
```

从 **Unsloth Studio → 设置 → API**复制你的密钥，然后设置它：

```powershell
$env:ANTHROPIC_AUTH_TOKEN = "sk-unsloth-xxxxxxxxxxxx"
```

**可选：** 使用当前在 Unsloth 中加载的模型名称将其设为默认值。

```powershell
$env:ANTHROPIC_MODEL = "gemma-4-26B-A4B-it-GGUF"
```

{% hint style="info" %}
模型名称应为当前在 Unsloth Studio 中加载的模型。&#x20;
{% endhint %}
{% endtab %}
{% endtabs %}

### 启动 Claude Code

使用当前在 Unsloth 中加载的模型启动 Claude Code。

我们将使用 `gemma-4-26B-A4B-it-GGUF`，但你可以使用任何与 Unsloth 兼容的模型。&#x20;

```shellscript
claude --model unsloth/gemma-4-26B-A4B-it-GGUF
```

Claude Code 应会打开并显示所选模型。

<figure><img src="/files/6d4bc21d09fd5681680ae40843b06b44cfd15323" alt=""><figcaption></figcaption></figure>

{% hint style="warning" %}
查看 [#fixing-90-slower-inference-in-claude-code](#fixing-90-slower-inference-in-claude-code "mention") 先看这个，以修复由于 KV Cache 失效导致开放模型慢 90% 的问题。
{% endhint %}

试试这个提示词，用于研究并排列高质量 SFT 数据集。

{% code overflow="wrap" %}

```
你只能在 project/ 中工作。不要搜索 CLAUDE.md——这就是它。使用网页搜索在 Hugging Face 上找到 10 个真实的 instruction/chat/SFT 数据集，简要总结你的发现，并在研究过程中解释每个数据集为何与 SFT 相关，然后创建 sft_report.md 作为一份精心整理的 markdown 报告，其中包含排名、数据集名称、创建者、3–5 个相关标签、简短的通俗英文摘要，以及它为何对 SFT 有用。保持内容简洁易读，不要出现大量元数据转储、粘贴原始描述、过长标签列表或无关数据集。当 sft_report.md 包含 10 条干净、写得好的数据集条目时，任务即完成，并以：“Successfully finetuned a model with Unsloth!” 结束
```

{% endcode %}

提交提示词后，代理将搜索网络、评估结果并撰写最终报告。这可能需要几分钟。

某些工作流可能需要你批准操作或回答后续提示。

<figure><img src="/files/b62a6c3b23315b9c625654765c0c4e78269d7198" alt="" width="563"><figcaption></figcaption></figure>

{% hint style="info" %}
某些工作流可能需要你批准操作或回答后续提示。
{% endhint %}

完成后，生成的 `sft_report.md` 将看起来与此类似。

<figure><img src="/files/f00c03605b12f627ff1970d0d9d0721b7be2039c" alt="" width="375"><figcaption></figcaption></figure>

{% hint style="warning" %}
如果你看到 `Unable to connect to API (ConnectionRefused)` ，记得取消设置 `ANTHROPIC_BASE_URL`  通过 `unset ANTHROPIC_BASE_URL`

如果你发现开放模型慢了 90%， [先看这里](#fixing-90-slower-inference-in-claude-code) 以修复 KV 缓存失效的问题。
{% endhint %}

## 🦙 Llama.cpp 教程

在开始之前，我们首先需要完成你将要使用的特定模型的设置。我们使用 `llama.cpp` 它是一个开源框架，可在你的 Mac、Linux、Windows 等设备上运行 LLM。Llama.cpp 包含 `llama-server` ，它允许你高效地提供和部署 LLM。模型将在 8001 端口上提供服务，所有代理工具都通过一个兼容 OpenAI 的端点进行路由。

#### Qwen3.5 教程

我们将使用 [Qwen3.5](/docs/zh/mo-xing/qwen3.5.md)-35B-A3B 以及用于快速准确编码任务的特定设置。如果你没有足够的显存并且想要一个更 **聪明的** model, **Qwen3.5-27B** ，这是一个很好的选择，但速度会慢约 2 倍，或者你也可以使用其他 Qwen3.5 变体，如 9B、4B 或 2B。

{% hint style="info" %}
如果你想要一个 **聪明的** 模型，或者显存不足，请使用 Qwen3.5-27B。它会比 35B-A3B 慢约 2 倍。不过你也可以使用 [**Qwen3-Coder-Next**](/docs/zh/mo-xing/qwen3-coder-next.md) ，如果你有足够的显存，它会非常出色。
{% endhint %}

{% stepper %}
{% step %}

#### 安装 llama.cpp

我们需要安装 `llama.cpp` 来部署/提供本地 LLM，以便在 Claude Code 等中使用。我们遵循官方构建说明，以获得正确的 GPU 绑定和最高性能。更改 `-DGGML_CUDA=ON` 改为 `-DGGML_CUDA=OFF` 如果你没有 GPU，或者只想进行 CPU 推理。 **对于 Apple Mac / Metal 设备**，设置 `-DGGML_CUDA=OFF` 然后照常继续——Metal 支持默认开启。

```bash
apt-get update
apt-get install pciutils build-essential cmake curl libcurl4-openssl-dev git-all -y
git clone https://github.com/ggml-org/llama.cpp
cmake llama.cpp -B llama.cpp/build \
    -DBUILD_SHARED_LIBS=OFF -DGGML_CUDA=ON
cmake --build llama.cpp/build --config Release -j --clean-first --target llama-cli llama-mtmd-cli llama-server llama-gguf-split
cp llama.cpp/build/bin/llama-* llama.cpp
```

<figure><img src="/files/675408caceb845def8b58ffd8fabf4e741a6a196" alt="" width="563"><figcaption></figcaption></figure>
{% endstep %}

{% step %}

#### 在本地下载并使用模型

通过 `huggingface_hub` 在 Python 中下载模型（在通过 `pip install huggingface_hub hf_transfer`安装后）。我们使用 **UD-Q4\_K\_XL** 量化版本，以获得最佳的体积/精度平衡。你可以在我们的 [合集这里](/docs/zh/kai-shi-shi-yong/unsloth-model-catalog.md)。如果下载卡住，请参见 [Hugging Face Hub，XET 调试](/docs/zh/ji-chu/troubleshooting-and-faqs/hugging-face-hub-xet-debugging.md)

```bash
hf download unsloth/Qwen3.5-35B-A3B-GGUF \\
    --local-dir unsloth/Qwen3.5-35B-A3B-GGUF \\
    --include "*UD-Q4_K_XL*" # 动态 2 位请使用 "*UD-Q2_K_XL*"
```

<figure><img src="/files/9d9a42a31d027b31aaf6635b3710f3a53d4a6caa" alt=""><figcaption></figcaption></figure>

{% hint style="success" %}
中找到所有 Unsloth GGUF 上传内容。我们使用了 `unsloth/Qwen3.5-35B-A3B-GGUF` ，但你也可以使用其他变体，如 27B，或者任何其他模型，例如 `unsloth/`[`Qwen3-Coder-Next`](/docs/zh/mo-xing/qwen3-coder-next.md)`-GGUF`.
{% endhint %}

<figure><img src="/files/56f8dbb1752bda89c4b66bc6ba2989c83811280a" alt="" width="563"><figcaption></figcaption></figure>
{% endstep %}

{% step %}

#### 启动 Llama-server

为了为智能体工作负载部署 Qwen3.5，我们使用 `llama-server`。我们应用 [Qwen 推荐的采样参数](/docs/zh/mo-xing/qwen3.5.md#recommended-settings) 用于思考模式： `temp 0.6`, `top_p 0.95` , `top-k 20`。请记住，如果你使用非思考模式或其他任务，这些数值会发生变化。

在新终端中运行此命令（使用 `tmux` 或打开一个新终端）。以下配置应当 **可完美适配 24GB GPU（RTX 4090）（占用 23GB）** `--fit on` 也会自动卸载，但如果你看到性能不佳，请降低 `--ctx-size` .

{% hint style="info" %}
中找到所有 Unsloth GGUF 上传内容。我们使用了 `--cache-type-k q8_0 --cache-type-v q8_0` 以对 KV 缓存进行量化，从而减少显存使用。若要使用全精度，请使用 `--cache-type-k bf16 --cache-type-v bf16` 。注意 bf16 KV Cache 在某些机器上可能会稍慢。
{% endhint %}

```bash
./llama.cpp/llama-server \
    --model unsloth/Qwen3.5-35B-A3B-GGUF/Qwen3.5-35B-A3B-UD-Q4_K_XL.gguf \\
    --alias "unsloth/Qwen3.5-35B-A3B" \\
    --temp 0.6 \\
    --top-p 0.95 \
    --top-k 20 \\
    --min-p 0.00 \\
    --port 8001 \
    --kv-unified \\
    --cache-type-k q8_0 --cache-type-v q8_0
```

{% hint style="success" %}
你也可以为 Qwen3.5 禁用 thinking，这可以提升智能体编码任务的性能。要在 llama.cpp 中禁用 thinking，请将以下内容添加到 llama-server 命令中：

`--chat-template-kwargs "{\"enable_thinking\": false}"`

<img src="/files/122fbec0dd1c1450b0f18c87633b0cabb192a69b" alt="" data-size="original">
{% endhint %}
{% endstep %}
{% endstepper %}

### 使用 llama-server 启动 Claude Code

{% hint style="success" %}
中找到所有 Unsloth GGUF 上传内容。我们使用了 `unsloth/GLM-4.7-Flash-GGUF` ，但你也可以使用任何模型，例如 `unsloth/Qwen3.6-27B-GGUF`.
{% endhint %}

{% hint style="warning" %}
查看 [#fixing-90-slower-inference-in-claude-code](#fixing-90-slower-inference-in-claude-code "mention") 先看这个，以修复由于 KV Cache 失效导致开放模型慢 90% 的问题。
{% endhint %}

进入你的项目文件夹（`mkdir project ; cd project`）并运行：

```bash
claude --model unsloth/GLM-4.7-Flash
```

要使用 Qwen3.6-35B-A3B，只需将其改为：

```bash
claude --model unsloth/Qwen3.6-35B-A3B
```

<div data-with-frame="true"><figure><img src="/files/9895a3039484599f93e699644a0bf20622f32921" alt="" width="563"><figcaption></figcaption></figure></div>

如果要将 Claude Code 设置为无需任何批准即可执行命令，请执行 **（注意：这会让 Claude Code 在无需任何批准的情况下按它自己的方式执行和运行代码！）**

{% code overflow="wrap" %}

```bash
claude --model unsloth/GLM-4.7-Flash --dangerously-skip-permissions
```

{% endcode %}

试试这个提示词来安装并运行一个简单的 Unsloth 微调：

{% code overflow="wrap" %}

```
你只能在当前工作目录 project/ 中工作。不要搜索 CLAUDE.md——这就是它。通过 uv 使用虚拟环境安装 Unsloth。如果可能，请使用 `python -m venv unsloth_env`，然后使用 `source unsloth_env/bin/activate`。关于安装方法，请参阅 https://unsloth.ai/docs/get-started/install/pip-install（获取并阅读）。然后执行 https://github.com/unslothai/unsloth 中描述的一个简单 Unsloth 微调运行。你可以使用 1 块 GPU。
```

{% endcode %}

<div data-with-frame="true"><figure><img src="/files/a3431c9353badb6bb35de75882b82d4a13ca2b49" alt="" width="563"><figcaption></figcaption></figure></div>

稍等片刻后，Unsloth 将通过 uv 安装到一个 venv 中，并加载完成：

<div data-with-frame="true"><figure><img src="/files/6ba0cfee745ccd165528bf1db06ec5ad1ab35122" alt="" width="563"><figcaption></figcaption></figure></div>

最后你将看到一个使用 Unsloth 成功微调的模型！

<div data-with-frame="true"><figure><img src="/files/4e98c753b70b30afb88ce8604503bcf46e1229ba" alt="" width="563"><figcaption></figcaption></figure></div>

{% hint style="warning" %}
如果你看到 `Unable to connect to API (ConnectionRefused)` ，记得取消设置 `ANTHROPIC_BASE_URL`  通过 `unset ANTHROPIC_BASE_URL`

如果你发现开放模型慢了 90%， [先看这里](#fixing-90-slower-inference-in-claude-code) 以修复 KV 缓存失效的问题。
{% endhint %}

[^1]: 必须使用这个！


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://unsloth.ai/docs/zh/ji-chu/claude-code.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
