← 返回
数据分析 中文

Token Counter

Track and analyze OpenClaw token usage across main, cron, and sub-agent sessions with category, client, model, and tool attribution. Use when the user asks where tokens are being spent, wants daily/weekly token reports, needs per-session drilldowns, or is planning token-cost optimizations and needs evidence from transcript data.
追踪并分析OpenClaw在各主进程、定时任务和子代理会话中的Token使用情况,按类别、客户端、模型和工具归因。适用于用户询问Token消耗来源、需每日/每周Token报告、需按会话细化分析,或计划优化Token成本并需要从对话记录中获取证据。
mkhaytman87
数据分析 clawhub v1.0.0 1 版本 99764.3 Key: 无需
★ 2
Stars
📥 1,230
下载
💾 19
安装
1
版本
#latest

概述

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:

$OPENCLAW_SKILLS_DIR/token-counter/scripts/token-counter --period 7d

Common Commands

1) Basic report:

$OPENCLAW_SKILLS_DIR/token-counter/scripts/token-counter --period 7d

2) Focus on selected breakdowns:

$OPENCLAW_SKILLS_DIR/token-counter/scripts/token-counter \
  --period 1d \
  --breakdown tools,category,client

3) Analyze one session:

$OPENCLAW_SKILLS_DIR/token-counter/scripts/token-counter \
  --session agent:main:cron:d3d76f7a-7090-41c3-bb19-e2324093f9b1

4) Export JSON:

$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:

$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:

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.

版本历史

共 1 个版本

  • v1.0.0 当前
    2026-03-29 04:31 安全 安全

安全检测

腾讯云安全 (Keen)

安全,无风险
查看报告

腾讯云安全 (Sanbu)

安全,无风险
查看报告

🔗 相关推荐

data-analysis

Data Analysis

ivangdavila
{"answer":"数据分析与可视化。查询数据库、生成报告、自动化电子表格,将原始数据转化为清晰可行的见解。适用于:(1) 您……"}
★ 198 📥 64,965
content-creation

Awwwards Design

mkhaytman87
运用高级动画、创意交互和独特视觉体验,打造获奖且令人难忘的网站。适用于作品集、代理展示、产品发布等需要惊艳效果的项目。
★ 11 📥 4,816
data-analysis

A股量化 AkShare

mbpz
A股量化数据分析工具,基于AkShare库获取A股行情、财务数据、板块信息等。用于回答关于A股股票查询、行情数据、财务分析、选股等问题。
★ 164 📥 59,799