Appearance
openclaw config
非交互式编辑 openclaw.json 的配置助手,支持 get/set/unset/file/schema/validate 操作,可通过路径读写任意配置项并打印当前配置文件路径。不带子命令直接运行时,会打开配置向导(等同于 openclaw configure)。
示例
bash
openclaw config file
openclaw config schema
openclaw config get browser.executablePath
openclaw config set browser.executablePath "/usr/bin/google-chrome"
openclaw config set agents.defaults.heartbeat.every "2h"
openclaw config set agents.list[0].tools.exec.node "node-id-or-name"
openclaw config set channels.discord.token --ref-provider default --ref-source env --ref-id DISCORD_BOT_TOKEN
openclaw config set secrets.providers.vaultfile --provider-source file --provider-path /etc/openclaw/secrets.json --provider-mode json
openclaw config unset plugins.entries.brave.config.webSearch.apiKey
openclaw config set channels.discord.token --ref-provider default --ref-source env --ref-id DISCORD_BOT_TOKEN --dry-run
openclaw config validate
openclaw config validate --jsonconfig schema
将 openclaw.json 的 JSON Schema 打印到标准输出(纯文本)。
bash
openclaw config schema如需用其他工具检查或验证,可导出到文件:
bash
openclaw config schema > openclaw.schema.json路径格式
路径使用点号或括号表示法:
bash
openclaw config get agents.defaults.workspace
openclaw config get agents.list[0].id用 agents 列表的索引定位具体的 agent:
bash
openclaw config get agents.list
openclaw config set agents.list[1].tools.exec.node "node-id-or-name"值解析
值会优先按 JSON5 解析,失败时作为字符串处理。使用 --strict-json 强制要求 JSON5 解析。--json 作为旧版别名仍然支持。
bash
openclaw config set agents.defaults.heartbeat.every "0m"
openclaw config set gateway.port 19001 --strict-json
openclaw config set channels.whatsapp.groups '["*"]' --strict-jsonconfig set 的四种模式
openclaw config set 支持四种写入方式:
值模式:
openclaw config set <path> <value>SecretRef 构建器模式:
bash
openclaw config set channels.discord.token \
--ref-provider default \
--ref-source env \
--ref-id DISCORD_BOT_TOKEN- Provider 构建器模式(仅限
secrets.providers.<alias>路径):
bash
openclaw config set secrets.providers.vault \
--provider-source exec \
--provider-command /usr/local/bin/openclaw-vault \
--provider-arg read \
--provider-arg openai/api-key \
--provider-timeout-ms 5000- 批量模式(
--batch-json或--batch-file):
bash
openclaw config set --batch-json '[
{
"path": "secrets.providers.default",
"provider": { "source": "env" }
},
{
"path": "channels.discord.token",
"ref": { "source": "env", "provider": "default", "id": "DISCORD_BOT_TOKEN" }
}
]'bash
openclaw config set --batch-file ./config-set.batch.json --dry-run批量解析始终以批量载荷(--batch-json/--batch-file)为准,--strict-json/--json 不影响批量解析行为。
JSON 路径/值模式对 SecretRef 和 provider 同样适用:
bash
openclaw config set channels.discord.token \
'{"source":"env","provider":"default","id":"DISCORD_BOT_TOKEN"}' \
--strict-json
openclaw config set secrets.providers.vaultfile \
'{"source":"file","path":"/etc/openclaw/secrets.json","mode":"json"}' \
--strict-jsonProvider 构建器标志
Provider 构建器的目标路径必须是 secrets.providers.<alias>。
通用标志:
--provider-source <env|file|exec>--provider-timeout-ms <ms>(file、exec)
Env provider(--provider-source env):
--provider-allowlist <ENV_VAR>(可重复)
File provider(--provider-source file):
--provider-path <path>(必填)--provider-mode <singleValue|json>--provider-max-bytes <bytes>
Exec provider(--provider-source exec):
--provider-command <path>(必填)--provider-arg <arg>(可重复)--provider-no-output-timeout-ms <ms>--provider-max-output-bytes <bytes>--provider-json-only--provider-env <KEY=VALUE>(可重复)--provider-pass-env <ENV_VAR>(可重复)--provider-trusted-dir <path>(可重复)--provider-allow-insecure-path--provider-allow-symlink-command
加固版 exec provider 示例:
bash
openclaw config set secrets.providers.vault \
--provider-source exec \
--provider-command /usr/local/bin/openclaw-vault \
--provider-arg read \
--provider-arg openai/api-key \
--provider-json-only \
--provider-pass-env VAULT_TOKEN \
--provider-trusted-dir /usr/local/bin \
--provider-timeout-ms 5000Dry run(预演模式)
使用 --dry-run 可以验证改动而不实际写入 openclaw.json。
bash
openclaw config set channels.discord.token \
--ref-provider default \
--ref-source env \
--ref-id DISCORD_BOT_TOKEN \
--dry-run
openclaw config set channels.discord.token \
--ref-provider default \
--ref-source env \
--ref-id DISCORD_BOT_TOKEN \
--dry-run \
--json
openclaw config set channels.discord.token \
--ref-provider vault \
--ref-source exec \
--ref-id discord/token \
--dry-run \
--allow-execDry-run 行为说明:
- 构建器模式:对变更的 ref/provider 执行 SecretRef 可解析性检查。
- JSON 模式(
--strict-json、--json或批量模式):执行 schema 验证 + SecretRef 可解析性检查。 - exec SecretRef 检查默认跳过,以避免命令副作用。
- 用
--allow-exec加上--dry-run可开启 exec SecretRef 检查(此时可能实际执行 provider 命令)。 --allow-exec仅在 dry-run 下有效,单独使用会报错。
--dry-run --json 输出机器可读报告,包含以下字段:
ok:dry-run 是否通过operations:评估的赋值数量checks:schema/可解析性检查是否执行checks.resolvabilityComplete:可解析性检查是否全部完成(跳过 exec ref 时为 false)refsChecked:dry-run 期间实际解析的 ref 数量skippedExecRefs:因未设置--allow-exec而跳过的 exec ref 数量errors:当ok=false时返回的 schema/可解析性错误结构
JSON 输出结构
json5
{
ok: boolean,
operations: number,
configPath: string,
inputModes: ["value" | "json" | "builder", ...],
checks: {
schema: boolean,
resolvability: boolean,
resolvabilityComplete: boolean,
},
refsChecked: number,
skippedExecRefs: number,
errors?: [
{
kind: "schema" | "resolvability",
message: string,
ref?: string, // 可解析性错误时存在
},
],
}成功示例:
json
{
"ok": true,
"operations": 1,
"configPath": "~/.openclaw/openclaw.json",
"inputModes": ["builder"],
"checks": {
"schema": false,
"resolvability": true,
"resolvabilityComplete": true
},
"refsChecked": 1,
"skippedExecRefs": 0
}失败示例:
json
{
"ok": false,
"operations": 1,
"configPath": "~/.openclaw/openclaw.json",
"inputModes": ["builder"],
"checks": {
"schema": false,
"resolvability": true,
"resolvabilityComplete": true
},
"refsChecked": 1,
"skippedExecRefs": 0,
"errors": [
{
"kind": "resolvability",
"message": "Error: Environment variable \"MISSING_TEST_SECRET\" is not set.",
"ref": "env:default:MISSING_TEST_SECRET"
}
]
}dry-run 失败时的常见错误:
config schema validation failed:修改后的配置结构不合法,请检查路径/值或 provider/ref 对象格式。SecretRef assignment(s) could not be resolved:引用的 provider/ref 当前无法解析(环境变量缺失、文件路径无效、exec provider 异常、provider/source 不匹配)。Dry run note: skipped <n> exec SecretRef resolvability check(s):跳过了 exec ref 检查,如需验证请加--allow-exec重跑。- 批量模式下,修复失败条目后重跑
--dry-run再正式写入。
子命令
config file:打印当前配置文件的路径(从OPENCLAW_CONFIG_PATH或默认位置解析)。
编辑后需重启 Gateway 才能生效——这只是"喂我的龙虾新配置",不会自动热重载。
验证(Validate)
在不启动 Gateway 的情况下,根据当前 schema 验证配置是否合法。
bash
openclaw config validate
openclaw config validate --json