Token Counter
通过类别、客户端、模型和工具属性跟踪和分析主会话、cron 会话和子代理会话中的 OpenClaw 令牌使用情况。当用户询问代币花在哪里、想要每日/每周代币报告、需要每个会话深入分析或正在计划代币成本优化并需要来自记录数据的证据时使用。
安装 / 下载方式
TotalClaw CLI推荐
totalclaw install totalclaw:mkhaytman87~mkhaytman87-token-countercURL直接下载,无需登录
curl -fsSL https://skills.taituai.com/api/skills/totalclaw%3Amkhaytman87~mkhaytman87-token-counter/file -o mkhaytman87-token-counter.mdGit 仓库获取源码
git clone https://github.com/openclaw/skills/commit/eb59ea13e0132e642c768afcd2b7c1db5d278249## 概述(中文) 通过类别、客户端、模型和工具属性跟踪和分析主会话、cron 会话和子代理会话中的 OpenClaw 令牌使用情况。当用户询问代币花在哪里、想要每日/每周代币报告、需要每个会话深入分析或正在计划代币成本优化并需要来自记录数据的证据时使用。 ## 原文 # Token Counter ## Overview Use this skill to produce token usage reports from local OpenClaw data. It parses session transcripts (`.jsonl`), session metadata, and cron definitions, then reports usage by category, client, tool, model, and top token consumers. ## Quick Start Run: ```bash $OPENCLAW_SKILLS_DIR/token-counter/scripts/token-counter --period 7d ``` ## Common Commands 1) Basic report: ```bash $OPENCLAW_SKILLS_DIR/token-counter/scripts/token-counter --period 7d ``` 2) Focus on selected breakdowns: ```bash $OPENCLAW_SKILLS_DIR/token-counter/scripts/token-counter \ --period 1d \ --breakdown tools,category,client ``` 3) Analyze one session: ```bash $OPENCLAW_SKILLS_DIR/token-counter/scripts/token-counter \ --session agent:main:cron:d3d76f7a-7090-41c3-bb19-e2324093f9b1 ``` 4) Export JSON: ```bash $OPENCLAW_SKILLS_DIR/token-counter/scripts/token-counter \ --period 30d \ --format json \ --output $OPENCLAW_WORKSPACE/token-usage/token-usage-30d.json ``` 5) Persist daily snapshot: ```bash $OPENCLAW_SKILLS_DIR/token-counter/scripts/token-counter \ --period 1d \ --save ``` This writes JSON to: `$OPENCLAW_WORKSPACE/token-usage/daily/YYYY-MM-DD.json` ## Defaults and Data Sources - Sessions index: `$OPENCLAW_DATA_DIR/agents/main/sessions/sessions.json` - Session transcripts: `$OPENCLAW_DATA_DIR/agents/main/sessions/*.jsonl` - Cron definitions: `$OPENCLAW_DATA_DIR/cron/jobs.json` The parser reads assistant `usage` fields for token counts and uses tool-call records for attribution. ## Notes on Attribution - Tool token attribution is heuristic: assistant-message tokens are split across tool calls in that message. - Session `totalTokens` may come from either session index metadata or transcript usage sums (max is used). - Client detection is rules-based (`personal`, `bonsai`, `mixed`, `unknown`) using path/domain/email markers. ## Validation Run: ```bash python3 $OPENCLAW_SKILLS_DIR/skill-creator/scripts/quick_validate.py \ $OPENCLAW_SKILLS_DIR/token-counter ``` ## References See: - `references/classification-rules.md` for category/client detection logic and keyword mapping.