OpenClaw Insight — Usage Guide
CLI tool that analyzes local OpenClaw session history and generates interactive reports with usage statistics, behavior patterns, friction analysis, and improvement suggestions. 100% local — no data leaves your machine.
Installation
One-Click Install (Recommended)
Use the official one-click installation script:
CODEBLOCK0
This script will automatically:
- 1. Detect your operating system and architecture
- Download the appropriate binary release
- Verify the integrity of the downloaded file
- Install it in a suitable location ($HOME/.local/bin by default)
- Make the command available in your PATH
Install Specific Version
To install a specific version (e.g., v1.0.0):
CODEBLOCK1
From Source
For development or if you want to build from source:
CODEBLOCK2
CLI Usage
CODEBLOCK3
Options
| Option | Default | Description |
|---|
| INLINECODE0 | INLINECODE1 | Number of days to analyze |
| INLINECODE2 |
200 | Maximum sessions to process |
|
-a, --agent <id> | auto-detect | Agent ID to analyze |
|
-s, --state-dir <path> |
~/.openclaw | OpenClaw state directory |
|
-o, --output <path> |
~/.openclaw/usage-data/report.html | Output file path |
|
-f, --format <fmt> |
html | Output format:
html or
json |
|
--no-open | — | Don not auto-open the report in browser |
|
-v, --verbose | — | Enable verbose output |
What the Report Includes
Usage Statistics
- - Sessions: total count, daily average, activity streaks
- Tokens: input/output breakdown, cache hit rates, cost estimation
- Temporal: daily activity charts, peak hours identification
- Channels: per-channel session counts and token efficiency
- Models: model diversity, per-model cache performance
Behavior Patterns
Automatically detects: peak hours, channel preferences, session duration profiles, cache utilization efficiency, model diversity, and tool usage preferences. Each pattern has an impact level (high / medium / low).
Friction Events
Identifies pain points in your sessions:
| Type | Description |
|---|
| INLINECODE15 | Excessive output relative to input |
| INLINECODE16 |
Repeatedly hitting context window limits |
|
abandoned_session | Started but barely used sessions |
|
underutilized_cache | Large sessions with zero cache hits |
|
context_overflow | Repeated context window exhaustion |
|
single_message_sessions | One-shot interactions with high overhead |
Improvement Suggestions
Prioritized recommendations across these categories:
- - Token Efficiency — cache optimization, verbosity control, batching
- Channel Optimization — multi-channel access, per-channel efficiency
- Model Selection — routing simple tasks to cheaper models
- Context Management — conversation splitting, token budgets
- Scheduling — usage pattern optimization
- Memory Utilization — cross-session context retention
- Feature Discovery — underused OpenClaw capabilities
- Workflow Improvement — conversation depth, specification clarity
Each suggestion includes impact, effort, detailed explanation, and optional config snippets.
Data Sources
The tool reads from OpenClaw local state directory (read-only, never modifies data):
CODEBLOCK4
JSON Output Structure
When using --format json, the report contains:
CODEBLOCK5
Common Scenarios
| User Request | Command |
|---|
| Show my stats | INLINECODE22 |
| How much am I spending? |
openclaw-insight --format json then read
summary.estimatedCostUsd |
| Why are my sessions slow? | Run analysis then focus on friction events |
| Compare my channels | Run analysis then present
channelStats |
| Report for last week |
openclaw-insight --days 7 |
| How can I use OpenClaw better? | Run analysis then present top suggestions |
Troubleshooting
| Problem | Fix |
|---|
| No agents found | Verify ~/.openclaw exists and contains agent data |
| No sessions in last N days |
Increase
--days value |
| Empty channel/model stats | OpenClaw version may be too old |
| Build errors | Upgrade to Node.js >= 22 |
Development
CODEBLOCK6
OpenClaw Insight — 使用指南
CLI工具,用于分析本地OpenClaw会话历史,生成包含使用统计、行为模式、摩擦分析和改进建议的交互式报告。100%本地运行——数据不会离开你的设备。
安装
一键安装(推荐)
使用官方一键安装脚本:
bash
curl -fsSL https://raw.githubusercontent.com/linsheng9731/openclaw-insight/main/install.sh | bash
该脚本将自动:
- 1. 检测你的操作系统和架构
- 下载相应的二进制发布版本
- 验证下载文件的完整性
- 将其安装到合适的位置(默认在$HOME/.local/bin)
- 使命令在你的PATH中可用
安装特定版本
要安装特定版本(例如v1.0.0):
bash
curl -fsSL https://raw.githubusercontent.com/linsheng9731/openclaw-insight/main/install.sh | bash -s -- --version v1.0.0
从源码安装
用于开发或从源码构建:
bash
git clone https://github.com/linsheng9731/openclaw-insight.git
cd openclaw-insight
npm install && npm run build
CLI使用
bash
默认:分析最近30天,在浏览器中打开HTML报告
openclaw-insight
分析最近7天
openclaw-insight --days 7
JSON输出
openclaw-insight --format json --output report.json
指定代理 + 自定义输出
openclaw-insight --agent my-agent --output ~/Desktop/insight.html
详细模式,不自动打开
openclaw-insight --verbose --no-open
选项
| 选项 | 默认值 | 描述 |
|---|
| -d, --days <n> | 30 | 要分析的天数 |
| -m, --max-sessions <n> |
200 | 要处理的最大会话数 |
| -a, --agent
| 自动检测 | 要分析的代理ID |
| -s, --state-dir | ~/.openclaw | OpenClaw状态目录 |
| -o, --output | ~/.openclaw/usage-data/report.html | 输出文件路径 |
| -f, --format | html | 输出格式:html或json |
| --no-open | — | 不自动在浏览器中打开报告 |
| -v, --verbose | — | 启用详细输出 |
报告包含内容
使用统计
- - 会话:总数、日均数、活跃连续天数
- 令牌:输入/输出分解、缓存命中率、成本估算
- 时间:每日活动图表、高峰时段识别
- 频道:各频道会话数和令牌效率
- 模型:模型多样性、各模型缓存性能
行为模式
自动检测:高峰时段、频道偏好、会话时长分布、缓存利用效率、模型多样性和工具使用偏好。每个模式都有影响等级(高/中/低)。
摩擦事件
识别会话中的痛点:
| 类型 | 描述 |
|---|
| hightokenwaste | 相对于输入,输出过多 |
| excessive_compactions |
反复达到上下文窗口限制 |
| abandoned_session | 已开始但几乎未使用的会话 |
| underutilized_cache | 大型会话但缓存命中率为零 |
| context_overflow | 反复耗尽上下文窗口 |
| singlemessagesessions | 单次交互但开销高 |
改进建议
按类别排列的优先级建议:
- - 令牌效率 — 缓存优化、冗长控制、批处理
- 频道优化 — 多频道访问、各频道效率
- 模型选择 — 将简单任务路由到更便宜的模型
- 上下文管理 — 对话拆分、令牌预算
- 调度 — 使用模式优化
- 内存利用 — 跨会话上下文保留
- 功能发现 — 未充分利用的OpenClaw功能
- 工作流改进 — 对话深度、规范清晰度
每条建议包括影响、工作量、详细说明和可选的配置片段。
数据源
该工具从OpenClaw本地状态目录读取数据(只读,从不修改数据):
~/.openclaw/
agents/{agentId}/
sessions/
sessions.json # 会话元数据索引
{sessionId}.jsonl # 每个会话的对话记录
JSON输出结构
使用--format json时,报告包含:
InsightReport {
generatedAt, periodStart, periodEnd, daysAnalyzed,
summary — 聚合统计(会话、令牌、成本、连续天数等)
dailyActivity — 每日分解
hourlyDistribution — 24小时活动热力图
channelStats — 各频道指标
modelStats — 各模型指标
sessionAnalyses — 详细的每个会话数据
patterns — 检测到的行为模式
frictions — 摩擦事件
suggestions — 改进建议
}
常见场景
| 用户请求 | 命令 |
|---|
| 显示我的统计信息 | openclaw-insight |
| 我花了多少钱? |
openclaw-insight --format json 然后读取 summary.estimatedCostUsd |
| 为什么我的会话很慢? | 运行分析,然后关注摩擦事件 |
| 比较我的频道 | 运行分析,然后查看 channelStats |
| 上周的报告 | openclaw-insight --days 7 |
| 如何更好地使用OpenClaw? | 运行分析,然后查看顶部建议 |
故障排除
| 问题 | 解决方法 |
|---|
| 未找到代理 | 确认 ~/.openclaw 存在并包含代理数据 |
| 最近N天内没有会话 |
增加 --days 值 |
| 频道/模型统计为空 | OpenClaw版本可能过旧 |
| 构建错误 | 升级到Node.js >= 22 |
开发
bash
npm install # 安装依赖
npm run build # 构建
npm run dev # 开发模式
npm test # 运行测试
npm run clean # 清理构建产物