Skip to content

OpenClaw 手动配置(Claude Code)

手动编辑配置文件,适合已经熟悉 OpenClaw 基本用法、或者需要精确控制配置内容的用户。

还没装过 OpenClaw?

先运行官方一键安装,再回来配置:

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

你需要有 root 账号权限,如果没有权限可使用 sudo dseditgroup -o edit -a 【用户名】 -t user admin 后在执行安装脚本

配置文件在哪里?

  • macOS / Linux~/.openclaw/openclaw.json
  • WindowsC:\Users\你的用户名\.openclaw\openclaw.json (把 你的用户名 换成你实际的 Windows 登录名,例如 C:\Users\wuwen\.openclaw\openclaw.json

如果文件不存在,先启动一次 OpenClaw 让它自动生成,或者手动创建这个名为openclaw.json的空文件

openclaw.json 完整结构说明

配置文件是一个 JSON 对象,最多有以下 6 个顶层字段。你不需要全部写,按需填写即可。

json
{
  "models": {
    "mode": "merge",
    "providers": {
      "服务商名称": {
        "baseUrl": "API地址",
        "apiKey": "你的密钥",
        "api": "协议类型",
        "models": []
      }
    }
  },
  "agents": {
    "defaults": {
      "model": {
        "primary": "服务商名称/模型id"
      },
      "imageModel": {
        "primary": "服务商名称/模型id"
      }
    }
  },
  "gateway": {
    "mode": "local",
    "port": 18789,
    "auth": {
      "mode": "token",
      "token": "123456"
    }
  },
  "telegram": {
    "enabled": true,
    "botToken": "你的BotToken"
  },
  "memory": {},
  "session": {}
}

顶层字段说明

models — 模型配置(最核心的部分)

  • modemerge 表示和已有配置合并,replace 表示完全替换
  • providers:服务商列表,可以同时配置多个服务商
  • 每个服务商下:
    • baseUrl:API 地址
    • apiKey:你的密钥
    • api:调用协议,Claude 用 anthropic-messages
    • models:该服务商下可用的模型列表

agents — 代理设置

  • defaults.model.primary:默认使用的模型,格式为 服务商名称/模型id
  • defaults.imageModel.primary:图像任务使用的模型(可与 primary 相同)

gateway — 网关设置

  • modelocal 表示本机运行
  • port:访问端口,默认 18789,一般不需要改
  • auth.token:访问令牌,自己设一个字符串

telegram — Telegram 通知(可选)

  • enabledtruefalse
  • botToken:通过 @BotFather 创建获取
  • 不需要此功能可以删掉整个 telegram

memory / session — 记忆与会话配置(可选,留空或不写均可)


配置 ccodezh(Claude 模型按量付费)

购买地址:ccodezh

将以下内容写入(或合并到)你的 openclaw.json

json
{
  "models": {
    "mode": "merge",
    "providers": {
      "ccodezh": {
        "baseUrl": "https://api.ccodezh.com",
        "apiKey": "sk-你的密钥",
        "api": "anthropic-messages",
        "models": [
          {
            "id": "claude-opus-4-6-n",
            "name": "claude-opus-4-6-n",
            "reasoning": true,
            "input": ["text", "image"],
            "cost": { "input": 0, "output": 0, "cacheRead": 0, "cacheWrite": 0 },
            "contextWindow": 200000,
            "maxTokens": 8192
          },
          {
            "id": "claude-sonnet-4-6-n",
            "name": "claude-sonnet-4-6-n",
            "reasoning": true,
            "input": ["text", "image"],
            "cost": { "input": 0, "output": 0, "cacheRead": 0, "cacheWrite": 0 },
            "contextWindow": 200000,
            "maxTokens": 8192
          }
        ]
      }
    }
  },
  "agents": {
    "defaults": {
      "model": { "primary": "ccodezh/claude-opus-4-6-n" },
      "imageModel": { "primary": "ccodezh/claude-opus-4-6-n" }
    }
  },
  "telegram": {
    "enabled": false,
    "botToken": "你的-Telegram-Bot-Token"
  },
  "gateway": {
    "mode": "local",
    "port": 18789,
    "auth": {
      "mode": "token",
      "token": "123456"
    }
  }
}

字段说明:

  • ccodezh:服务商自定义名称,后面引用模型时会用到(格式:ccodezh/claude-opus-4-6-n
  • baseUrlhttps://api.ccodezh.com,注意末尾没有 /v1
  • apiKey:登录 ccodezh 控制台 后复制你的 API Key
  • api:填 anthropic-messages,这是 Claude 系列使用的协议类型
  • models:推荐配置 -n 系列模型,价格更便宜(0.6元 = 1美元)且支持第三方调用
    • 注意:不带 -n 的主渠道模型仅支持在 Claude Code 官方客户端中使用
  • cost:全填 0,按量计费时 OpenClaw 不需要在客户端计算成本
  • telegram.enabled:不需要 Telegram 通知时设为 false,或删掉整个 telegram

写入步骤:

  1. 用文本编辑器打开 openclaw.json
  2. 如果文件为空({}),直接粘贴上面完整内容
  3. 如果文件已有内容,将 providers 下的 ccodezh 块合并进去,并更新 agents.defaults
  4. 保存文件
  5. 重启 gateway(见下方"修改配置后重启生效")

修改配置后重启生效

bash
# macOS / Linux / Windows(CMD)
openclaw gateway stop
openclaw gateway --port 18789

常用命令

  • 启动 Web 服务(含管理界面):
bash
openclaw gateway --port 18789
  • 启动纯 API 网关(不带 Web 界面):
bash
openclaw gateway
  • 关闭 Web 服务:
bash
openclaw gateway stop
  • 清空配置:
bash
openclaw reset
  • 校验配置:
bash
openclaw doctor --fix