token-stats-reporter
by @sinoslug
生成 Token 使用统计和参考费用报告。支持 Anthropic Claude Opus 4.7 和 OpenAI GPT-5.5 两种参考费率,默认 Opus 4.7,输出"省了多少"的满足感。 适用场景:用户要求查看 Token 使用统计、需要展示"本应多少费用"、生成每条消息末尾的 Token 统计行。...
clawhub install token-stats-reporter📖 About This Skill
name: token-stats-reporter description: Generate and append accurate token/cost statistics in replies with a reproducible local algorithm (snapshot+incremental log aggregation + dedupe). Use when users ask for token usage, when channel policy requires token stats in every message, or when periodic reports need transparent model/cost attribution.
Token Stats Reporter
Use this skill to produce a single, consistent token line at the end of every user-facing message.
Workflow
1. Run the bundled reporter script:
- python3 /home/admin/.openclaw/workspace/skills/token-stats-reporter/scripts/token-show.py
2. Append exactly one returned line to the end of the reply.
3. Do not modify numbers manually.
Output format (exact)
📊 Token:
Algorithm guarantees (must preserve)
~/.openclaw/agents/main/sessions/*.jsonl*type=message
- message.role=assistant
- has text content
- has usage
message.id (fallback composite key only if id missing)Asia/Shanghai)memory/token-agg-state.json
- Per-file offset tracking for incremental scans
- Truncation/reset-safe fallback (offset reset when file shrinks)
usage.cost.totalmessage.modelReliability rules
session_status and explicitly label as fallback.v1.2.0 Send Gate (fail-closed)
Use this mandatory gate to avoid hand-written token lines:
1. Build token line first (must run script):
- python3 /home/admin/.openclaw/workspace/skills/token-stats-reporter/scripts/token-show.py
2. Validate token line before sending:
- must contain 📊 Token:
- must contain 模型:
- model must NOT be delivery-mirror
3. Append token line to message body, then send.
4. If step 1 or 2 fails: block sending (do not handwrite numbers).
5. Allowed fallback text only when blocked:
- 📊 Token: 统计暂不可用(脚本失败,已拦截手填)
Portability rule (for other assistants)
When installing on another assistant instance, use this skill's bundled script path as the source of truth. Do not depend on external ad-hoc scripts with unknown local modifications.