ClawDef — Token Optimization Dashboard for OpenClaw
A local web dashboard that helps you monitor and reduce your OpenClaw token costs.
Features
| Feature | Description |
|---|
| 🧠 Smart Auto-Optimizer | Analyzes usage every 5min, auto-switches to cheapest model based on budget and task complexity |
| 💰 Cost Estimator |
Input a task → see estimated cost per model, one-click switch |
| 📊 Real-time Dashboard | Token/cost tracking, cache hit rate, hourly charts, waste detection |
| 🤖 One-click Model Setup | 8 providers (Zhipu/OpenAI/Claude/DeepSeek/Qwen/Kimi/Gemini/Custom), just fill API Key |
| 💳 Budget Control | Daily/monthly limits with 80% warning and 95% auto-downgrade |
| 🔄 Failover | Auto-detect unhealthy models and switch |
| 🚨 Emergency Controls | Disable all skills or stop Gateway (admin-only, manual trigger) |
| 👥 Multi-user | Admin/Editor/Viewer roles with password auth |
Prerequisites
- - Node.js v18+ (
node --version) - OpenClaw installed and running
- OS: Linux or macOS
Installation
Step 1: Copy files
CODEBLOCK0
Step 2: Install dependencies
CODEBLOCK1
Step 3: Start
CODEBLOCK2
Or use the helper script:
CODEBLOCK3
Step 4: First-run setup
Open http://127.0.0.1:3456 in your browser.
On first run, you'll be prompted to set an admin password.
Optional: Run as a service (Linux with systemd)
The install script copies files only. To run as a persistent service, create a systemd unit manually:
CODEBLOCK4
File Access
This skill reads and writes the following files:
| File/Path | Access | Purpose |
|---|
| INLINECODE1 | Read + Write | Read current model config; write agents.defaults.model.primary (model switching) and skills.entries (skill enable/disable) |
| INLINECODE4 |
Read only | Parse session transcripts for token counting |
|
/tmp/openclaw/*.log | Read only | Parse gateway logs for request tracking |
|
~/.openclaw/workspace/skills/*/SKILL.md | Read only | List installed skills with metadata |
|
<install_dir>/data/clawdef.db | Read + Write | Local SQLite database for dashboard data |
Network Activity
| Destination | Trigger | Data sent |
|---|
| INLINECODE8 | Always | Local web dashboard (served to your browser) |
| INLINECODE9 |
Dashboard load | HTTP GET health check (Gateway status) |
|
127.0.0.1:11612/v1/chat/completions | User sends chat message | Proxied to Gateway |
| User-configured model APIs | Manual health check | Minimal POST to verify API is reachable |
No data is sent to any third-party server. The dashboard UI is served entirely from local files (no CDN).
Security Notes
- - Binding: Listens on
127.0.0.1 only (not externally accessible) - Auth: JWT tokens with bcrypt-hashed passwords, 7-day expiry
- No default password: First-run setup requires creating admin credentials
- No telemetry: No outbound data collection or phone-home
- Dependencies:
express, better-sqlite3, jsonwebtoken, bcryptjs, ws (all well-known packages) - Native module:
better-sqlite3 requires a C++ build step during INLINECODE18
Uninstall
CODEBLOCK5
Supported Providers
Zhipu (智谱) · OpenAI · Anthropic Claude · DeepSeek · Qwen (通义) · Moonshot (Kimi) · Google Gemini · Custom (any OpenAI-compatible API)
License
MIT
ClawDef — OpenClaw 令牌优化仪表盘
一个本地网页仪表盘,帮助您监控并降低 OpenClaw 的令牌成本。
功能
| 功能 | 描述 |
|---|
| 🧠 智能自动优化器 | 每5分钟分析使用情况,根据预算和任务复杂度自动切换到最便宜的模型 |
| 💰 成本估算器 |
输入任务 → 查看每个模型的预估成本,一键切换 |
| 📊 实时仪表盘 | 令牌/成本追踪、缓存命中率、小时级图表、浪费检测 |
| 🤖 一键模型设置 | 8个提供商(智谱/OpenAI/Claude/DeepSeek/通义千问/Kimi/Gemini/自定义),只需填写API密钥 |
| 💳 预算控制 | 每日/每月限额,80%预警和95%自动降级 |
| 🔄 故障转移 | 自动检测不健康模型并切换 |
| 🚨 紧急控制 | 禁用所有技能或停止网关(仅管理员,手动触发) |
| 👥 多用户 | 管理员/编辑者/查看者角色,密码认证 |
前提条件
- - Node.js v18+ (node --version)
- OpenClaw 已安装并运行
- 操作系统:Linux 或 macOS
安装
步骤 1:复制文件
bash
CLAWDEF_DIR=/opt/openclaw-monitor # 或您喜欢的任何目录
SKILL_DIR=~/.openclaw/workspace/skills/clawdef
mkdir -p $CLAWDEFDIR/data $CLAWDEFDIR/public/lib
cp $SKILLDIR/scripts/server.js $CLAWDEFDIR/server.js
cp $SKILLDIR/scripts/package.json $CLAWDEFDIR/package.json
cp $SKILLDIR/public/index.html $CLAWDEFDIR/public/index.html
cp $SKILLDIR/public/lib/chart.min.js $CLAWDEFDIR/public/lib/chart.min.js
步骤 2:安装依赖
bash
cd $CLAWDEF_DIR && npm install --production
步骤 3:启动
bash
node $CLAWDEF_DIR/server.js
或使用辅助脚本:
bash
bash ~/.openclaw/workspace/skills/clawdef/scripts/install.sh
步骤 4:首次运行设置
在浏览器中打开 http://127.0.0.1:3456。
首次运行时,系统会提示您设置管理员密码。
可选:作为服务运行(使用 systemd 的 Linux)
安装脚本仅复制文件。要作为持久服务运行,请手动创建 systemd 单元:
bash
sudo tee /etc/systemd/system/clawdef.service << EOF
[Unit]
Description=ClawDef 令牌优化器
After=network.target
[Service]
Type=simple
ExecStart=$(which node) /opt/openclaw-monitor/server.js
WorkingDirectory=/opt/openclaw-monitor
Restart=on-failure
RestartSec=5
[Install]
WantedBy=multi-user.target
EOF
sudo systemctl daemon-reload
sudo systemctl enable --now clawdef
文件访问
此技能读取和写入以下文件:
| 文件/路径 | 访问权限 | 用途 |
|---|
| ~/.openclaw/openclaw.json | 读取 + 写入 | 读取当前模型配置;写入 agents.defaults.model.primary(模型切换)和 skills.entries(技能启用/禁用) |
| ~/.openclaw/agents//sessions/.jsonl |
只读 | 解析会话记录以进行令牌计数 |
| /tmp/openclaw/*.log | 只读 | 解析网关日志以进行请求追踪 |
| ~/.openclaw/workspace/skills/*/SKILL.md | 只读 | 列出已安装的技能及其元数据 |
|
/data/clawdef.db | 读取 + 写入 | 用于仪表盘数据的本地 SQLite 数据库 |
网络活动
| 目标 | 触发条件 | 发送的数据 |
|---|
| 127.0.0.1:3456 | 始终 | 本地网页仪表盘(提供给您的浏览器) |
| 127.0.0.1:11612/health |
仪表盘加载 | HTTP GET 健康检查(网关状态) |
| 127.0.0.1:11612/v1/chat/completions | 用户发送聊天消息 | 代理到网关 |
| 用户配置的模型 API | 手动健康检查 | 最小 POST 请求以验证 API 是否可达 |
不会向任何第三方服务器发送数据。 仪表盘 UI 完全从本地文件提供(无 CDN)。
安全说明
- - 绑定:仅监听 127.0.0.1(不可从外部访问)
- 认证:使用 bcrypt 哈希密码的 JWT 令牌,7天有效期
- 无默认密码:首次运行设置需要创建管理员凭据
- 无遥测:无出站数据收集或回传
- 依赖项:express、better-sqlite3、jsonwebtoken、bcryptjs、ws(均为知名包)
- 原生模块:better-sqlite3 在 npm install 期间需要 C++ 构建步骤
卸载
bash
如果使用 systemd,停止服务
sudo systemctl stop clawdef && sudo systemctl disable clawdef
删除文件
rm -rf /opt/openclaw-monitor
支持的提供商
智谱 · OpenAI · Anthropic Claude · DeepSeek · 通义千问 · Moonshot (Kimi) · Google Gemini · 自定义(任何兼容 OpenAI 的 API)
许可证
MIT