- Author: Daniel Li
- Copyright © Daniel Li. All rights reserved.
Feature Overview
Automatically tally the local OpenClaw instance's token consumption and Agent work output every day, format it, and write it to Feishu Bitable.
Instance Mapping
| Instance | CEO Agent | Reporter |
|---|---|---|
| aa (local) | Xiao a (main) | Daniel |
| Peter Mini | Xiao Tu (xiaotu) | Peter |
| Xiao m | Xiao m bot | Xiao m |
Execution Flow
Step 1: Scan JSONL Logs
Scan incremental data for the day in ~/.openclaw/agents/*/sessions/*.jsonl .
Each assistant message carries a usage object:
{
"usage": {
"input": 27813,
"output": 246,
"cacheRead": 6720,
"cacheWrite": 0,
"totalTokens": 34779,
"cost": {
"input": 0, "output": 0,
"cacheRead": 0, "cacheWrite": 0,
"total": 0
}
}
}
Step 2: Aggregate by Agent + Model
Focus on tracking 4 models (other models are grouped under "Other"):
| Model | Matching Rule |
|---|---|
| opus4.6 | claude-opus-4-6 (xingsuancode, xingjiabiapi) |
| glm-5 | zai/glm-5 |
| minimax-M2.5 | minimax/MiniMax-M2.5 |
| gemini-3-pro | gemini-3-pro (xingjiabiapi) |
Step 3: Format Token Details
opus4.6: input 320K / output 18K / cache 82% / $4.2
glm-5: input 1.2M / output 85K / cache 78% / $0.3
minimax-M2.5: input 200K / output 12K / cache 0% / $0.1
gemini: — (当日未使用)
cache% = cacheRead / (input + cacheRead + cacheWrite) × 100
Step 4: Collect Output
Summarize each agent's work summary for the day, format:
code: KGKB工厂30/30完成, 5平台发布脚本 | content: 小红书×2, 选题推荐 | ops: cron改造, 服务器巡检
Output collection methods:
- Read the day's memory file
~/clawd/memory/$(date +%Y-%m-%d).md - Parse
## Agent名sections or keyword matching - If there is no memory file, infer from a summary of the last user/assistant message in the JSONL
Step 5: Write to Feishu Bitable
Use the lark-mcp tool to write to Bitable:
| Field | Type | Filled By | Description |
|---|---|---|---|
| Employee Name | Text | config | Hardcoded in config.json person |
| TokenDetails | Text | Script statistics | 4-model formatted text |
| Output | Text | Script statistics | Each agent's work summary for the day |
| Personal Summary | Text | Filled by person | Manually filled by employee (leave blank) |
| Rating | Single select | Selected by management | Excellent/Good/Fail (leave blank) |
| Time | Date | Script automatic | Current date |
Feishu API
- Reference skill:
~/clawd/skills/feishu-automation/SKILL.md - Tool prefix:
mcp__lark-mcp_* - Add record:
mcp__lark-mcp_createRecord - Query record:
mcp__lark-mcp_listRecords
Script Usage
# 统计当日 Token(只看数据,不上报)
python scripts/report.py --scan-only
# 统计 + 上报飞书
python scripts/report.py --report
# 指定日期
python scripts/report.py --date 2026-03-17 --scan-only
# 使用指定配置
python scripts/report.py --config /path/to/config.json --report
Cron Configuration Suggestions
{
"name": "📊 每日 Token 报告 + 飞书上报",
"schedule": { "kind": "cron", "expr": "0 23 * * *", "tz": "Asia/Shanghai" },
"payload": {
"kind": "agentTurn",
"message": "执行每日 Token 报告任务:\n1. 运行 python3 ~/clawd/skills/token-reporter/scripts/report.py --scan-only\n2. 查看输出,确认数据合理\n3. 运行 python3 ~/clawd/skills/token-reporter/scripts/report.py --report\n4. 确认飞书写入成功后,用 message(action=send, channel=telegram, target=-1003890797239) 简要汇报\n5. 如果失败,报告错误原因"
}
}
Configuration
During installation, copy config.example.json → config.json and fill in:
{
"person": "Daniel",
"instance": "aa",
"lark_app_id": "cli_a83467f9ecba5013",
"bitable_app_token": "your_bitable_token",
"bitable_table_id": "your_table_id"
}
File Structure
token-reporter/
├── SKILL.md
├── config.example.json # 配置模板(安装时复制为 config.json)
├── scripts/
│ └── report.py # 核心统计脚本
└── references/
└── jsonl-structure.md # JSONL 数据结构参考
Error Handling
| Error | Handling |
|---|---|
| Corrupted JSONL file | Skip that line, log a warning |
| No data for the day | Report "no data for the day" |
| Feishu API failure | Retry 3 times; after failure, cache the result locally |
| config.json does not exist | Prompt to copy config.example.json |
| Memory file does not exist | Output marked as "no record" |