# 小ai：OpenClaw 配置手册 - openclaw.json 完全指南

> 本文完整解析 OpenClaw 配置文件 ~/.openclaw/openclaw.json 中全部24个顶层字段的含义、语法与用法，涵盖JSON基础规则、校验机制及典型配置示例，帮助进阶用户快速定位并修复配置问题。

- 来源: https://www.waytoagi.com/kb/ai-agents/openclaw-json-complete-guide
- 飞书原文: https://waytoagi.feishu.cn/wiki/Ew81wgRZxikhCJkDfhycTodsnyc
- 更新于: 2026-10-24

---

> 部署完小龙虾后，一旦出现故障或需要修改配置文件，OpenClaw的配置文件看起来是不是像天书？
>
> 本文档完整梳理了 OpenClaw 配置文件 ~/.openclaw/openclaw.json 中所有24个顶层字段的含义与用法，基于 2026.3.13 版整理。
>
> **目标读者**：OpenClaw 的进阶学习者，想了解 `openclaw.json` 配置文件的语法结构和用法。
>
> **前置条件**：已完成 `openclaw onboard` 初始化

---

## 一、JSON 语法

OpenClaw 的所有配置都存储在 `~/.openclaw/openclaw.json` 中。`openclaw.json` 就是一个 JSON 文件，掌握JSON的语法规则，能避免 90% 的配置错误。

### 1.1 什么是 JSON？

JSON（JavaScript Object Notation）是一种轻量级的数据交换格式，说白了就是一种"**用文字存储结构化数据**"的方式。

### 1.2 JSON 的基本规则

**1. 键值对结构**

JSON 由一个个"键: 值"对组成，用冒号分隔：

```json
{
  "name": "OpenClaw",
  "version": "2026.3.13"
}
```

左边的 `"name"` 是键，右边的 `"OpenClaw"` 是值。

**2. 数据类型**

| 类型 | 写法 | 示例 |
| --- | --- | --- |
| 字符串 | 用双引号包裹 | `"hello"` |
| 数字 | 直接写，不加引号 | `123`, `3.14` |
| 布尔值 | 只有两种 | `true`, `false` |
| 空值 | 表示"没有" | `null` |
| 数组 | 用方括号 | `["a", "b", "c"]` |
| 对象 | 用花括号 | `{"key": "value"}` |

> **注意**：OpenClaw配置文件会先用JSON Schema（一种检验JSON语法的语言）校验一遍，未知键、类型错误或无效值会导致 Gateway 拒绝启动。

当校验失败时：

- Gateway 网关不会启动，症状就是龙虾没反应

- 只有诊断命令可用（`openclaw doctor`、`openclaw logs`、`openclaw health`、`openclaw status`）

- 运行 `openclaw doctor` 以查看具体问题

- 运行 `openclaw doctor --fix`进行修复

**大部分gateway网关没有启动，都跟这个openclaw.json配置错误有关。**

### 1.3 如何验证 JSON 是否正确

