配置文件详解
OpenClaw 的所有行为——用哪个模型、连哪些渠道、多久心跳一次——都由一个 JSON5 配置文件控制。本附录逐项解读每个配置块,帮你理解"这个字段是干什么的"以及"什么时候需要改它"。
不想手写配置? 推荐使用 OpenClaw 配置生成器 可视化生成配置,再对照本附录微调。
配置文件位置
~/.openclaw/openclaw.json # 主配置文件(JSON5 格式)
~/.openclaw/.env # 环境变量文件(存放 API Key 等)
配置文件不存在也能运行——OpenClaw 会使用安全默认值。可以通过 openclaw config file 确认实际路径。
配置文件整体结构
{
agents: { ... }, // 智能体:模型、工作区、心跳
channels: { ... }, // 渠道:Telegram / QQ / 飞书等
gateway: { ... }, // 网关:端口、认证、热重载
session: { ... }, // 会话:隔离策略、自动重置
messages: { ... }, // 消息:群聊提及规则
tools: { ... }, // 工具:启用级别、搜索配置
skills: { ... }, // 技能:启用与凭证
cron: { ... }, // 定时任务:并发、日志
hooks: { ... }, // Webhook:外部事件触发
bindings: [...], // 绑定:Agent 与渠道的映射
env: { ... }, // 环境变量:API Key 等
commands: { ... }, // 斜杠命名配置
}
Agent 配置
Agent 是 OpenClaw 的核心——每个 Agent 有自己的模型、工作区和行为设置。
1.默认配置(agents.defaults)
所有 Agent 共享的默认值,单个 Agent 可以覆盖。
{
agents: {
defaults: {
workspace: "~/.openclaw/workspace",
// 模型:主模型 + 回退链
model: {
primary: "anthropic/claude-sonnet-4-5",
fallbacks: ["openai/gpt-5.2"]
},
// 模型目录(让用户通过 /model 命令切换)
models: {
"anthropic/claude-sonnet-4-5": { alias: "Sonnet" },
"openai/gpt-5.2": { alias: "GPT" }
},
imageMaxDimensionPx: 1200, // 图片缩放上限(像素)
// 心跳:Agent 定期主动发消息
heartbeat: {
every: "30m", // 间隔:30m / 2h / 1d
target: "last", // 发给谁:last(最近对话) | 指定渠道 | none
directPolicy: "allow" // 是否允许直接消息:allow | block
},
// 沙盒:隔离工具执行环境
sandbox: {
mode: "non-main", // off | non-main(非主 Agent 隔离) | all
scope: "agent" // session | agent | shared
},
// 工具
tools: {
enabled: true,
profile: "full"
}
}
}
}
配置项速查:
| 配置项 | 类型 | 默认值 | 什么时候改 |
|---|---|---|---|
workspace | string | ~/.openclaw/workspace | 想把工作文件放到别的目录 |
model.primary | string | — | 换主模型(格式 provider/model) |
model.fallbacks | array | [] | 主模型挂了自动切换到备选 |
imageMaxDimensionPx | number | 1200 | 图片太大占 Token,可以调小 |
heartbeat.every | string | — | 调整 Agent 主动问候的频率 |
sandbox.mode | string | off | 安全敏感场景建议开 all |
2.多 Agent 配置(agents.list)
一个 OpenClaw 实例可以运行多个 Agent——比如"家庭助手"和"工作助手"用不同模型:
{
agents: {
list: [
{
id: "home",
default: true, // 默认 Agent
workspace: "~/.openclaw/workspace-home",
groupChat: {
mentionPatterns: ["@openclaw", "openclaw"]
}
},
{
id: "work",
workspace: "~/.openclaw/workspace-work",
model: {
primary: "anthropic/claude-opus-4-6" // 工作用更强的模型
}
}
]
}
}
多 Agent 需要配合绑定配置,指定哪个 Agent 响应哪个渠道。
渠道配置
渠道决定了 OpenClaw 连接哪些聊天平台、谁能跟它说话。
1.渠道与 DM 策略
每个渠道可以独立设置"谁能私聊"策略:
{
channels: {
telegram: {
enabled: true,
botToken: "123:abc",
dmPolicy: "pairing", // 私聊策略(见下表)
allowFrom: ["tg:123"], // allowlist/open 模式 下的白名单
},
whatsapp: {
enabled: true,
allowFrom: ["+15555550123"],
groups: {
"*": { requireMention: true } // 群聊必须 @ 才响应
}
},
discord: {
enabled: true,
botToken: "${DISCORD_BOT_TOKEN}", // 引用环境变量
dmPolicy: "pairing",
allowFrom: ["discord:123"]
},
slack: {
enabled: true,
botToken: "${SLACK_BOT_TOKEN}",
dmPolicy: "pairing"
}
}
}
DM 策略选项:
| 策略 | 行为 | 适用场景 |
|---|---|---|
pairing | 陌生人收到配对码,需管理员批准 | 个人使用(推荐) |
allowlist | 仅白名单内的用户可私聊 | 小团队 |
open | 允许所有人私聊(需 allowFrom: ["*"]) | 公开服务 |
disabled | 忽略所有私聊 | 仅群聊场景 |
2.群聊提及门控
群聊中,Agent 默认不会响应每条消息——需要被 @ 提及才会回复:
{
agents: {
list: [{
id: "main",
groupChat: {
mentionPatterns: ["@openclaw", "openclaw"] // 触发词
}
}]
},
channels: {
whatsapp: {
groups: {
"*": { requireMention: true } // 所有群都要 @
}
}
}
}
网关配置
网关是 OpenClaw 的后台服务进程,所有消息收发都经过它。
{
gateway: {
port: 18789, // 监听端口
bind: "loopback", // 绑定地址
auth: {
mode: "token", // 认证方式
token: "${OPENCLAW_GATEWAY_TOKEN}",
password: "${OPENCLAW_GATEWAY_PASSWORD}",
allowTailscale: true // Tailscale 连接免认证
},
tailscale: {
mode: "off", // off | serve | funnel
resetOnExit: false
},
reload: {
mode: "hybrid", // 配置变更时的重载策略
debounceMs: 300
}
}
}
绑定地址——决定谁能连:
| 值 | 能访问的范围 | 安全性 |
|---|---|---|
loopback | 仅本机(127.0.0.1) | 最安全(默认) |
lan | 局域网内所有设备 | 需配合认证 |
tailnet | Tailscale 虚拟网络 | 端到端加密 |
auto | 自动检测 | — |
custom | 自定义地址 | 取决于配置 |
热重载模式——改了配置要不要重启:
| 模式 | 行为 | 选择建议 |
|---|---|---|
hybrid | 安全更改热应用,关键更改自动重启 | 推荐(默认) |
hot | 仅热应用,需要重启时只记日志 | 不想被打断 |
restart | 任何改动都重启 | 追求一致性 |
off | 不监听配置文件变化 | 手动管理 |
网关管理查看。
会话配置
会话决定了"谁和谁的对话算同一个上下文"。
{
session: {
dmScope: "per-channel-peer", // 会话隔离粒度
threadBindings: { // 线程绑定(Discord/Slack 等有线程的平台)
enabled: true,
idleHours: 24, // 线程空闲多久后解绑
maxAgeHours: 0 // 0 = 不限最大年龄
},
reset: { // 自动重置会话
mode: "daily", // daily | idle | manual
atHour: 4, // daily 模式:每天几点重置(24h 制)
idleMinutes: 120 // idle 模式:空闲多久重置
}
}
}
会话隔离粒度——影响"谁和谁共享记忆":
| 值 | 隔离方式 | 适用场景 |
|---|---|---|
main | 所有人共享一个会话 | 单用户 |
per-peer | 每人一个会话 | 简单多用户 |
per-channel-peer | 每个平台的每人一个会话 | 多平台多用户(推荐) |
per-account-channel-peer | 每个账号×平台×用户 | 多 Agent 多平台 |
工具配置
控制 Agent 能使用哪些工具(搜索、编程、文件操作等)。
{
tools: {
profile: "full", // 工具集级别
enabled: true,
web: {
search: {
apiKey: "${BRAVE_API_KEY}" // Web 搜索需要的 API Key
}
}
}
}
工具集级别——从少到多:
| Profile | 包含的工具 | 适用场景 |
|---|---|---|
messaging | 仅聊天,无工具 | 纯对话 |
default | 基础工具集 | 日常使用 |
coding | 编程工具集 | 开发者 |
full | 完整工具集 |