安装 Claude Code 并配置智谱z.ai GLM
智谱相关
- 智谱网址 https://z.ai
- 注册, 登录, 点右上角API前往国际站
- 查看套餐和消耗量 https://z.ai/manage-apikey/subscription
- 管理API Key https://z.ai/manage-apikey/apikey-list
- 工具接入文档 https://docs.bigmodel.cn/cn/coding-plan/overview
- 工具接入文档(EN) https://docs.z.ai/devpack/overview
套餐用量
| 每 5 小时限额 | 每周限额 | |
|---|---|---|
| Lite 套餐 | 最多约 80 次 prompts(35M token) | 最多约 320 次 prompts(140M token) |
| Pro 套餐 | 最多约 400 次 prompts | 最多约 1600 次 prompts |
| Max 套餐 | 最多约 1600 次 prompts | 最多约 6400 次 prompts |
Lite现在还只有GLM4.7, 不能用GLM5, 日常开发Lite基本够用, 如果要整个项目重构这种不行.
对比 MiniMax 的套餐, MiniMax 的Starter也可以用最新的 MiniMax2.5, 但是配额比较少
- Starter: 40 prompts / 每 5 小时
- Plus: 100 prompts / 每 5 小时
Claude Code 相关
Ubuntu 24.04 安装
- 安装
curl -fsSL https://claude.ai/install.sh | bash也可以将install.sh下载后安装bash bootstrap.sh(下载下来的是 bootstrap.sh) - 网络原因, 安装如果不成功多试几次
在 Ubuntu24.04 中安装完成后, 会报.bashrc 中, 没有将 .local/bin 添加到 PATH, 这个可以不用理会, Ubuntu24.04 中 .profile 中带这个PATH, 退出登录再进来就可以看到claude了.
Win10 安装
在命令行下
npm install -g @anthropic-ai/claude-code@latest --registry=https://registry.npmmirror.com
Windows 下最好安装 Windows Terminal, 如果执行 claude 的时候出现错误: ps1 cannot be loaded because running scripts is disabled on this system, 可以用管理员在Power Shell 或者 Windows Terminal 中执行
Set-ExecutionPolicy -Scope CurrentUser -ExecutionPolicy RemoteSigned
# or
Set-ExecutionPolicy -Scope LocalMachine -ExecutionPolicy RemoteSigned
配置
配置要参考中文页面上的说明: https://docs.bigmodel.cn/cn/coding-plan/tool/claude, 避免 claude 启动后去访问官网然后报网络错误. 选手动配置,
# 编辑或新增 `settings.json` 文件
# MacOS & Linux 为 `~/.claude/settings.json`
# Windows 为`用户目录/.claude/settings.json`
# 新增或修改里面的 env 字段
# 注意替换里面的 `your_zhipu_api_key` 为您上一步获取到的 API Key
{
"env": {
"ANTHROPIC_AUTH_TOKEN": "your_zhipu_api_key",
"ANTHROPIC_BASE_URL": "https://open.bigmodel.cn/api/anthropic",
"API_TIMEOUT_MS": "3000000",
"CLAUDE_CODE_DISABLE_NONESSENTIAL_TRAFFIC": 1
}
}
# 再编辑或新增 `.claude.json` 文件
# MacOS & Linux 为 `~/.claude.json`
# Windows 为`用户目录/.claude.json`
# 新增 `hasCompletedOnboarding` 参数
{
"hasCompletedOnboarding": true
}
claude 可以正常启动后, 就可以开始安装智谱的几个MCP, 图片解析用的是模型配额, 后面三个是工具配额, 基础套餐每月只有100次调用
- 图片解析 https://docs.bigmodel.cn/cn/coding-plan/mcp/vision-mcp-server
- 联网搜索 https://docs.bigmodel.cn/cn/coding-plan/mcp/search-mcp-server
- 网页读取 https://docs.bigmodel.cn/cn/coding-plan/mcp/reader-mcp-server
- GitHub解析 https://docs.bigmodel.cn/cn/coding-plan/mcp/zread-mcp-server
在 claude 命令行中, 可以通过 /mcp查看这些mcp的状态
配置文件
https://code.claude.com/docs/en/settings
- 用户全局设置 ~/.claude/settings.json
- 项目设置 project_folder/.claude/settings.json
- 项目设置(用户本地) .claude/settings.local.json . Claude Code 会设置 gitignore 这个文件
在当前工作目录之外, 再包含其它路径
{
"permissions": {
"additionalDirectories": ["../docs/", "../shared/"]
}
}
使用
基于第三方接口文档创建代码
将第三方接口文档转为 markdown 格式, 如果文档为网页, 可以通过 html2md(下载地址), 命令为
# 输入 api1.html, 输出 api1.md, -T表示带表格转换
html2md -T -i api1.html > api1.md
# 从网址读取, 仅提取 body > article 下的内容
html2md -T -i https://help.ishumei.com/docs/tj/image/versionV4/batchSync/developDoc -s "body article" > api3.md
在 Claude Code 中提示模型去创建接口工具类和对应的对象, 提示词
# 1
read the file api1.md in input folder, and generate the API utility class and request and response pojo in folder project-lib/src/main/java/com/project/server/lib/shumei
# 2
I have added another 5 api docs (api2.md ~ api6.md), please generate the API utility class and request and response pojo respectively and put them to sub folder accordingly
浙公网安备 33010602011771号