OpenClaw Config
Overview
Safely edit ~/.openclaw/openclaw.json (or the path set by OPENCLAW_CONFIG_PATH) using a schema-first workflow. Validate before and after changes to avoid invalid keys/types that can break startup or change security behavior.
Workflow (Safe Edit)
- 1. Identify the active config path
- - Precedence:
OPENCLAW_CONFIG_PATH > OPENCLAW_STATE_DIR/openclaw.json > INLINECODE4 - The config file is JSON5 (comments + trailing commas allowed).
- 2. Get an authoritative schema (do not guess keys)
- - If the Gateway is running: use
openclaw gateway call config.schema --params '{}' to fetch a JSON Schema matching the running version. - Otherwise: use
openclaw/openclaw source-of-truth, primarily:
-
src/config/zod-schema.ts (
OpenClawSchema root keys like
gateway/
skills/
plugins)
-
src/config/zod-schema.*.ts (submodules: channels/providers/models/agents/tools)
-
docs/gateway/configuration.md (repo docs + examples)
- 3. Apply changes with the smallest safe surface
- - Prefer small edits:
openclaw config get|set|unset (dot path or bracket notation). - If the Gateway is online and you want "write + validate + restart" in one step: use RPC
config.patch (merge patch) or config.apply (replaces the entire config; use carefully). - For complex setups, split config with
$include (see below).
- 4. Validate strictly
- - Run
openclaw doctor, then fix issues using the reported path + message. - Do not run
openclaw doctor --fix/--yes without explicit user consent (it writes to config/state files).
Guardrails (Avoid Schema Bugs)
- - Most objects are strict (
.strict()): unknown keys usually fail validation and the Gateway will refuse to start. - INLINECODE23 is
.passthrough(): extension channels (matrix/zalo/nostr, etc.) can add custom keys, but most provider configs remain strict. - INLINECODE25 is
.catchall(z.string()): you can put string env vars directly under env, and you can also use env.vars. - Secrets: prefer environment variables/credential files. Avoid committing long-lived tokens/API keys into
openclaw.json.
$include (Modular Config)
INLINECODE30 is resolved before schema validation and lets you split config across JSON5 files:
- - Supports
"$include": "./base.json5" or INLINECODE32 - Relative paths are resolved against the directory of the current config file.
- Deep-merge rules (per implementation):
- objects: merge recursively
- arrays:
concatenate (not replace)
- primitives: later value wins
- - If sibling keys exist alongside
$include, sibling keys override included values. - Limits: max depth 10; circular includes are detected and rejected.
Common Recipes (Examples)
- 1. Set default workspace
CODEBLOCK0
- 2. Change Gateway port
CODEBLOCK1
- 3. Split config (example)
CODEBLOCK2
- 4. Telegram open DMs (must explicitly allow senders)
Schema constraint: when dmPolicy="open", allowFrom must include "*".
CODEBLOCK3
- 5. Discord token (config or env fallback)
CODEBLOCK4
- 6. Enable web_search (Brave / Perplexity)
CODEBLOCK5
Resources
Load these when you need a field index or source locations:
- -
references/openclaw-config-fields.md (root key index + key field lists with sources) - INLINECODE38 (how to locate schema + constraints in openclaw repo)
- INLINECODE39 (print config path + run doctor)
OpenClaw Config
概述
使用模式优先的工作流安全编辑 ~/.openclaw/openclaw.json(或由 OPENCLAWCONFIGPATH 设置的路径)。在变更前后进行验证,以避免可能导致启动失败或改变安全行为的无效键/类型。
工作流(安全编辑)
- 1. 确定当前配置路径
- - 优先级:OPENCLAWCONFIGPATH > OPENCLAWSTATEDIR/openclaw.json > ~/.openclaw/openclaw.json
- 配置文件为 JSON5 格式(允许注释和尾随逗号)。
- 2. 获取权威模式(不要猜测键)
- - 如果网关正在运行:使用 openclaw gateway call config.schema --params {} 获取与当前运行版本匹配的 JSON Schema。
- 否则:使用 openclaw/openclaw 权威来源,主要包括:
- src/config/zod-schema.ts(OpenClawSchema 根键,如 gateway/skills/plugins)
- src/config/zod-schema.*.ts(子模块:channels/providers/models/agents/tools)
- docs/gateway/configuration.md(仓库文档 + 示例)
- 3. 以最小安全范围应用变更
- - 优先使用小范围编辑:openclaw config get|set|unset(点路径或括号表示法)。
- 如果网关在线且希望一步完成写入 + 验证 + 重启:使用 RPC config.patch(合并补丁)或 config.apply(替换整个配置;请谨慎使用)。
- 对于复杂配置,使用 $include 拆分配置(见下文)。
- 4. 严格验证
- - 运行 openclaw doctor,然后根据报告的 path + message 修复问题。
- 未经用户明确同意,不要运行 openclaw doctor --fix/--yes(它会写入配置/状态文件)。
防护措施(避免模式错误)
- - 大多数对象是严格的(.strict()):未知键通常会验证失败,网关将拒绝启动。
- channels 是 .passthrough():扩展频道(matrix/zalo/nostr 等)可以添加自定义键,但大多数提供者配置仍然是严格的。
- env 是 .catchall(z.string()):可以直接在 env 下放置字符串环境变量,也可以使用 env.vars。
- 密钥:优先使用环境变量/凭证文件。避免将长期有效的令牌/API 密钥提交到 openclaw.json 中。
$include(模块化配置)
$include 在模式验证之前解析,允许将配置拆分到多个 JSON5 文件中:
- - 支持 $include: ./base.json5 或 $include: [./a.json5, ./b.json5]
- 相对路径基于当前配置文件所在目录解析。
- 深度合并规则(按实现方式):
- 对象:递归合并
- 数组:
拼接(不替换)
- 基本类型:后值优先
- - 如果 $include 旁边存在同级键,则同级键会覆盖包含的值。
- 限制:最大深度为 10;循环包含会被检测并拒绝。
常用方案(示例)
- 1. 设置默认工作空间
bash
openclaw config set agents.defaults.workspace ~/.openclaw/workspace --json
openclaw doctor
- 2. 更改网关端口
bash
openclaw config set gateway.port 18789 --json
openclaw doctor
- 3. 拆分配置(示例)
json5
// ~/.openclaw/openclaw.json
{
$include: [./gateway.json5, ./channels/telegram.json5],
}
- 4. Telegram 开放私信(必须明确允许发送者)
模式约束:当 dmPolicy=open 时,allowFrom 必须包含 *。
bash
openclaw config set channels.telegram.dmPolicy open --json
openclaw config set channels.telegram.allowFrom [*] --json
openclaw doctor
- 5. Discord 令牌(配置或环境变量回退)
bash
选项 A:写入配置
openclaw config set channels.discord.token YOUR
DISCORDBOT_TOKEN --json
选项 B:环境变量回退(仍建议存在 channels.discord 部分)
export DISCORDBOTTOKEN=...
openclaw doctor
- 6. 启用网络搜索(Brave / Perplexity)
bash
openclaw config set tools.web.search.enabled true --json
openclaw config set tools.web.search.provider brave --json
建议:通过环境变量提供密钥(或写入 tools.web.search.apiKey)
export BRAVEAPIKEY=...
openclaw doctor
资源
当需要字段索引或源代码位置时,请加载以下内容:
- - references/openclaw-config-fields.md(根键索引 + 带来源的键字段列表)
- references/schema-sources.md(如何在 openclaw 仓库中定位模式和约束)
- scripts/openclaw-config-check.sh(打印配置路径并运行 doctor)