如果不确定 JSON 写得对不对，可以用这个**在线工具** [JSONLint](https://jsonlint.com/) 复制进去进行语法检查

![](https://www.waytoagi.com/api/kb-media/SKydbpSUvovPsfxWojRcegvIn9c)

---

## 二、典型`openclaw.json`配置文件

下面以我完成 `openclaw onboard` 初始化后，`openclaw.json`配置文件示例。

```json
{
  "meta": {
    "lastTouchedVersion": "2026.3.13",
    "lastTouchedAt": "2026-03-18T14:11:59.484Z"
  },
  "wizard": {
    "lastRunAt": "2026-03-15T08:07:21.852Z",
    "lastRunVersion": "2026.3.13",
    "lastRunCommand": "onboard",
    "lastRunMode": "local"
  },
  "auth": {
    "profiles": {
      "zai:default": {
        "provider": "zai",
        "mode": "api_key"
      }
    }
  },
  "models": {
    "mode": "merge",
    "providers": {
      "zai": {
        "baseUrl": "https://open.bigmodel.cn/api/coding/paas/v4",
        "api": "openai-completions",
        "models": [
          {
            "id": "glm-5",
            "name": "GLM-5",
            "reasoning": true,
            "input": [
              "text"
            ],
            "cost": {
              "input": 0,
              "output": 0,
              "cacheRead": 0,
              "cacheWrite": 0
            },
            "contextWindow": 204800,
            "maxTokens": 131072
          },
          {
            "id": "glm-4.7",
            "name": "GLM-4.7",
            "reasoning": true,
            "input": [
              "text"
            ],
            "cost": {
              "input": 0,
              "output": 0,
              "cacheRead": 0,
              "cacheWrite": 0
            },
            "contextWindow": 204800,
            "maxTokens": 131072
          },
          {
            "id": "glm-4.7-flash",
            "name": "GLM-4.7 Flash",
            "reasoning": true,
            "input": [
              "text"
            ],
            "cost": {
              "input": 0,
              "output": 0,
              "cacheRead": 0,
              "cacheWrite": 0
            },
            "contextWindow": 204800,
            "maxTokens": 131072
          },
          {
            "id": "glm-4.7-flashx",
            "name": "GLM-4.7 FlashX",
            "reasoning": true,
            "input": [
              "text"
            ],
            "cost": {
              "input": 0,
              "output": 0,
              "cacheRead": 0,
              "cacheWrite": 0
            },
            "contextWindow": 204800,
            "maxTokens": 131072
          }
        ]
      }
    }
  },
  "agents": {
    "defaults": {
      "model": {
        "primary": "zai/glm-5"
      },
      "models": {
        "zai/glm-5": {
          "alias": "GLM"
        },
        "zai/glm-4.7": {}
      },
      "workspace": "~/.openclaw/workspace",
      "compaction": {
        "mode": "safeguard"
      }
    }
  },
  "tools": {
    "profile": "full"
  },
  "commands": {
    "native": "auto",
    "nativeSkills": "auto",
    "restart": true,
    "ownerDisplay": "raw"
  },
  "session": {
    "dmScope": "per-channel-peer"
  },
  "hooks": {
    "internal": {
      "enabled": true,
      "entries": {
        "boot-md": {
          "enabled": true
        },
        "bootstrap-extra-files": {
          "enabled": true
        },
        "command-logger": {
          "enabled": true
        },
        "session-memory": {
          "enabled": true
        }
      }
    }
  },
  "channels": {
    "feishu": {
      "enabled": true,
      "appId": "cli_xxxxxxxxxx",
      "appSecret": "xxxxxxxxxxxxxxxxxxxxxx",
      "domain": "feishu",
      "connectionMode": "websocket",
      "requireMention": true,
      "dmPolicy": "allowlist",
      "groupPolicy": "open",
      "allowFrom": [
        "ou_xxxxxxxxxxxxxxxxxxxxxx"
      ],
      "groupAllowFrom": [],
      "streaming": true,
      "footer": {
        "elapsed": true,
        "status": true
      },
      "threadSession": true
    }
  },
  "gateway": {
    "port": 18789,
    "mode": "local",
    "bind": "loopback",
    "auth": {
      "mode": "token",
      "token": "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
    },
    "tailscale": {
      "mode": "off",
      "resetOnExit": false
    },
    "nodes": {
      "denyCommands": [
        "camera.snap",
        "camera.clip",
        "screen.record",
        "contacts.add",
        "calendar.add",
        "reminders.add",
        "sms.send"
      ]
    }
  },
  "skills": {
    "install": {
      "nodeManager": "npm"
    }
  },
  "plugins": {
    "allow": [
      "openclaw-lark"
    ],
    "entries": {
      "feishu": {
        "enabled": false
      },
      "openclaw-lark": {
        "enabled": true
      }
    },
    "installs": {
      "openclaw-lark": {
        "source": "npm",
        "spec": "@larksuite/openclaw-lark",
        "installPath": "~/.openclaw/extensions/openclaw-lark",
        "version": "2026.3.15",
        "resolvedName": "@larksuite/openclaw-lark",
        "resolvedVersion": "2026.3.15",
        "resolvedSpec": "@larksuite/openclaw-lark@2026.3.15",
        "integrity": "sha512-xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx",
        "shasum": "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx",
        "resolvedAt": "2026-03-15T08:18:48.995Z",
        "installedAt": "2026-03-15T08:19:17.956Z"
      }
    }
  }
}
```

典型的 `openclaw.json` 包含以下顶层字段：

```json
{
  "meta": {},        // 版本信息（自动生成）
  "wizard": {},      // 向导运行记录（自动生成）
  "auth": {},        // 认证配置（API Key 等）
  "models": {},      // 模型提供商和默认模型
  "agents": {},      // Agent 配置（工作区、心跳等）
  "tools": {},       // 工具配置
  "commands": {},    // 命令配置
  "session": {},     // 会话管理
  "hooks": {},       // 钩子（自动化触发器）
  "channels": {},    // 通道配置（飞书、企业微信等）
  "gateway": {},     // 网关设置（端口、认证等）
  "skills": {},      // 技能配置
  "plugins": {}      // 插件配置
}
```

---

## 三、主要配置字段

### 3.1 meta — 版本信息

系统自动维护元数据，一般不需要手动修改。

代码示例：

```json
{
  "meta": {
    "lastTouchedVersion": "2026.3.13",
    "lastTouchedAt": "2026-03-18T14:11:59.484Z"
  }
}
```

字段含义：

| 字段 | 类型 | 说明 |
| --- | --- | --- |
| `meta.lastTouchedVersion` | string | OpenClaw 版本号 |
| `meta.lastTouchedAt` | string | 校验时间 |

---

### 3.2 wizard — 向导运行记录

由 CLI 向导（`onboard`、`configure`、`doctor`）写入的运行记录。

代码示例：

```json
{
  "wizard": {
    "lastRunAt": "2026-03-15T08:07:21.852Z",
    "lastRunVersion": "2026.3.13",
    "lastRunCommit": "abc1234",
    "lastRunCommand": "onboard",
    "lastRunMode": "local"
  }
}
```

字段含义：

| 字段 | 类型 | 说明 |
| --- | --- | --- |
| `wizard.lastRunAt` | string | 最后运行向导的时间 |
| `wizard.lastRunVersion` | string | 运行向导时的 OpenClaw 版本 |
| `wizard.lastRunCommit` | string | Git commit hash |
| `wizard.lastRunCommand` | string | 运行的命令：`onboard` / `configure` / `doctor` |
| `wizard.lastRunMode` | string | 运行模式：`local` / `remote` |

---

### 3.3 auth — 认证配置

存储各模型提供商的认证信息（API Key、OAuth 等）。每个 profile 对应一个提供商的认证方式，系统启动时会读取这些凭据来连接模型服务。

代码示例：

```json
{
  "auth": {
    "profiles": {
      "zai:default": {
        "provider": "zai",
        "mode": "api_key"
      },
      "openrouter:default": {
        "provider": "openrouter",
        "mode": "api_key"
      }
    }
  }
}
```

字段含义：

| 字段 | 类型 | 说明 |
| --- | --- | --- |
| `auth.profiles` | object | 认证 profile 集合，key 为 profile 名称（格式：`provider:label`） |
| `profiles.*.provider` | string | 提供商标识，如 `zai`、`openrouter`、`anthropic` |
| `profiles.*.mode` | string | 认证方式：`api_key`（API密钥）、`oauth`（OAuth授权）、`token`（令牌） |

> **提示**：API Key 通常通过环境变量注入（如 `ZAI_API_KEY`、`OPENROUTER_API_KEY`），不需要明文写在配置文件中。推荐使用 `${ENV_VAR}` 语法引用环境变量。

---

### 3.4 models — 模型提供商和默认模型

定义模型提供商的连接信息（API 地址、协议类型、可用模型列表）以及每个模型的能力参数。`mode` 字段控制自定义提供商与内置目录的合并策略。

代码示例：

```json
{
  "models": {
    "mode": "merge",
    "providers": {
      "zai": {
        "baseUrl": "https://open.bigmodel.cn/api/coding/paas/v4",
        "api": "openai-completions",
        "models": [
          {
            "id": "glm-5",
            "name": "GLM-5",
            "reasoning": true,
            "input": ["text"],
            "cost": {
              "input": 0,
              "output": 0,
              "cacheRead": 0,
              "cacheWrite": 0
            },
            "contextWindow": 204800,
            "maxTokens": 131072
          }
        ]
      }
    }
  }
}
```

字段含义：

| 字段 | 类型 | 说明 |
| --- | --- | --- |
| `models.mode` | string | 提供商目录合并策略：`merge`（合并到内置目录，默认）或 `replace`（完全替换内置目录） |
| `models.providers` | object | 自定义提供商集合，key 为提供商 ID |
| `providers.*.baseUrl` | string | 提供商 API 的基础 URL |
| `providers.*.api` | string | API 协议类型：`openai-completions`、`openai-responses`、`anthropic-messages`、`google-generative-ai` |
| `providers.*.apiKey` | string | API 密钥，推荐用 `${ENV_VAR}` 引用环境变量 |
| `providers.*.models` | array | 该提供商下的模型列表 |
| `models.*.id` | string | 模型 ID，用于 `provider/model` 引用 |
| `models.*.name` | string | 模型显示名称 |
| `models.*.reasoning` | boolean | 是否支持推理/思考模式 |
| `models.*.input` | array | 支持的输入类型：`["text"]`、`["text","image"]` |
| `models.*.cost` | object | 每百万 token 的成本（单位：美元），含 `input`、`output`、`cacheRead`、`cacheWrite` |
| `models.*.contextWindow` | number | 上下文窗口大小（token 数） |
| `models.*.maxTokens` | number | 单次最大输出 token 数 |

---

### 3.5 agents — 智能体配置

控制 Agent 的核心行为：默认模型、工作区路径、心跳频率、上下文压缩策略、子 Agent 并发限制等。分为 `defaults`（全局默认）和 `list`（逐个 Agent 覆盖）两层。

代码示例：

```json
{
  "agents": {
    "defaults": {
      "model": {
        "primary": "zai/glm-5",
        "fallbacks": ["openrouter/xiaomi/mimo-v2-pro"]
      },
      "models": {
        "zai/glm-5": { "alias": "GLM" },
        "openrouter/auto": { "alias": "OpenRouter" }
      },
      "workspace": "~/.openclaw/workspace",
      "compaction": {
        "mode": "safeguard"
      },
      "maxConcurrent": 4,
      "subagents": {
        "maxConcurrent": 8
      },
      "heartbeat": {
        "every": "30m"
      }
    }
  }
}
```

字段含义：

| 字段 | 类型 | 说明 |
| --- | --- | --- |
| `agents.defaults.model` | string/object | 默认模型。字符串形式如 `"zai/glm-5"`；对象形式含 `primary`（主模型）和 `fallbacks`（备用模型数组） |
| `agents.defaults.models` | object | 模型目录及别名配置。key 为 `provider/model`，值含 `alias`（快捷名）和 `params`（参数覆盖） |
| `agents.defaults.workspace` | string | Agent 工作区路径，默认 `~/.openclaw/workspace` |
| `agents.defaults.compaction.mode` | string | 上下文压缩模式：`default`（标准压缩）或 `safeguard`（分块摘要，适合长对话） |
| `agents.defaults.maxConcurrent` | number | 最大并行 Agent 运行数（跨会话），默认 1 |
| `agents.defaults.subagents.maxConcurrent` | number | 最大并行子 Agent 数量 |
| `agents.defaults.heartbeat.every` | string | 心跳间隔，如 `"30m"`、`"1h"`。设为 `"0m"` 禁用 |
| `agents.defaults.userTimezone` | string | 时区设置，如 `"Asia/Shanghai"`。不设则取系统时区 |
| `agents.defaults.timeFormat` | string | 时间格式：`auto`（跟随系统）、`12`（12小时制）、`24`（24小时制） |

---

### 3.6 tools — 工具配置

控制 Agent 可用的工具范围、权限级别和执行参数。通过 `profile`（预设模板）、`allow`（允许列表）、`deny`（禁止列表）三级策略控制工具访问。

代码示例：

```json
{
  "tools": {
    "profile": "full",
    "deny": ["browser", "canvas"],
    "elevated": {
      "enabled": true,
      "allowFrom": {
        "feishu": ["ou_xxxxxxxxxx"]
      }
    },
    "exec": {
      "backgroundMs": 10000,
      "timeoutSec": 1800
    },
    "web": {
      "search": {
        "enabled": true,
        "maxResults": 5
      },
      "fetch": {
        "enabled": true,
        "maxChars": 50000
      }
    }
  }
}
```

字段含义：

| 字段 | 类型 | 说明 |
| --- | --- | --- |
| `tools.profile` | string | 工具预设模板：`minimal`（仅状态查询）、`coding`（编程工具集）、`messaging`（消息工具集）、`full`（全部工具） |
| `tools.allow` | array | 额外允许的工具名列表，支持 `group:xxx` 分组和 `*` 通配符 |
| `tools.deny` | array | 禁止的工具名列表（deny 优先级高于 allow） |
| `tools.elevated.enabled` | boolean | 是否允许提权执行（在宿主机上直接运行命令） |
| `tools.elevated.allowFrom` | object | 按渠道限制可提权的用户，key 为渠道名，value 为用户 ID 数组 |
| `tools.exec.backgroundMs` | number | 后台进程等待超时（毫秒），默认 10000 |
| `tools.exec.timeoutSec` | number | 命令最大执行时间（秒），默认 1800 |
| `tools.web.search.enabled` | boolean | 是否启用网页搜索工具 |
| `tools.web.search.maxResults` | number | 搜索结果最大数量 |
| `tools.web.fetch.enabled` | boolean | 是否启用网页抓取工具 |
| `tools.web.fetch.maxChars` | number | 抓取内容最大字符数 |

---

### 3.7 commands — 命令配置

控制聊天中的斜杠命令（`/new`、`/reset`、`/config` 等）的启用状态和权限。不同渠道对原生命令的支持程度不同。

代码示例：

```json
{
  "commands": {
    "native": "auto",
    "nativeSkills": "auto",
    "restart": true,
    "ownerDisplay": "raw",
    "text": true,
    "bash": false,
    "config": false
  }
}
```

字段含义：

| 字段 | 类型 | 说明 |
| --- | --- | --- |
| `commands.native` | string/boolean | 原生命令注册策略：`auto`（Discord/Telegram 自动注册）、`true`（全部注册）、`false`（不注册） |
| `commands.nativeSkills` | string/boolean | 技能命令注册：`auto`、`true`、`false` |
| `commands.restart` | boolean | 是否允许 `/restart` 命令和网关重启工具 |
| `commands.ownerDisplay` | string | 所有者显示格式：`raw`（原始 ID）或其他格式 |
| `commands.text` | boolean | 是否解析聊天消息中的 `/commands` |
| `commands.bash` | boolean | 是否允许 `!` 快捷执行宿主机命令（需配合 `tools.elevated`） |
| `commands.config` | boolean | 是否允许 `/config` 命令（读写 openclaw.json） |

---

### 3.8 session — 会话管理

控制会话的生命周期、隔离策略和存储管理。决定了不同渠道、不同用户的对话如何分组和归档。

代码示例：

```json
{
  "session": {
    "dmScope": "per-channel-peer",
    "reset": {
      "mode": "daily",
      "atHour": 4
    },
    "maintenance": {
      "mode": "warn",
      "pruneAfter": "30d",
      "maxEntries": 500
    },
    "threadBindings": {
      "enabled": true,
      "idleHours": 24
    }
  }
}
```

字段含义：

| 字段 | 类型 | 说明 |
| --- | --- | --- |
| `session.dmScope` | string | DM 会话分组策略：`main`（所有 DM 共享主会话）、`per-peer`（按发送者隔离）、`per-channel-peer`（按渠道+发送者隔离，推荐）、`per-account-channel-peer`（按账号+渠道+发送者隔离） |
| `session.reset.mode` | string | 会话重置策略：`daily`（每天定时重置）或 `idle`（空闲超时重置） |
| `session.reset.atHour` | number | `daily` 模式下的重置时刻（24小时制），如 4 表示凌晨4点 |
| `session.reset.idleMinutes` | number | `idle` 模式下的空闲分钟数 |
| `session.maintenance.mode` | string | 维护模式：`warn`（仅警告）或 `enforce`（自动清理） |
| `session.maintenance.pruneAfter` | string | 陈旧条目清理阈值，如 `"30d"` |
| `session.maintenance.maxEntries` | number | sessions.json 中的最大条目数，默认 500 |
| `session.threadBindings.enabled` | boolean | 是否启用话题绑定会话功能 |
| `session.threadBindings.idleHours` | number | 话题会话自动取消绑定的空闲小时数，0 表示禁用 |

---

### 3.9 hooks — 钩子（自动化触发器）

事件驱动的自动化系统。内置 4 个钩子：会话记忆保存（`session-memory`）、引导文件注入（`bootstrap-extra-files`）、命令日志（`command-logger`）、启动执行（`boot-md`）。钩子在 Gateway 启动时自动发现和加载。

代码示例：

```json
{
  "hooks": {
    "internal": {
      "enabled": true,
      "entries": {
        "boot-md": {
          "enabled": true
        },
        "session-memory": {
          "enabled": true
        },
        "command-logger": {
          "enabled": true
        }
      }
    }
  }
}
```

字段含义：

| 字段 | 类型 | 说明 |
| --- | --- | --- |
| `hooks.internal.enabled` | boolean | 是否启用内部钩子系统 |
| `hooks.internal.entries` | object | 钩子配置集合，key 为钩子名称 |
| `entries.*.enabled` | boolean | 是否启用该钩子 |

内置钩子说明：

| 钩子名 | 触发事件 | 功能 |
| --- | --- | --- |
| `session-memory` | `/new` 命令 | 将当前会话上下文保存到 `memory/` 目录 |
| `bootstrap-extra-files` | Agent 引导时 | 注入额外的工作区引导文件 |
| `command-logger` | 所有命令 | 记录所有命令事件到 `~/.openclaw/logs/commands.log` |
| `boot-md` | Gateway 启动时 | 执行 `BOOT.md` 中的指令 |

> **提示**：自定义钩子放在 `~/.openclaw/hooks/` 目录下，包含 `HOOK.md`（元数据）和 `handler.ts`（处理逻辑）。系统会自动发现并加载。

---

### 3.10 channels — 渠道配置

连接各种消息平台（飞书、企业微信 等）。每个渠道是一个独立的配置块，包含认证凭据、访问策略和消息行为设置。

代码示例：

```json
{
  "channels": {
    "feishu": {
      "enabled": true,
      "appId": "cli_xxxxxxxxxx",
      "appSecret": "xxxxxxxxxxxxxxxxxxxxxx",
      "domain": "feishu",
      "connectionMode": "websocket",
      "dmPolicy": "pairing",
      "groupPolicy": "open",
      "streaming": true,
      "footer": {
        "elapsed": true,
        "status": true
      },
      "threadSession": true
    }
  }
}
```

字段含义（以飞书为例）：

| 字段 | 类型 | 说明 |
| --- | --- | --- |
| `channels.feishu.enabled` | boolean | 是否启用飞书渠道 |
| `channels.feishu.appId` | string | 飞书应用 App ID（`cli_` 开头） |
| `channels.feishu.appSecret` | string | 飞书应用密钥 |
| `channels.feishu.domain` | string | API 域名：`feishu`（国内）或 `lark`（国际） |
| `channels.feishu.connectionMode` | string | 连接模式：`websocket`（长连接，推荐）或 `webhook`（需公网地址） |
| `channels.feishu.dmPolicy` | string | 私聊策略：`pairing`（配对码，默认）、`allowlist`（白名单）、`open`（开放）、`disabled`（禁用） |
| `channels.feishu.groupPolicy` | string | 群聊策略：`open`（允许所有群）、`allowlist`（仅白名单群）、`disabled`（禁用群消息） |
| `channels.feishu.streaming` | boolean | 是否启用流式卡片输出 |
| `channels.feishu.footer.elapsed` | boolean | 回复底部是否显示耗时 |
| `channels.feishu.footer.status` | boolean | 回复底部是否显示状态信息 |
| `channels.feishu.threadSession` | boolean | 是否启用话题绑定会话 |

---

### 3.11 gateway — 网关服务器配置

OpenClaw 的核心服务器设置。网关是一个多路复用的 HTTP/WebSocket 服务，统一处理所有渠道的消息收发、Agent 通信和 API 调用。

代码示例：

```json
{
  "gateway": {
    "port": 18789,
    "mode": "local",
    "bind": "loopback",
    "auth": {
      "mode": "token",
      "token": "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
    },
    "tailscale": {
      "mode": "off",
      "resetOnExit": false
    },
    "nodes": {
      "denyCommands": [
        "camera.snap",
        "camera.clip",
        "screen.record",
        "contacts.add",
        "calendar.add",
        "reminders.add"
      ]
    }
  }
}
```

字段含义：

| 字段 | 类型 | 说明 |
| --- | --- | --- |
| `gateway.port` | number | 网关监听端口，默认 18789 |
| `gateway.mode` | string | 运行模式：`local`（本地运行）或 `remote`（连接远程网关） |
| `gateway.bind` | string | 绑定地址：`loopback`（仅本机，默认）、`lan`（局域网）、`tailnet`（Tailscale 网络）、`auto` |
| `gateway.auth.mode` | string | 认证方式：`token`（令牌认证）、`password`（密码认证）、`none`（无认证，仅限可信本地） |
| `gateway.auth.token` | string | 认证令牌，建议用 `${ENV_VAR}` 引用环境变量 |
| `gateway.tailscale.mode` | string | Tailscale 集成：`off`（关闭）、`serve`（仅 Tailnet 内网）、`funnel`（公网访问） |
| `gateway.nodes.denyCommands` | array | 禁止 Node 设备执行的命令列表（安全策略） |

> **注意事项**：修改网关配置后**需要重启**：`openclaw gateway restart`

---

### 3.12 skills — 技能配置

技能是可插拔的功能模块（如搜索、日历、代码执行等）。支持从 npm 安装、从本地目录加载，以及逐个启用/禁用。

代码示例：

```json
{
  "skills": {
    "install": {
      "nodeManager": "npm"
    },
    "entries": {
      "openmaic": {
        "enabled": true,
        "config": {
          "accessCode": "sk-xxxxx"
        }
      }
    }
  }
}
```

字段含义：

| 字段 | 类型 | 说明 |
| --- | --- | --- |
| `skills.install.nodeManager` | string | Node 包管理器：`npm`、`pnpm`、`yarn` |
| `skills.install.preferBrew` | boolean | 是否优先使用 Homebrew 安装 |
| `skills.allowBundled` | array | 内置技能白名单（不设则全部可用） |
| `skills.load.extraDirs` | array | 额外的技能加载目录 |
| `skills.entries` | object | 技能配置集合，key 为技能名称 |
| `entries.*.enabled` | boolean | 是否启用该技能 |
| `entries.*.config` | object | 技能自定义配置（由技能自身定义） |
| `entries.*.apiKey` | string/object | 技能 API 密钥，支持明文或 SecretRef |

---

### 3.13 plugins — 插件配置

插件是扩展 OpenClaw 核心功能的高级模块（如新的渠道连接器、记忆系统、上下文引擎等）。插件通常以 npm 包形式安装，运行在 Gateway 进程内。

代码示例：

```json
{
  "plugins": {
    "allow": [
      "openclaw-lark"
    ],
    "entries": {
      "openclaw-lark": {
        "enabled": true
      }
    },
    "installs": {
      "openclaw-lark": {
        "source": "npm",
        "spec": "@larksuite/openclaw-lark",
        "installPath": "~/.openclaw/extensions/openclaw-lark",
        "version": "2026.3.15",
        "resolvedName": "@larksuite/openclaw-lark",
        "resolvedVersion": "2026.3.15"
      }
    }
  }
}
```

字段含义：

| 字段 | 类型 | 说明 |
| --- | --- | --- |
| `plugins.allow` | array | 插件白名单（仅列出的插件会加载） |
| `plugins.deny` | array | 插件黑名单（deny 优先于 allow） |
| `plugins.load.paths` | array | 额外的插件加载路径 |
| `plugins.entries` | object | 插件配置集合，key 为插件 ID |
| `entries.*.enabled` | boolean | 是否启用该插件 |
| `entries.*.config` | object | 插件自定义配置（由插件 schema 校验） |
| `entries.*.apiKey` | string | 插件级 API 密钥 |
| `entries.*.env` | object | 插件专属环境变量 |
| `plugins.installs` | object | CLI 管理的安装元数据（一般由 `openclaw plugins install` 自动维护） |
| `installs.*.source` | string | 安装来源：`npm`、`git`、`local` |
| `installs.*.spec` | string | npm 包标识，如 `@larksuite/openclaw-lark` |
| `installs.*.installPath` | string | 插件安装路径 |
| `installs.*.version` | string | 安装时的版本 |

> **提示**：修改插件配置后需要重启 Gateway 才能生效。常用管理命令：
>
> - `openclaw plugins list` — 查看已安装插件
>
> - `openclaw plugins install <spec>` — 安装插件
>
> - `openclaw plugins update <Plugin id>`  — 更新插件

---

## 四、其他顶层字段——进阶学习

上一章涵盖了 `openclaw.json` 的 13 个核心顶层字段。本章是其他高级功能（如安全加固、日志脱敏等）的配置字段含义，供进阶学习使用，按使用频率排列。

### 4.1 env — 环境变量

定义内联环境变量，供模型 API Key、插件凭据等引用。仅在进程环境缺少对应 key 时生效，不会覆盖已有环境变量。

代码示例：

```json
{
  "env": {
    "OPENROUTER_API_KEY": "sk-or-xxxxx",
    "ZAI_API_KEY": "xxxxx",
    "vars": {
      "GROQ_API_KEY": "gsk-xxxxx"
    },
    "shellEnv": {
      "enabled": true,
      "timeoutMs": 15000
    }
  }
}
```

字段含义：

| 字段 | 类型 | 说明 |
| --- | --- | --- |
| `env.<KEY>` | string | 直接定义环境变量（如 `OPENROUTER_API_KEY`） |
| `env.vars` | object | 环境变量分组（功能同直接定义，仅语义区分） |
| `env.shellEnv.enabled` | boolean | 是否从登录 Shell 的 profile 中导入缺失的环境变量 |
| `env.shellEnv.timeoutMs` | number | Shell 环境导入超时（毫秒） |

> **提示**：环境变量还有两种来源：项目根目录的 `.env` 文件和 `~/.openclaw/.env`。优先级：进程已有变量 > `openclaw.json` 内联 > `.env` 文件。

---

### 4.2 messages — 消息行为配置

控制回复前缀、ACK 反应、消息队列、入站防抖、TTS 等全局消息行为。

代码示例：

```json
{
  "messages": {
    "responsePrefix": "auto",
    "ackReaction": "👀",
    "ackReactionScope": "group-mentions",
    "removeAckAfterReply": false,
    "queue": {
      "mode": "collect",
      "debounceMs": 1000,
      "cap": 20
    },
    "inbound": {
      "debounceMs": 2000
    }
  }
}

```

字段含义：

| 字段 | 类型 | 说明 |
| --- | --- | --- |
| `messages.responsePrefix` | string | 回复前缀：`"auto"`（自动用 Agent 名称/emoji）、固定字符串、或 `""`（禁用） |
| `messages.ackReaction` | string | 收到消息后的 ACK 表情反应，默认取 Agent 的 `identity.emoji`，否则 `"👀"` |
| `messages.ackReactionScope` | string | ACK 范围：`group-mentions`（仅群@，默认）、`group-all`（所有群消息）、`direct`（私聊）、`all`（全部） |
| `messages.removeAckAfterReply` | boolean | 回复完成后是否移除 ACK 反应 |
| `messages.queue.mode` | string | 消息队列策略：`collect`（合并为一条）、`steer`（插队）、`interrupt`（中断当前回复） |
| `messages.queue.debounceMs` | number | 队列防抖间隔（毫秒） |
| `messages.queue.cap` | number | 队列最大容量 |
| `messages.inbound.debounceMs` | number | 入站消息防抖（毫秒），将同一发送者的连续文本合并为一次 Agent 调用。0 禁用 |

---

### 4.3 bindings — 多 Agent 路由

将不同渠道、不同用户或群组的消息路由到不同的 Agent。适用于一个 Gateway 管理多个 Agent 的场景，即龙虾团队模式。

代码示例：

```json
{
  "bindings": [
    {
      "agentId": "home",
      "match": {
        "channel": "feishu",
        "peer": { "kind": "direct", "id": "ou_xxx" }
      }
    },
    {
      "agentId": "work",
      "match": {
        "channel": "feishu",
        "peer": { "kind": "group", "id": "oc_yyy" }
      }
    }
  ]
}
```

字段含义：

| 字段 | 类型 | 说明 |
| --- | --- | --- |
| `bindings[].agentId` | string | 目标 Agent ID（需在 `agents.list` 中定义） |
| `bindings[].match.channel` | string | 渠道名：`feishu`、`telegram`、`discord` 等 |
| `bindings[].match.peer.kind` | string | 对话类型：`direct`（私聊）或 `group`（群聊） |
| `bindings[].match.peer.id` | string | 用户 open_id（`ou_xxx`）或群组 ID（`oc_xxx`） |
| `bindings[].match.accountId` | string | 多账号场景下的账号 ID（可选） |

---

### 4.4 logging — 日志配置

控制系统日志的级别、输出位置和格式。

代码示例：

```json
{
  "logging": {
    "level": "info",
    "file": "/tmp/openclaw/openclaw.log",
    "consoleLevel": "info",
    "consoleStyle": "pretty",
    "redactSensitive": "tools"
  }
}
```

字段含义：

| 字段 | 类型 | 说明 |
| --- | --- | --- |
| `logging.level` | string | 日志级别：`debug`、`info`（默认）、`warn`、`error` |
| `logging.file` | string | 日志文件路径。不设则默认 `/tmp/openclaw/openclaw-YYYY-MM-DD.log` |
| `logging.consoleLevel` | string | 控制台日志级别，`--verbose` 时自动提升为 `debug` |
| `logging.consoleStyle` | string | 控制台样式：`pretty`（美化）、`compact`（紧凑）、`json` |
| `logging.redactSensitive` | string | 敏感信息脱敏：`off`（不脱敏）、`tools`（脱敏工具调用中的敏感内容） |

---

### 4.5 browser — 浏览器配置

控制 OpenClaw 内置浏览器的行为，用于 Agent 的网页浏览和自动化操作。

代码示例：

```json
{
  "browser": {
    "enabled": true,
    "evaluateEnabled": true,
    "defaultProfile": "openclaw",
    "profiles": {
      "openclaw": { "cdpPort": 18800 },
      "user": { "cdpPort": 18801 }
    }
  }
}
```

字段含义：

| 字段 | 类型 | 说明 |
| --- | --- | --- |
| `browser.enabled` | boolean | 是否启用浏览器工具 |
| `browser.evaluateEnabled` | boolean | 是否允许 `act:evaluate` 和 `wait --fn` 操作 |
| `browser.defaultProfile` | string | 默认浏览器配置：`openclaw`（隔离浏览器）、`user`（用户浏览器） |
| `browser.profiles` | object | 浏览器配置集合，key 为配置名 |
| `profiles.*.cdpPort` | number | CDP 调试端口 |
| `browser.color` | string | 浏览器标识颜色（多配置区分用） |

---

### 4.6 discovery — 网络发现配置

控制 mDNS（局域网设备发现）和 DNS-SD（广域网服务发现）。

代码示例：

```json
{
  "discovery": {
    "mdns": {
      "mode": "minimal"
    },
    "wideArea": {
      "enabled": false
    }
  }
}
```

字段含义：

| 字段 | 类型 | 说明 |
| --- | --- | --- |
| `discovery.mdns.mode` | string | mDNS 模式：`minimal`（默认，不暴露 CLI 路径和 SSH 端口）、`full`（完整信息）、`off`（关闭） |
| `discovery.wideArea.enabled` | boolean | 是否启用 DNS-SD 广域网发现 |

---

### 4.7 cron — 定时任务配置

控制定时任务（Cron Jobs）的并发限制、会话保留和运行日志。

代码示例：

```json
{
  "cron": {
    "enabled": true,
    "maxConcurrentRuns": 2,
    "sessionRetention": "24h",
    "runLog": {
      "maxBytes": "2mb",
      "keepLines": 2000
    }
  }
}
```

字段含义：

| 字段 | 类型 | 说明 |
| --- | --- | --- |
| `cron.enabled` | boolean | 是否启用定时任务系统 |
| `cron.maxConcurrentRuns` | number | 最大并行定时任务数，默认 2 |
| `cron.sessionRetention` | string | 完成的定时任务会话保留时长，如 `"24h"`。设 `false` 禁用清理 |
| `cron.runLog.maxBytes` | string | 单个运行日志文件最大大小，默认 `2mb` |
| `cron.runLog.keepLines` | number | 日志裁剪时保留的最新行数，默认 2000 |

---

### 4.8 secrets — 密钥管理配置

配置密钥提供程序，支持从环境变量、文件或外部命令获取敏感凭据。

代码示例：

```json
{
  "secrets": {
    "providers": {
      "default": { "source": "env" },
      "filemain": {
        "source": "file",
        "path": "~/.openclaw/secrets.json",
        "mode": "json"
      }
    },
    "defaults": {
      "env": "default",
      "file": "filemain"
    }
  }
}
```

字段含义：

| 字段 | 类型 | 说明 |
| --- | --- | --- |
| `secrets.providers` | object | 密钥提供程序集合 |
| `providers.*.source` | string | 来源类型：`env`（环境变量）、`file`（文件）、`exec`（外部命令） |
| `providers.*.path` | string | `file` 类型的文件路径 |
| `providers.*.mode` | string | `file` 的读取模式：`json`（JSON 解析）或 `singleValue` |
| `providers.*.command` | string | `exec` 类型的命令路径（必须为绝对路径） |
| `secrets.defaults` | object | 各来源类型的默认提供程序 |

---

### 4.9 ui — 界面外观配置

控制原生应用界面的配色和 Agent 身份显示。

代码示例：

```json
{
  "ui": {
    "seamColor": "#FF4500",
    "assistant": {
      "name": "皮皮虾",
      "emoji": "🦐"
    }
  }
}
```

字段含义：

| 字段 | 类型 | 说明 |
| --- | --- | --- |
| `ui.seamColor` | string | 界面主题色（Talk Mode 气泡等） |
| `ui.assistant.name` | string | 界面中显示的助手名称 |
| `ui.assistant.avatar` | string | 助手头像：emoji、短文本、图片 URL 或 data URI |

---

### 4.10 canvasHost — 画布服务配置

控制 Agent 可编辑的 HTML/JS 画布的 HTTP 服务。

代码示例：

```json
{
  "canvasHost": {
    "root": "~/.openclaw/workspace/canvas",
    "liveReload": true
  }
}
```

字段含义：

| 字段 | 类型 | 说明 |
| --- | --- | --- |
| `canvasHost.root` | string | 画布文件根目录 |
| `canvasHost.liveReload` | boolean | 是否启用实时重载 |

---

### 4.11 talk — 语音对话配置

macOS/iOS/Android 语音对话模式的默认设置，控制 TTS 语音、静默超时和打断行为。

代码示例：

```json
{
  "talk": {
    "voiceId": "elevenlabs_voice_id",
    "modelId": "eleven_v3",
    "outputFormat": "mp3_44100_128",
    "silenceTimeoutMs": 1500,
    "interruptOnSpeech": true
  }
}
```

字段含义：

| 字段 | 类型 | 说明 |
| --- | --- | --- |
| `talk.voiceId` | string | ElevenLabs 语音 ID |
| `talk.voiceAliases` | object | 语音别名映射，如 `{"Clawd": "EXAVITQu4vr..."}` |
| `talk.modelId` | string | TTS 模型 ID |
| `talk.outputFormat` | string | 输出音频格式 |
| `talk.silenceTimeoutMs` | number | 用户静默后发送转录的等待时间（毫秒） |
| `talk.interruptOnSpeech` | boolean | 用户说话时是否打断当前播放 |

---

## 参考资料

1. OpenClaw 官方文档 https://docs.openclaw.ai

2. OpenClaw GitHub 仓库 https://github.com/openclaw/openclaw
