openclaw config

openclaw config 是对 openclaw.json 进行非交互式读写的核心命令。不带子命令时等同于打开 openclaw configure 向导。

常用子命令

openclaw config file              # 打印当前配置文件路径
openclaw config schema            # 输出 JSON Schema
openclaw config validate          # 校验配置合法性
openclaw config get <path>        # 读取指定路径的值
openclaw config set <path> <val>  # 写入指定路径的值
openclaw config unset <path>      # 删除指定路径
openclaw config patch --file ./patch.json5  # 批量合并补丁

路径语法

使用点号或方括号表示法:

openclaw config get agents.defaults.workspace
openclaw config get agents.list[0].id
openclaw config set agents.list[1].tools.exec.node "node-id"

值解析规则

  • 默认按 JSON5 解析,失败则当字符串处理
  • --strict-json:强制 JSON5 解析
  • --merge:向受保护的 map/list 路径追加条目(如 agents.defaults.models、plugins.entries)
  • --replace:强制整体替换目标路径
openclaw config set agents.defaults.models '{"openai/gpt-5.4":{}}' --strict-json --merge

config set 四种模式

模式说明
Value mode直接赋值
SecretRef builder--ref-provider / --ref-source / --ref-id 写入密钥引用
Provider builder目标必须是 secrets.providers.<alias>
Batch mode--batch-json 或 --batch-file 批量操作

SecretRef 示例:

openclaw config set channels.discord.token \
  --ref-provider default --ref-source env --ref-id DISCORD_BOT_TOKEN

config patch

接受 JSON5 对象,对象递归合并,数组/标量替换,null 删除路径:

openclaw config patch --file ./openclaw.patch.json5 --dry-run
openclaw config patch --file ./openclaw.patch.json5
# 通过 stdin 远程推送
ssh openclaw-host 'openclaw config patch --stdin' < ./openclaw.patch.json5

Dry Run

--dry-run 验证变更但不写盘,--allow-exec 允许 exec 类 SecretRef 在 dry-run 中执行:

openclaw config set channels.discord.token \
  --ref-provider default --ref-source env --ref-id DISCORD_BOT_TOKEN --dry-run

Nix 模式

OPENCLAW_NIX_MODE=1 时 openclaw.json 不可变,写操作被拒绝,只读命令(get、file、schema、validate)仍可用。

写安全

写入前会对完整配置做 schema 校验;校验失败时原配置不变,被拒绝的 payload 保存为 openclaw.json.rejected.*。

相关链接