# 两行命令，用免费模型运行 Claude Code

> 安装 anyr CLI，然后运行 anyr claude。Claude Code 可以在 AnyRouter 的免费模型上运行，不需要绑卡。包含完整命令、手动配置、可以试的模型和限制。

- Date: October 16, 2026
- Category: guides
- HTML: https://anyrouter.dev/blog/zh/claude-code-free-models

## 两行命令

安装 `anyr` CLI，然后通过它在免费路由上启动 Claude Code：

```bash
curl -fsSL https://anyrouter.dev/cli.sh | bash
anyr claude --model anyrouter/free
```

第一次运行会打开浏览器让你登录，创建 key 并保存。之后的运行会直接进入 Claude Code。如果还没装 Claude Code，加上 `--install`，`anyr` 会先帮你安装。需要 AnyRouter 账号，但不需要绑卡。

`anyrouter/free` 会选一个当前健康的免费模型，失败时回退到下一个。同样的两行命令也在 [/claude-code](https://anyrouter.dev/claude-code) 页面上；登录后的版本已填入你自己的 key，在 [/welcome#claude-code](https://anyrouter.dev/welcome#claude-code)。

## 让后台调用也免费

Claude Code 会把一部分调用发给小型后台模型和子代理。`anyr claude` 默认把它们指向 Claude Haiku，而这个模型只能通过你自己的供应商 key（BYOK）使用。没有 BYOK key 的 Free 账号即使主模型是免费的，这些调用也可能以 `404 model_unavailable` 失败。把所有别名都固定到免费路由即可避免：

```bash
anyr claude --model anyrouter/free \
  --haiku anyrouter/free --sonnet anyrouter/free \
  --opus anyrouter/free --fable anyrouter/free
```

`anyr claude --dry-run` 会打印它将使用的命令和环境变量（key 已打码），方便你在开始前检查这些别名。

## 不用 CLI

Claude Code 读取两个环境变量。先在[控制台](https://anyrouter.dev/dashboard/keys)创建 key（每把 key 都以 `sk-ar-` 开头），然后：

```bash
export ANTHROPIC_BASE_URL="https://anyrouter.dev/api"
export ANTHROPIC_API_KEY="sk-ar-your-key"
claude --model anyrouter/free
```

base URL 不要带 `/v1`：Claude Code 会自己拼上 `/v1/messages`。完整参考：[anyrouter.dev/docs/cli/claude-code](https://anyrouter.dev/docs/cli/claude-code)。

## 可以试哪些免费模型

我们没有为编码给免费模型排名，任何排名一周就会过时。我们能说的是：`anyrouter/free` 可能路由到哪些模型，且上下文至少有 128K，因为 Claude Code 自己的提示词和工具列表会占掉小窗口的一大部分。下表在构建页面时从目录生成。

| 模型 | Id | 上下文 |
| --- | --- | --- |
| [LongCat-2.5](https://anyrouter.dev/model/meituan/longcat-2.5) | `meituan/longcat-2.5` | 1M |
| [Beam 1.0](https://anyrouter.dev/model/reflection/beam-1.0) | `reflection/beam-1.0` | 1M |
| [Glyph Cluster](https://anyrouter.dev/model/stealth/glyph-cluster) | `stealth/glyph-cluster` | 256K |
| [Dots3-Note Preview](https://anyrouter.dev/model/dots-studio/dots-3-note-preview) | `dots-studio/dots-3-note-preview` | 512K |
| [Nemotron 3.5 Lightning 30B A3B](https://anyrouter.dev/model/nvidia/nemotron-3.5-lightning-30b-a3b) | `nvidia/nemotron-3.5-lightning-30b-a3b` | 1M |
| [Qwen3-8B](https://anyrouter.dev/model/qwen/qwen3-8b) | `qwen/qwen3-8b` | 128K |
| [North Mini Code](https://anyrouter.dev/model/cohere/north-mini-code) | `cohere/north-mini-code` | 256K |
| [Nemotron 3 Ultra 550B](https://anyrouter.dev/model/nvidia/nemotron-3-ultra-550b-a55b) | `nvidia/nemotron-3-ultra-550b-a55b` | 1M |
| [GPT-OSS 20B](https://anyrouter.dev/model/openai/gpt-oss-20b) | `openai/gpt-oss-20b` | 131K |
| [Qwen 2.5 Coder 32B](https://anyrouter.dev/model/qwen/qwen2.5-coder-32b-instruct) | `qwen/qwen2.5-coder-32b-instruct` | 131K |

把任意 id 传给 `--model` 即可固定该模型。完整的最新列表在 [/free](https://anyrouter.dev/free)。如果只想看支持 Claude Code 所用 Messages API 的模型，可以筛选[模型列表](https://anyrouter.dev/models?endpoint=messages)。

## 限制，直说

- 费用：免费模型每个 token 计费 $0，不动用你的额度余额。付费模型在你添加额度或套餐之前会返回 `402`。
- 速率：没有每日上限。Go 及以上套餐的免费模型共享每个 API key 每分钟 2,400 次请求。
- 登录：不带 key 的请求会收到 `401`。注册是免费的。
- 质量：这些不是 Claude。复杂的多文件任务最容易让免费模型卡住或出错，所以像对待任何代理一样审查 diff。
- 可用性：免费容量来自上游供应商，会变化。`anyrouter/free` 会自动回退，但固定的模型可能繁忙或已下线。
- 设置：如果 Zero Data Retention 这类隐私设置排除了所有免费模型，你会收到 `400 no_eligible_models`。固定一个符合该设置的模型。
- 长任务：对于慢速模型，`export API_TIMEOUT_MS=3000000` 可以提高 Claude Code 的超时时间。`anyr` 启动器已经设置了它。

## 确认生效

运行任意提示词，然后打开你的[请求日志](https://anyrouter.dev/dashboard/logs)。这次调用会在流结束后几秒出现，包含作答的模型、token 数和费用。免费调用显示 $0。

从 OpenRouter 迁移？同样的两行替换适用于任何兼容 OpenAI 的客户端。参见 [AnyRouter 对比 OpenRouter](/blog/zh/anyrouter-vs-openrouter)，有带来源的对比和迁移步骤。

在 Claude Code 里用免费模型：两行命令，不需要绑卡。

[打开设置页面](https://anyrouter.dev/claude-code)
