OpenClaw 中文教程

从入门到精通,打造你的专属 AI 助手

📦 1. 快速安装

系统要求

  • Node.js >= 18.0
  • pnpm >= 8.0
  • Linux / macOS / Windows (WSL2)

一键安装

# 使用 npm 全局安装
npm install -g openclaw

# 或者使用 pnpm
pnpm add -g openclaw

提示:安装完成后运行 openclaw --version 验证安装

启动 Gateway

# 启动 OpenClaw Gateway
openclaw gateway start

# 查看状态
openclaw gateway status

成功标志:看到 Gateway 运行在 http://127.0.0.1:18789

⚙️ 2. 基础配置

配置文件位置

~/.openclaw/openclaw.json

配置模型

{
  "models": {
    "providers": {
      "bailian": {
        "baseUrl": "https://dashscope.aliyuncs.com/api/v1",
        "apiKey": "sk-your-api-key",
        "models": [
          {
            "id": "qwen-plus",
            "name": "通义千问 Plus",
            "contextWindow": 32000
          }
        ]
      }
    }
  }
}

配置工作区

{
  "agents": {
    "defaults": {
      "workspace": "/home/your-name/openclaw-workspace"
    }
  }
}

提示:工作区是 OpenClaw 操作文件的地方,建议单独创建一个目录

☁️ 2.5 阿里云百炼 Coding Plan 配置

推荐:使用阿里云百炼 Coding Plan 可以获得更强大的编程能力和更低的成本

获取 API Key

  1. 访问 阿里云百炼控制台
  2. 登录阿里云账号
  3. 进入 Coding Plan 页面
  4. 创建或选择已有的 API Key
  5. 复制 API Key(格式类似:sk-xxxxxxxxxxxxxxxx

方式一:通过 Web UI 配置(推荐)

# 打开 Web UI
openclaw dashboard

在 Web UI 左侧菜单选择 SettingsConfig,复制以下内容到 Raw JSON 输入框:

{
  "models": {
    "mode": "merge",
    "providers": {
      "bailian": {
        "baseUrl": "https://coding.dashscope.aliyuncs.com/v1",
        "apiKey": "YOUR_API_KEY",
        "api": "openai-completions",
        "models": [
          { "id": "qwen3.5-plus", "name": "qwen3.5-plus", "contextWindow": 1000000, "maxTokens": 65536 },
          { "id": "qwen3-max-2026-01-23", "name": "qwen3-max-2026-01-23", "contextWindow": 262144 },
          { "id": "qwen3-coder-next", "name": "qwen3-coder-next", "contextWindow": 262144 },
          { "id": "qwen3-coder-plus", "name": "qwen3-coder-plus", "contextWindow": 1000000 },
          { "id": "MiniMax-M2.5", "name": "MiniMax-M2.5", "contextWindow": 196608 },
          { "id": "glm-5", "name": "glm-5", "contextWindow": 202752 },
          { "id": "kimi-k2.5", "name": "kimi-k2.5", "contextWindow": 262144 }
        ]
      }
    }
  },
  "agents": {
    "defaults": {
      "model": { "primary": "bailian/qwen3.5-plus" }
    }
  },
  "gateway": { "mode": "local" }
}

注意:YOUR_API_KEY 替换为你的 Coding Plan 专属 API Key

切换模型

临时切换(当前会话有效):

# 进入 TUI 界面
openclaw tui

# 使用 /model 命令切换
/model qwen3-coder-next

推荐模型:

  • qwen3.5-plus - 综合性能最佳,适合日常使用
  • qwen3-coder-plus - 编程专用,代码能力更强
  • qwen3-max-2026-01-23 - 最强模型,适合复杂任务

💬 3. 消息渠道配置

飞书 (Feishu)

{
  "channels": {
    "feishu": {
      "enabled": true,
      "dmPolicy": "pairing",
      "accounts": {
        "main": {
          "appId": "cli_xxxxxxxxxxxxx",
          "appSecret": "xxxxxxxxxxxxxxxx",
          "botName": "我的 OpenClaw"
        }
      }
    }
  }
}

Telegram

{
  "channels": {
    "telegram": {
      "enabled": true,
      "accounts": {
        "main": {
          "botToken": "123456789:ABCdefGHIjklMNOpqrsTUVwxyz"
        }
      }
    }
  }
}

提示:通过 @BotFather 创建 Telegram 机器人

🛠️ 4. 工具与技能

内置工具组

  • group:fs - 文件系统操作
  • browser - 浏览器控制
  • group:runtime - 代码执行
  • group:automation - 自动化任务
  • group:openclaw - OpenClaw 管理

安装技能

# 使用 clawhub 安装技能
npx clawhub install weather

# 查看已安装技能
npx clawhub list

热门技能:weather(天气)、tmux(远程终端)、video-frames(视频处理)

🧠 5. 记忆系统

记忆文件结构

workspace/
├── MEMORY.md              # 长期记忆
├── SOUL.md                # 人格定义
├── USER.md                # 用户信息
├── IDENTITY.md            # 身份定义
├── HEARTBEAT.md           # 心跳任务
└── memory/
    ├── 2026-03-11.md      # 每日记忆
    └── 2026-03-12.md

提示:OpenClaw 会自动学习并更新记忆文件

🚀 6. 进阶功能

Tailscale 远程访问

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

定时任务 (Cron)

# 配置定时提醒
openclaw cron add --schedule "0 9 * * *" --message "早上好!今日待办..."

Cloudflare Tunnel 公网访问

# 安装 cloudflared
# 配置隧道
cloudflared tunnel create my-tunnel

# 运行隧道
cloudflared tunnel run my-tunnel

7. 常见问题

Q: Gateway 启动失败?

A: 检查端口是否被占用,查看日志:

openclaw logs --tail 50

Q: 如何备份配置?

A: 备份整个 ~/.openclaw 目录:

tar -czf openclaw-backup.tar.gz ~/.openclaw

Q: 如何更新 OpenClaw?

A: 使用以下命令更新:

openclaw update

注意:不要将包含敏感信息的配置文件上传到公开仓库