第 1 章

安装与初始化

📦 安装

# 全局安装(任选其一)
npm install -g openclaw@latest
pnpm add -g openclaw@latest

# 启动安装向导(推荐)
openclaw onboard --install-daemon

Windows 用户:强烈推荐在 WSL2 下运行,体验与 Linux 一致。

向导会引导你完成:

  • 选择 AI 模型
  • 连接消息渠道(Telegram / WhatsApp / Discord 等)
  • 安装 Gateway 守护进程

📁 目录结构

~/.openclaw/
├── openclaw.json          # 主配置文件
├── credentials/           # API Keys(chmod 600)
│   ├── anthropic
│   ├── openai
│   └── whatsapp/
└── workspace/             # Agent 的"大脑"
    ├── AGENTS.md          # 工作规范(每次会话都会加载)
    ├── SOUL.md            # Agent 性格与价值观
    ├── IDENTITY.md        # Agent 对外身份(名字、emoji)
    ├── USER.md            # 用户信息与偏好
    ├── MEMORY.md          # 长期记忆索引
    ├── TOOLS.md           # 本地工具说明
    ├── HEARTBEAT.md       # 定时心跳任务清单
    ├── BOOTSTRAP.md       # 首次运行初始化脚本(用完即删)
    ├── memory/            # 每日日志
    │   ├── 2026-02-25.md
    │   └── 2026-02-26.md
    └── skills/            # 自定义 Skill

workspace 路径可在 openclaw.json 中通过 agents.defaults.workspace 自定义,默认 ~/.openclaw/workspace

⚙️ 最小可用配置

安装后编辑 ~/.openclaw/openclaw.json

{
  "agent": {
    "model": "anthropic/claude-sonnet-4-6",
    "workspace": "~/.openclaw/workspace"
  },
  "channels": {
    "telegram": {
      "token": "YOUR_BOT_TOKEN",
      "allowFrom": ["YOUR_TELEGRAM_USER_ID"]
    }
  }
}

配置文件支持 JSON5(可以写注释和尾逗号)。修改后 Gateway 会自动热加载,大多数配置无需重启。

验证安装

openclaw doctor        # 检查配置问题并自动修复
openclaw status        # 查看 Gateway 运行状态
openclaw health        # 请求 Gateway 健康快照