乐于分享
好东西不私藏

OpenClaw 配置指南(完整中文版)

OpenClaw 配置指南(完整中文版)

整理时间:2026-03-14


目录

  1. 配置文件基础
  2. 渠道配置(Channels)
  3. 模型配置(Models)
  4. Agent 配置
  5. TTS 语音合成配置
  6. 会话配置(Session)
  7. 工具配置(Tools)
  8. 浏览器配置(Browser)
  9. 音频配置(Audio)
  10. Hooks 配置
  11. Cron 定时任务配置
  12. Gateway 配置
  13. 命令配置
  14. 诊断命令
  15. 配置示例

一、配置文件基础

1.1 配置文件位置

~/.openclaw/openclaw.json

1.2 配置格式

  • 使用 JSON5 格式(支持注释 // 和 /* */,支持尾随逗号)
  • 所有字段都是可选的,OpenClaw 有安全默认值

1.3 配置热重载

Gateway 自动监听配置文件变化,大多数设置无需手动重启。

重载模式
说明
配置方式
hybrid
(默认)
安全变更立即生效,关键变更自动重启
gateway.reload: "hybrid"
hot
只热应用安全变更,需要重启时发出警告
gateway.reload: "hot"
restart
任何变更都重启 Gateway
gateway.reload: "restart"
off
禁用文件监听,手动重启生效
gateway.reload: "off"

热重载支持的配置:

  • 渠道、Agent、模型、自动化、会话、消息、工具、媒体、UI 等

需要重启的配置:

  • Gateway 端口、绑定地址、认证、TLS、插件等

1.4 环境变量

OpenClaw 从以下位置读取环境变量:

  1. 父进程环境
  2. 当前目录的 .env 文件
  3. ~/.openclaw/.env(全局回退)

在配置中使用环境变量:

{  "models": {    "providers": {      "openai": {        "apiKey": "${OPENAI_API_KEY}"      }    }  }}

二、渠道配置(Channels)

每个渠道在其配置部分存在时自动启动(除非 enabled: false)。

2.1 私聊策略(dmPolicy)

策略
说明
pairing
(默认)
未知发送者获取一次性配对码,需主人批准
allowlist
只允许 allowFrom 列表中的发送者
open
允许所有私聊(需设置 allowFrom: ["*"]
disabled
忽略所有私聊

2.2 群聊策略(groupPolicy)

策略
说明
allowlist
(默认)
只允许配置的群组
open
绕过群组白名单(提及限制仍适用)
disabled
阻止所有群聊消息

2.3 群聊提及限制

群聊默认需要提及机器人才会响应:

提及类型:

  • 元数据提及:平台原生 @提及(WhatsApp 点击提及、Telegram @bot 等)
  • 文本模式mentionPatterns 中的正则表达式
{  "agents": {    "list": [{      "id": "my-agent",      "groupChat": {        "mentionPatterns": ["机器人", "助手", "@my_bot"]      }    }]  }}

2.4 Telegram 配置

{  "channels": {    "telegram": {      "enabled": true,      "botToken": "YOUR_BOT_TOKEN",      "dmPolicy": "pairing",      "groupPolicy": "open",      "allowFrom": ["123456789"],      "groups": {        "-1001234567890": {          "requireMention": true,          "enabled": true        }      },      "accounts": {        "default": {          "botToken": "BOT_TOKEN_1"        },        "scholar": {          "botToken": "BOT_TOKEN_2"        }      }    }  }}

字段说明:

字段
类型
说明
botToken
string
Telegram Bot Token
tokenFile
string
从文件读取 Token(更安全)
dmPolicy
string
私聊策略
groupPolicy
string
群聊策略
allowFrom
array
允许的用户 ID 列表
groups
object
群组配置,key 为群组 ID
requireMention
bool
是否需要提及才响应
configWrites
bool
是否允许通过命令修改配置
streaming
string
流式回复模式:"partial"

2.5 Discord 配置

{  "channels": {    "discord": {      "token": "YOUR_DISCORD_BOT_TOKEN",      "dmPolicy": "pairing",      "guilds": {        "GUILD_ID": {          "enabled": true,          "ignoreOtherMentions": true        }      },      "voice": {        "enabled": true,        "autoJoin": true      }    }  }}

2.6 WhatsApp 配置

{  "channels": {    "whatsapp": {      "enabled": true,      "dmPolicy": "pairing",      "accounts": {        "default": {          "sendReadReceipts": true        }      }    }  }}

2.7 多账号配置

所有渠道都支持多账号:

{  "channels": {    "telegram": {      "defaultAccount": "default",      "accounts": {        "default": {          "botToken": "TOKEN_1"        },        "butler": {          "botToken": "TOKEN_2"        },        "scholar": {          "botToken": "TOKEN_3"        }      }    }  }}

三、模型配置(Models)

3.1 模型格式

provider/model-id

例如:anthropic/claude-opus-4-6openai/gpt-5.4google/gemini-3.1-pro-preview

3.2 默认模型配置

{  "agents": {    "defaults": {      "model": "freeapi/gpt-5.2",      "imageModel": "openai/gpt-4o",      "pdfModel": "anthropic/claude-sonnet-4-6"    }  }}

字段说明:

字段
说明
model
主模型,支持字符串或对象 { primary, fallbacks }
imageModel
图像理解模型(用于 image 工具)
pdfModel
PDF 分析模型

3.3 模型目录和别名

{  "agents": {    "defaults": {      "models": {        "anthropic/claude-opus-4-6": {          "alias": "opus",          "params": {            "temperature": 0.7,            "maxTokens": 4096          }        },        "openai/gpt-5.4": {          "alias": "gpt"        }      }    }  }}

3.4 内置别名快捷方式

别名
模型
opusanthropic/claude-opus-4-6
sonnetanthropic/claude-sonnet-4-6
gptopenai/gpt-5.4
gpt-miniopenai/gpt-5-mini
geminigoogle/gemini-3.1-pro-preview
gemini-flashgoogle/gemini-3-flash-preview

3.5 故障转移

{  "agents": {    "defaults": {      "model": {        "primary": "anthropic/claude-opus-4-6",        "fallbacks": ["openai/gpt-5.4", "google/gemini-3.1-pro-preview"]      }    }  }}

3.6 自定义提供商

{  "models": {    "mode": "merge",    "providers": {      "my-custom-provider": {        "baseUrl": "https://api.example.com/v1",        "apiKey": "${MY_API_KEY}",        "api": "openai-completions",        "models": [          {            "id": "my-model",            "contextWindow": 128000,            "maxTokens": 8192          }        ]      }    }  }}

四、Agent 配置

4.1 默认设置

{  "agents": {    "defaults": {      "workspace": "~/.openclaw/workspace",      "repoRoot": "/path/to/repo",      "model": "provider/model-id",      "maxConcurrent": 1,      "timeoutSeconds": 1800,      "contextTokens": 1000000,      "imageMaxDimensionPx": 1200,      "userTimezone": "Asia/Shanghai",      "timeFormat": "auto"    }  }}

字段说明:

字段
默认值
说明
workspace~/.openclaw/workspace
工作空间目录
repoRoot
自动检测
仓库根目录(显示在系统提示中)
model
-
默认模型
maxConcurrent
1
最大并行 Agent 运行数
timeoutSeconds
1800
单次运行超时时间
contextTokens
-
上下文窗口大小
imageMaxDimensionPx
1200
图片最大尺寸(降低可减少 token 消耗)
userTimezone
系统时区
用户时区
timeFormatauto
时间格式

4.2 Bootstrap 文件

Agent 启动时会加载工作空间中的以下文件:

文件
说明
AGENTS.md
Agent 行为指导
SOUL.md
Agent 人格定义
TOOLS.md
工具使用指导
IDENTITY.md
身份信息
USER.md
用户偏好
HEARTBEAT.md
心跳任务指导
BOOTSTRAP.md
启动指导

相关配置:

{  "agents": {    "defaults": {      "skipBootstrap": false,      "bootstrapMaxChars": 20000,      "bootstrapTotalMaxChars": 150000    }  }}

4.3 多 Agent 配置

{  "agents": {    "list": [      {        "id": "main",        "default": true,        "workspace": "~/.openclaw/workspace-main",        "groupChat": {          "mentionPatterns": ["诺玛", "@main_bot"]        }      },      {        "id": "butler",        "workspace": "~/.openclaw/workspace-butler",        "groupChat": {          "mentionPatterns": ["管家", "@butler_bot"]        }      },      {        "id": "scholar",        "workspace": "~/.openclaw/workspace-scholar",        "groupChat": {          "mentionPatterns": ["学霸", "@scholar_bot"]        }      }    ]  }}

4.4 Agent 绑定(路由)

{  "bindings": [    {      "agentId": "main",      "match": {        "channel": "telegram",        "accountId": "default"      }    },    {      "agentId": "butler",      "match": {        "channel": "telegram",        "accountId": "butler"      }    },    {      "agentId": "scholar",      "match": {        "channel": "telegram",        "accountId": "scholar"      }    }  ]}

匹配字段说明:

字段
说明
match.channel
渠道名称(必填)
match.accountId
账号 ID(可选,* 表示任意账号)
match.peer
对等体 { kind: "direct|group|channel", id }
match.guildId
Discord 服务器 ID
match.teamId
Slack/Teams 团队 ID

4.5 心跳配置(Heartbeat)

定期运行 Agent 任务:

{  "agents": {    "defaults": {      "heartbeat": {        "every": "30m",        "suppressToolErrorWarnings": true,        "directPolicy": "allow",        "lightContext": true      }    }  }}

字段说明:

字段
默认值
说明
every30m
心跳间隔
suppressToolErrorWarnings
false
是否抑制工具错误警告
directPolicyallow
直接投递策略:allow / block
lightContext
false
使用轻量级上下文(只加载 HEARTBEAT.md)

4.6 上下文压缩(Compaction)

长会话自动压缩:

{  "agents": {    "defaults": {      "compaction": {        "mode": "safeguard",        "identifierPolicy": "strict",        "model": "anthropic/claude-sonnet-4-6",        "memoryFlush": {          "enabled": true,          "softThresholdTokens": 6000        }      }    }  }}

4.7 沙箱配置(Sandbox)

使用 Docker 隔离 Agent:

{  "agents": {    "defaults": {      "sandbox": {        "mode": "off",        "workspaceAccess": "rw",        "scope": "agent",        "docker": {          "image": "openclaw-sandbox:latest",          "network": "none",          "binds": ["/host/path:/container/path"]        }      }    }  }}

工作空间访问模式:

模式
说明
none
沙箱内独立工作空间
ro
只读挂载 Agent 工作空间
rw
读写挂载 Agent 工作空间

作用域:

作用域
说明
session
每个会话独立容器
agent
每个 Agent 一个容器(默认)
shared
共享容器(无会话隔离)

五、TTS 语音合成配置

5.1 启用 TTS

{  "messages": {    "tts": {      "auto": "always",      "provider": "edge"    }  }}

5.2 TTS 模式

模式
说明
off
禁用(默认)
always
总是生成语音
inbound
只在收到语音消息后回复语音
tagged
只在回复包含 [[tts]] 标签时生成语音

5.3 支持的 TTS 服务

服务
特点
需要 API Key
Edge TTS
微软神经音色,免费
❌ 不需要
OpenAI TTS
高质量
✅ 需要
ElevenLabs
最高质量,多音色
✅ 需要

5.4 Edge TTS 配置

{  "messages": {    "tts": {      "auto": "always",      "provider": "edge",      "edge": {        "enabled": true,        "voice": "zh-CN-XiaoxiaoNeural",        "lang": "zh-CN",        "outputFormat": "ogg-24khz-16bit-mono-opus",        "rate": "+0%",        "pitch": "+0%",        "volume": "+0%"      }    }  }}

常用中文音色:

音色
说明
zh-CN-XiaoxiaoNeural
晓晓,温柔女声
zh-CN-YunxiNeural
云希,阳光男声
zh-CN-YunyangNeural
云扬,专业男声
zh-CN-XiaoyiNeural
晓伊,活泼女声

常用英文音色:

音色
说明
en-US-JennyNeural
Jenny,清晰女声
en-US-GuyNeural
Guy,稳重男声
en-GB-SoniaNeural
Sonia,英音女声
en-GB-RyanNeural
Ryan,英音男声

5.5 OpenAI TTS 配置

{  "messages": {    "tts": {      "auto": "always",      "provider": "openai",      "openai": {        "voice": "alloy",        "model": "tts-1"      }    }  }}

5.6 用户偏好文件

位置:~/.openclaw/settings/tts.json

{  "enabled": true,  "provider": "edge",  "maxLength": 10000,  "summarize": false}

字段说明:

字段
默认值
说明
enabled
-
是否启用
provider
-
TTS 提供商
maxLength
1500
最大文本长度(超过则摘要或截断)
summarize
true
是否对长文本进行摘要

5.7 斜杠命令

/tts on          # 开启 TTS(等同于 /tts always)/tts off         # 关闭 TTS/tts always      # 总是生成语音/tts inbound     # 只在收到语音后回复语音/tts tagged      # 只在标记时生成语音/tts audio       # 生成一次性语音回复/tts limit 5000  # 设置长度限制

5.8 模型驱动的音色切换

Agent 可以在回复中插入指令切换音色:

这是中文内容。[[tts:voice=en-US-JennyNeural]][[tts:text]]This is English content.[[/tts:text]]继续中文内容...

六、会话配置(Session)

6.1 会话作用域(dmScope)

作用域
说明
main
所有私聊共享主会话
per-peer
按发送者 ID 隔离
per-channel-peer
按渠道+发送者隔离(推荐多用户)
per-account-channel-peer
按账号+渠道+发送者隔离(推荐多账号)
{  "session": {    "dmScope": "per-channel-peer"  }}

6.2 会话重置

{  "session": {    "reset": {      "mode": "idle",      "idleMinutes": 30    },    "resetByType": {      "direct": {        "mode": "idle",        "idleMinutes": 30      },      "group": {        "mode": "idle",        "idleMinutes": 60      }    }  }}

重置模式:

模式
说明
idle
空闲指定时间后重置
daily
每天指定时间重置

七、工具配置(Tools)

7.1 工具白名单/黑名单

{  "tools": {    "allow": ["*"],    "deny": ["exec", "process"],    "profile": "coding"  }}

工具配置文件(Profile):

Profile
包含的工具
minimal
只有 session_status
coding
文件系统、运行时、会话、内存、图像工具
messaging
消息、会话历史、会话状态
full
无限制(默认)

7.2 工具组(Groups)

组名
包含的工具
group:runtimeexec
bashprocess
group:fsread
writeeditapply_patch
group:sessionssessions_list
sessions_historysessions_sendsessions_spawnsession_status
group:memorymemory_search
memory_get
group:webweb_search
web_fetch
group:uibrowser
canvas
group:automationcron
gateway
group:messagingmessage
group:nodesnodes
group:openclaw
所有内置工具(不含插件)

7.3 Web 搜索配置

{  "tools": {    "web": {      "search": {        "enabled": true,        "provider": "brave",        "maxResults": 10      },      "fetch": {        "enabled": true,        "maxCharsCap": 50000      }    }  }}

支持的搜索提供商:

  • brave(推荐)
  • perplexity
  • gemini
  • grok
  • kimi

7.4 Agent 间通信

{  "tools": {    "agentToAgent": {      "enabled": true,      "allow": ["main", "butler", "scholar"]    }  }}

7.5 命令执行配置

{  "tools": {    "exec": {      "host": "gateway",      "security": "full"    },    "elevated": {      "enabled": true,      "allowFrom": {        "telegram": ["123456789"]      }    }  }}

安全级别:

级别
说明
deny
禁止执行
allowlist
只允许白名单命令
full
允许所有命令

八、浏览器配置(Browser)

8.1 基本配置

{  "browser": {    "enabled": true,    "defaultProfile": "openclaw",    "executablePath": "/usr/bin/chromium"  }}

8.2 多 Profile 配置

{  "browser": {    "profiles": {      "openclaw": {        "color": "orange",        "cdpPort": 18800      },      "work": {        "color": "blue",        "cdpPort": 18801      }    }  }}

8.3 远程 CDP 配置

连接到远程浏览器(如 Browserless、Browserbase):

{  "browser": {    "profiles": {      "browserless": {        "cdpUrl": "wss://chrome.browserless.io?token=YOUR_TOKEN"      }    }  }}

8.4 浏览器工具操作

操作
说明
status
查看状态
start
 / stop
启动/停止浏览器
tabs
列出标签页
open
 / focus / close
打开/聚焦/关闭标签页
snapshot
获取页面快照(AI 或 ARIA)
screenshot
截图
navigate
导航到 URL
act
执行操作(click/type/press 等)

8.5 CLI 命令示例

# 查看状态openclaw browser status# 截图openclaw browser screenshot --full-page# AI 快照openclaw browser snapshot# 交互模式快照(带 ref)openclaw browser snapshot --interactive# 点击元素openclaw browser click 12        # AI snapshot 数字 refopenclaw browser click e12       # Role snapshot ref# 输入文字openclaw browser type 23 "hello" --submit# 导航openclaw browser navigate https://example.com

九、音频配置(Audio)

9.1 自动检测

如果不配置,OpenClaw 会自动检测可用的转录方案:

  1. 本地 CLI:sherpa-onnx-offlinewhisper-cliwhisper
  2. Gemini CLI
  3. Provider API:OpenAI → Groq → Deepgram → Google

9.2 配置示例

{  "tools": {    "media": {      "audio": {        "enabled": true,        "maxBytes": 20971520,        "maxChars": null,        "echoTranscript": false,        "models": [          {            "provider": "openai",            "model": "gpt-4o-mini-transcribe"          }        ]      }    }  }}

9.3 字段说明

字段
默认值
说明
enabled
true
是否启用音频理解
maxBytes
20MB
最大音频文件大小
maxChars
无限制
最大转录字符数
echoTranscript
false
是否将转录结果发回聊天
models
自动检测
转录模型列表

9.4 群聊语音提及检测

在需要提及的群聊中,OpenClaw 会先转录语音再检查是否提及:

{  "channels": {    "telegram": {      "groups": {        "-1001234567890": {          "requireMention": true,          "disableAudioPreflight": false        }      }    }  }}

十、Hooks 配置

Hooks 是事件驱动的自动化系统,在特定事件发生时运行脚本。

10.1 内置 Hooks

Hook
事件
说明
session-memorycommand:new
保存会话上下文到记忆文件
bootstrap-extra-filesagent:bootstrap
注入额外的 bootstrap 文件
command-loggercommand
记录所有命令到日志
boot-mdgateway:startup
启动时运行 BOOT.md

10.2 启用 Hooks

{  "hooks": {    "internal": {      "enabled": true,      "entries": {        "session-memory": {          "enabled": true        },        "command-logger": {          "enabled": true        }      }    }  }}

10.3 事件类型

命令事件:

  • command:new - 执行 /new 时
  • command:reset - 执行 /reset 时
  • command:stop - 执行 /stop 时

会话事件:

  • session:compact:before - 压缩前
  • session:compact:after - 压缩后

Agent 事件:

  • agent:bootstrap - Agent 启动时

Gateway 事件:

  • gateway:startup - Gateway 启动时

消息事件:

  • message:received - 收到消息
  • message:transcribed - 语音转录完成
  • message:sent - 发送消息

10.4 自定义 Hook 结构

~/.openclaw/hooks/my-hook/├── HOOK.md└── handler.ts

HOOK.md 格式:

---emoji: "📝"events:  - command:new  - command:reset---# My Custom HookDescription of what this hook does.

handler.ts 格式:

import { HookHandler } from 'openclaw';const handler: HookHandler = async (event, context) => {  // 处理事件  console.log('Event:', event);};export default handler;

10.5 CLI 命令

# 列出所有 Hooksopenclaw hooks list# 查看 Hook 详情openclaw hooks show session-memory# 启用/禁用 Hookopenclaw hooks enable session-memoryopenclaw hooks disable session-memory# 检查 Hook 是否符合条件openclaw hooks check session-memory

十一、Cron 定时任务配置

11.1 基本概念

Cron 是 Gateway 内置的调度器,支持:

  • 一次性任务(at
  • 固定间隔任务(every
  • Cron 表达式任务(cron

11.2 任务配置

{  "cron": {    "enabled": true,    "store": "~/.openclaw/cron/jobs.json",    "sessionRetention": "24h",    "runLog": {      "maxBytes": 2000000,      "keepLines": 2000    },    "jobs": [      {        "id": "daily-summary",        "enabled": true,        "schedule": {          "kind": "cron",          "expr": "0 9 * * *",          "tz": "Asia/Shanghai"        },        "sessionTarget": "isolated",        "payload": {          "kind": "agentTurn",          "message": "Generate daily summary"        },        "delivery": {          "mode": "announce",          "channel": "telegram",          "to": "123456789"        }      }    ]  }}

11.3 调度类型

类型
字段
说明
atschedule.at
一次性任务,ISO 8601 时间戳
everyschedule.everyMs
固定间隔,毫秒
cronschedule.expr
Cron 表达式

11.4 会话目标

目标
说明
main
在主会话中运行(通过心跳)
isolated
在独立会话 cron:<jobId> 中运行
current
绑定到创建时的当前会话
session:xxx
在指定的持久会话中运行

11.5 投递模式

模式
说明
announce
投递摘要到目标渠道
webhook
POST 到指定 URL
none
仅内部运行,不投递

11.6 CLI 命令

# 查看状态openclaw cron status# 列出任务openclaw cron list# 添加一次性任务openclaw cron add --at "2026-03-15T09:00:00+08:00" --message "Reminder"# 添加重复任务openclaw cron add --every 30m --message "Check status"# 添加 cron 任务openclaw cron add --cron "0 9 * * *" --message "Daily task"# 编辑任务openclaw cron edit <jobId> --message "New message"# 删除任务openclaw cron remove <jobId># 立即运行任务openclaw cron run <jobId># 查看运行历史openclaw cron runs --id <jobId>

十二、Gateway 配置

12.1 基本配置

{  "gateway": {    "port": 18789,    "mode": "local",    "bind": "loopback",    "auth": {      "mode": "token",      "token": "your-secure-token"    }  }}

12.2 字段说明

字段
默认值
说明
port
18789
Gateway 端口
modelocal
运行模式:local / remote
bindloopback
绑定地址:loopback / 0.0.0.0
auth.mode
-
认证模式:token / password / none
auth.token
自动生成
认证 Token

12.3 TLS 配置

{  "gateway": {    "tls": {      "enabled": true,      "autoGenerate": true    }  }}

12.4 健康检查

curl http://127.0.0.1:18789/health# 返回:{"ok":true,"status":"live"}

十三、命令配置

13.1 命令开关

{  "commands": {    "native": "auto",    "restart": true,    "bash": false,    "config": false,    "ownerDisplay": "raw"  }}

字段说明:

字段
默认值
说明
nativeauto
原生命令注册:auto / true / false
restart
true
是否允许 /restart 命令
bash
false
是否允许 ! <cmd> 执行 Shell
config
false
是否允许 /config 命令

13.2 常用命令

命令
说明
/new
开始新会话
/reset
重置当前会话
/model <model>
切换模型
/models
列出可用模型
/tts on/off
开关 TTS
/allowlist
管理白名单
/config show
显示配置
/restart
重启 Gateway
/help
显示帮助

十四、诊断命令

14.1 CLI 诊断

# 检查配置问题openclaw doctor# 自动修复问题openclaw doctor --fix# 查看日志openclaw logs# 健康检查openclaw health# 运行状态openclaw status

14.2 日志位置

/tmp/openclaw/openclaw-YYYY-MM-DD.log~/.openclaw/logs/commands.log

十五、配置示例

15.1 最小配置

{  "agents": {    "defaults": {      "model": "anthropic/claude-sonnet-4-6"    }  },  "channels": {    "telegram": {      "botToken": "YOUR_BOT_TOKEN",      "dmPolicy": "pairing"    }  }}