Phase 2 / Ep 08: 配置管理 —— config get/set 与 openclaw.json 深度解读
🎯 学习目标:精通配置系统的层级关系和常用配置项。
1. 配置优先级
graph TD
A["1️⃣ CLI 参数\n最高优先级"] --> B["2️⃣ 环境变量\nOPENCLAW_*"]
B --> C["3️⃣ Agent 级配置\nagent.json"]
C --> D["4️⃣ 全局配置\nopenclaw.json"]2. config 命令
# 读取配置
openclaw config get llm.provider
# → anthropic
# 写入配置
openclaw config set llm.provider anthropic
openclaw config set llm.model claude-sonnet-4-20250514
openclaw config set tools.profile coding
# 列出所有配置
openclaw config list
3. openclaw.json 关键字段
{
"gateway": {
"port": 3377,
"host": "127.0.0.1",
"logLevel": "info"
},
"llm": {
"provider": "anthropic",
"model": "claude-sonnet-4-20250514",
"maxTokens": 4096,
"temperature": 0.7
},
"tools": {
"profile": "standard",
"allowedCommands": [],
"blockedCommands": ["rm -rf /", "shutdown"]
},
"channels": {
"telegram": {
"enabled": true,
"token": "${TELEGRAM_BOT_TOKEN}",
"allowedUsers": [123456789]
}
},
"agents": {
"default": "personal"
}
}
4. 敏感配置管理
绝对不要在 openclaw.json 中硬编码 API Key。使用环境变量:
# .env 文件
ANTHROPIC_API_KEY=sk-ant-xxx
TELEGRAM_BOT_TOKEN=7123456789:AAH...
OPENAI_API_KEY=sk-xxx
# 在 openclaw.json 中引用
"token": "${TELEGRAM_BOT_TOKEN}"
5. CLI vs Telegram 对照
| 操作 | CLI | Telegram |
|---|---|---|
| 读取配置 | openclaw config get llm.model |
/config llm.model |
| 修改配置 | openclaw config set llm.model xxx |
/config set llm.model xxx |
| 列出所有 | openclaw config list |
/config list |
下节预告: Ep 09,进入 Skills 命令——从 ClawHub 发现、安装和管理技能,解锁 Agent 的新能力。