← 返回首页
Setup阅读时间 8 min

国内怎么用 Claude Code 2026 | GLM Coding Plan 原生方案(不用 VPN)

Anthropic 屏蔽国内,但 GLM Coding Plan 和 Kimi Code 都走 Anthropic 协议——让 Claude Code CLI 指向它们,国内问题就没了。

一键速查

装 Claude Code CLI → 配环境变量指向 GLM 或 Kimi → 跑 claude。整个教程就这几步,下面是细节。

流程总览

1订阅 GLM Coding Plan打开 https://z.ai/subscribe 或 bigmodel.cn(人民币计费)选档位。Lite $3 足够验证。支持支付宝、微信、美元卡。2拿 API key订阅完成后在 Z.ai 控制台 → API Keys → 创建一个绑定到你 Coding Plan 的 key,复制备用。3安装 Claude Code CLI官方安装:npm install -g @anthropic-ai/claude-code,或者用原生安装器。这一步不需要代理,npm 镜像就能装。4让 Claude Code 指向 GLM配两个环境变量,完全跳过 Anthropic 登录流程。写进 ~/.zshrc 或 ~/.bashrc 让每个 shell 都能读到。5正常跑 Claude Code进入项目目录,输入 claude。CLI 会无感走 GLM-5.1。slash 命令、MCP 服务器、sub-agent 全都继续用。6验证模型Claude Code 里打 /model 或 /debug 确认确实是 GLM 在服务。应该看到 GLM-5.1 或 GLM-5-Turbo。

详细步骤

1

订阅 GLM Coding Plan

打开 https://z.ai/subscribe 或 bigmodel.cn(人民币计费)选档位。Lite $3 足够验证。支持支付宝、微信、美元卡。

2

拿 API key

订阅完成后在 Z.ai 控制台 → API Keys → 创建一个绑定到你 Coding Plan 的 key,复制备用。

3

安装 Claude Code CLI

官方安装:npm install -g @anthropic-ai/claude-code,或者用原生安装器。这一步不需要代理,npm 镜像就能装。

npm install -g @anthropic-ai/claude-code
4

让 Claude Code 指向 GLM

配两个环境变量,完全跳过 Anthropic 登录流程。写进 ~/.zshrc 或 ~/.bashrc 让每个 shell 都能读到。

export ANTHROPIC_BASE_URL=https://open.bigmodel.cn/api/anthropic
export ANTHROPIC_API_KEY=你的_zai_key
5

正常跑 Claude Code

进入项目目录,输入 claude。CLI 会无感走 GLM-5.1。slash 命令、MCP 服务器、sub-agent 全都继续用。

cd your-project
claude
6

验证模型

Claude Code 里打 /model 或 /debug 确认确实是 GLM 在服务。应该看到 GLM-5.1 或 GLM-5-Turbo。

⚠️ 踩坑提醒

  • !不要用 Anthropic 账号登录 Claude Code——会强制走 api.anthropic.com,国内必挂。完全靠环境变量。
  • !如果 claude 还在找 Anthropic,说明环境变量没生效。echo $ANTHROPIC_BASE_URL 检查,然后重开终端。
  • !bigmodel 国内端点走人民币计费。如果你要美元计费换成 https://api.z.ai/api/anthropic。
  • !npm install 被墙了就切淘宝镜像:npm config set registry https://registry.npmmirror.com。

相关内容

常见问题

真的不用 VPN 吗?

不用。ANTHROPIC_BASE_URL 指向 Z.ai 或 bigmodel 后,所有 Claude Code 流量走国内友好域名。

以后还想用真·Claude 模型怎么办?

把环境变量 unset 或者换一个 shell profile 就行。Claude Code 用环境变量配置不存在锁定。

这个方案能用 Claude Code Max 的功能吗?

CLI 层的功能(slash、MCP、sub-agent)都能用,模型质量是 GLM 本身,不是 Opus。Max 20x 的 extended thinking 这类是 Claude 独占,无法复刻。