OpenClaw是一个开源的跨平台个人AI助手框架,采用MIT协议发布。项目以龙虾(Lobster)为吉祥物,口号"The lobster way"展现了其独特的技术风格。截至2026年2月,该项目在GitHub上已获得43.9k收藏,拥有超过14,000次提交记录,显示出极高的开发活跃度和社区认可度。
核心定位是打造"完全属于用户"的个人AI助手,强调数据主权(own-your-data)原则。与主流AI助手不同,OpenClaw的设计哲学是让用户完全掌控AI的运行环境、数据流向和功能边界。这种去中心化的设计理念在当前AI服务普遍云端化的背景下显得尤为独特。
技术架构上采用多Agent协同工作的模式,主要包含以下组件:
这种架构使得OpenClaw既能够保持核心精简,又可以通过插件机制无限扩展功能。项目使用pnpm进行包管理,采用TypeScript作为主要开发语言,确保了代码质量和可维护性。
OpenClaw支持Windows/macOS/Linux三大平台,建议配置:
注意:Windows用户建议使用Windows Terminal替代传统cmd,以获得更好的命令行体验。如果遇到权限问题,需要以管理员身份运行终端。
对于Node.js环境,推荐使用nvm(Node Version Manager)进行管理,可以方便地切换不同Node版本:
bash复制# Windows用户安装nvm-windows
choco install nvm
# macOS/Linux用户
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.5/install.sh | bash
安装完成后配置Node.js环境变量(Windows示例):
powershell复制$env:Path = "C:\Program Files\nodejs\node_global;$env:Path"
where.exe node # 验证node路径
提供三种安装方式供选择:
powershell复制iwr -useb https://openclaw.ai/install.ps1 | iex
bash复制npm install -g openclaw@latest
bash复制pnpm add -g openclaw@latest
安装完成后验证版本:
bash复制openclaw --version
执行初始化向导:
bash复制openclaw onboard --install-daemon
这个交互式向导会引导完成:
实操技巧:初次配置时建议选择"跳过"非必要选项,后续可通过
openclaw configure命令单独配置。特别注意网关模式要设置为local(本地模式):bash复制openclaw config set gateway.mode local
OpenClaw的主要配置文件位于~/.openclaw/openclaw.json,关键配置项包括:
json复制{
"agents": {
"defaults": {
"memorySearch": {
"enabled": false // 语义记忆功能开关
},
"sandbox": {
"mode": "off", // 沙箱模式
"scope": "agent" // 沙箱作用域
}
}
},
"gateway": {
"port": 18789, // 服务端口
"auth": {
"enabled": false // 认证开关
}
}
}
使用doctor命令进行系统检查:
bash复制openclaw doctor
常见问题处理:
bash复制openclaw gateway --verbose # 查看详细日志
powershell复制openclaw config set agents.defaults.sandbox.mode off
taskkill /F /IM node.exe # 结束残留进程
openclaw gateway --force # 强制重启
bash复制openclaw config set gateway.port 新的端口号
启动网关服务:
bash复制openclaw gateway --port 18789 --verbose
发送测试消息:
bash复制openclaw message send --to +1234567890 --message "测试消息"
与AI助手交互:
bash复制openclaw agent --message "今天的日程安排" --thinking high
注意事项:
--thinking high参数会启用深度思考模式,响应时间较长但结果更精确。日常简单查询可省略此参数。
访问本地仪表盘:
code复制http://127.0.0.1:18789/
主要功能区域:
解除沙箱限制后,可实现本地文件操作:
bash复制# 创建目录
openclaw agent --message "在桌面创建test文件夹"
# 文件操作
openclaw agent --message "将下载目录中的图片移动到test文件夹"
安全提示:关闭沙箱后,建议通过
agents.defaults.sandbox.scope限制AI可访问的目录范围,避免安全风险。
安装飞书官方插件:
bash复制openclaw plugins install @openclaw/feishu
验证插件安装:
bash复制openclaw plugins list
飞书后台配置流程:
json复制{
"scopes": {
"tenant": [
"im:message",
"im:message:send_as_bot"
]
}
}
OpenClaw端通道配置:
bash复制openclaw channels add
选择Feishu后依次输入:
配对验证流程:
bash复制openclaw pairing approve feishu PAIR-ABC123
OpenClaw采用插件式架构,开发者可以创建自定义技能。基本开发流程:
初始化技能项目:
bash复制openclaw skill init my-skill
典型技能结构:
code复制my-skill/
├── package.json
├── src/
│ ├── index.ts # 主逻辑
│ └── schema.ts # 参数定义
└── test/ # 测试用例
示例技能代码:
typescript复制import { Skill } from 'openclaw';
export default new Skill({
name: 'my-skill',
description: '自定义技能示例',
actions: {
greet: {
handler: async ({ name }) => {
return `Hello, ${name}!`;
}
}
}
});
本地测试安装:
bash复制cd my-skill
pnpm link
openclaw plugins link ./my-skill
启动完整服务栈:
bash复制openclaw start
单独控制组件:
bash复制# 网关控制
openclaw gateway start|stop|restart
# 代理控制
openclaw agent start|stop|restart
状态检查:
bash复制openclaw status --all # 完整状态
openclaw health # 健康检查
openclaw logs --follow # 实时日志
资源限制配置:
bash复制openclaw config set agents.defaults.resources.cpu 0.5 # 限制CPU使用率
openclaw config set agents.defaults.resources.memory 1024 # 内存限制(MB)
模型加载策略:
bash复制openclaw config set models.preload false # 按需加载模型
缓存配置:
bash复制openclaw config set cache.enabled true
openclaw config set cache.ttl 3600 # 缓存有效期(秒)
配置文件备份:
powershell复制# Windows
Compress-Archive -Path "$env:USERPROFILE\.openclaw" -DestinationPath "openclaw-backup.zip"
# macOS/Linux
tar -czvf openclaw-backup.tar.gz ~/.openclaw
恢复流程:
问题1:npm安装时报权限错误
bash复制# 解决方案:
npm install -g openclaw@latest --unsafe-perm
# 或使用pnpm:
pnpm add -g openclaw@latest
问题2:Windows脚本执行策略限制
powershell复制# 解决方案:
Set-ExecutionPolicy RemoteSigned -Scope CurrentUser
错误1:Gateway unreachable
bash复制# 分步排查:
openclaw gateway --verbose # 查看网关日志
netstat -ano | findstr 18789 # 检查端口占用
openclaw config get gateway.port # 确认配置端口
错误2:Sandbox violation
powershell复制# 彻底解决方案:
$cfg = "$env:USERPROFILE\.openclaw\openclaw.json"
$j = Get-Content $cfg -Raw | ConvertFrom-Json
$j.agents.defaults.sandbox.mode = "off"
$j | ConvertTo-Json -Depth 100 | Set-Content $cfg
现象1:AI无响应
bash复制# 诊断流程:
openclaw doctor # 基础检查
openclaw status --all # 组件状态
openclaw logs --follow # 实时日志
现象2:插件加载失败
bash复制# 处理步骤:
openclaw plugins list # 查看已安装插件
openclaw plugins rebuild # 重建插件索引
openclaw plugins install 插件名 --force # 强制重装
启用网关认证:
bash复制openclaw config set gateway.auth.enabled true
openclaw config set gateway.auth.token "你的安全令牌"
API调用时需携带认证头:
bash复制curl -H "Authorization: Bearer 你的令牌" http://localhost:18789/api/v1/status
生产环境部署建议:
示例Nginx配置:
nginx复制server {
listen 443 ssl;
server_name yourdomain.com;
ssl_certificate /path/to/cert.pem;
ssl_certificate_key /path/to/key.pem;
location / {
proxy_pass http://127.0.0.1:18789;
proxy_set_header Authorization "Bearer 你的令牌";
}
}
敏感配置加密:
bash复制openclaw config set --secure db.password "你的密码"
加密后的配置会以secure:前缀存储在配置文件中,只能通过OpenClaw CLI解密读取。
量化模型:使用4-bit量化减小内存占用
bash复制openclaw config set models.quantization 4bit
模型缓存:启用磁盘缓存加速加载
bash复制openclaw config set models.cache.enabled true
openclaw config set models.cache.dir "/path/to/cache"
批处理请求:合并处理相似请求
bash复制openclaw config set agents.batch.enabled true
openclaw config set agents.batch.size 8
监控内存使用:
bash复制openclaw metrics --watch memory
配置内存限制:
bash复制# 单个Agent内存限制(MB)
openclaw config set agents.defaults.resources.memory 2048
# 全局内存阈值(超过后自动清理)
openclaw config set system.memory.threshold 80%
创建专用功能Agent:
bash复制openclaw agent create --name email-agent --model claude-3-sonnet
配置路由规则:
bash复制openclaw config set routers.rules '[{
"match": {"intent": "email"},
"route": ["email-agent"]
}]'
配置智能知识库:
bash复制# 建立索引
openclaw index create --name my-knowledge --path ~/Documents
# 查询知识
openclaw agent --message "根据我的文档,总结机器学习要点"
邮件自动处理示例:
bash复制# 安装邮件插件
openclaw plugins install @openclaw/email
# 配置自动规则
openclaw rules add --name "重要邮件提醒" --pattern "urgent OR important" --action "notify slack"
通过Home Assistant集成:
bash复制# 安装HA插件
openclaw plugins install @openclaw/homeassistant
# 语音控制灯光
openclaw agent --message "把客厅灯光调为50%亮度"
典型插件结构:
code复制my-plugin/
├── package.json
├── src/
│ ├── index.ts # 主入口
│ ├── types.ts # 类型定义
│ └── assets/ # 静态资源
├── test/ # 测试代码
└── openclaw.plugin.json # 插件清单
关键生命周期事件:
typescript复制export default {
onInstall: async () => { /* 安装逻辑 */ },
onLoad: async () => { /* 加载逻辑 */ },
onUnload: async () => { /* 卸载逻辑 */ },
onConfigChange: async (newConfig) => { /* 配置变更处理 */ }
}
仪表盘UI扩展:
typescript复制// 注册新路由
dashboard.routes.register({
path: '/my-plugin',
component: MyComponent
})
// 添加侧边栏项
dashboard.navigation.add({
id: 'my-plugin',
title: '我的插件',
icon: 'extension',
path: '/my-plugin'
})
克隆仓库:
bash复制git clone https://github.com/openclaw/openclaw.git
cd openclaw
安装依赖:
bash复制pnpm install
开发模式运行:
bash复制pnpm dev
自定义通信协议:
增强Agent能力:
分布式部署:
代码风格要求:
安装VS Code扩展:
bash复制openclaw plugins install @openclaw/vscode
常用开发命令:
bash复制# 生成代码片段
openclaw agent --message "根据当前文件生成单元测试"
# 解释复杂代码
openclaw agent --message "解释这个函数的实现原理" --file ./src/utils.ts
官方Docker镜像:
bash复制docker pull openclaw/core:latest
典型docker-compose配置:
yaml复制version: '3'
services:
openclaw:
image: openclaw/core:latest
ports:
- "18789:18789"
volumes:
- ./data:/root/.openclaw
environment:
- NODE_ENV=production
GitHub Actions示例:
yaml复制name: Code Review
on: [pull_request]
jobs:
review:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- run: npm install -g openclaw
- run: openclaw agent --message "审查这次代码变更" --diff ${{ github.event.pull_request.diff_url }}
| 特性 | OpenClaw | ChatGPT | Claude | Copilot |
|---|---|---|---|---|
| 数据本地化 | ✓ | ✗ | ✗ | ✗ |
| 可扩展性 | ✓ | ✗ | ✗ | △ |
| 开源 | ✓ | ✗ | ✗ | ✗ |
| 多平台支持 | ✓ | ✓ | ✓ | ✓ |
| 私有化部署 | ✓ | ✗ | ✗ | ✗ |
适合OpenClaw的场景:
其他方案更优的情况:
根据社区讨论,重点发展方向包括:
热门插件方向:
值得尝试的扩展方向:
入门教程:
openclaw tutorial)进阶书籍:
必备工具链:
效率工具: