Offline token and cost reporting for local OpenClaw session logs.
openclaw-token-stats is a small OpenClaw skill + script bundle for turning raw session jsonl logs into practical token and cost reports.
It is built for questions like:
- How many tokens did OpenClaw burn today?
- Which model caused the spike?
- How much of the total came from cache?
- What did the last day / week / month cost?
It reads local logs only. It does not rely on the OpenClaw UI and does not upload usage data anywhere.
-
scripts/openclaw_token_stats.py
Aggregate token / cost usage from local session logs. -
scripts/openclaw_token_report.py
Generate daily / weekly / monthly Markdown reports. -
SKILL.md
AgentSkill entry point for OpenClaw usage. -
references/
Supporting notes for observed fields and cron prompts.
- Reads OpenClaw session logs under
~/.openclaw/agents/<agent>/sessions/*.jsonl* - Aggregates usage fields such as:
inputoutputcacheReadcacheWritetotalTokens
- Aggregates provider-reported cost fields when present:
usage.cost.inputusage.cost.outputusage.cost.cacheReadusage.cost.cacheWriteusage.cost.total
- Breaks usage down by:
- model
- provider
- session file
- Generates chat-ready daily / weekly / monthly reports
OpenClaw logs already contain useful accounting data, but raw logs are annoying to reason about at speed.
This project is for the practical layer in between:
- daily accounting
- anomaly detection
- model cost observation
- “what just happened?” debugging
The goal is not fancy dashboards. The goal is fast, offline answers.
openclaw-token-stats/
├── README.md
├── LICENSE
├── SKILL.md
├── scripts/
│ ├── openclaw_token_stats.py
│ └── openclaw_token_report.py
├── references/
│ ├── fields.md
│ ├── cron-prompt-daily.txt
│ ├── cron-prompt-weekly.txt
│ └── cron-prompt-monthly.txt
└── examples/
├── sample-daily-report.md
└── sample-weekly-report.md
python3 scripts/openclaw_token_stats.py --agent main --days 1 --by modelpython3 scripts/openclaw_token_stats.py --agent main --days 7 --by providerpython3 scripts/openclaw_token_stats.py --agent main --days 2 --by sessionpython3 scripts/openclaw_token_stats.py --agent main --days 7 --by model --jsonpython3 scripts/openclaw_token_report.py --agent main --period dailypython3 scripts/openclaw_token_report.py --agent main --period weeklypython3 scripts/openclaw_token_report.py --agent main --period monthlyUse the Python scripts directly if you just want local reporting.
Keep SKILL.md, scripts/, and references/ together inside a skill directory if you want another agent instance to trigger and use it as a reusable skill.
- Daily:
examples/sample-daily-report.md - Weekly:
examples/sample-weekly-report.md
This project intentionally prefers the stable view first:
Start with the overall ledger: total usage + top models + cache + cost.
Why:
- overall totals are usually the most stable signal
- per-session drilldown is useful, but should be treated as a debugging view
- “main conversation vs background work” reconstruction is helpful, but not always perfect from logs alone
In other words: total first, drill down second.
This tool is intentionally conservative.
- read local session logs
- sum fields that are already present in those logs
- report cost only when the provider/runtime already returned cost data
- estimate price from public pricing tables
- invent missing cost fields
- guarantee perfect session-role mapping in every OpenClaw setup
- send your logs anywhere
This project is best for:
- OpenClaw users who want offline token accounting
- operators debugging usage spikes
- people running scheduled daily / weekly / monthly summaries
- anyone who wants a lightweight observability layer without building a dashboard first
- Reads local files only
- No external upload path in the reporting scripts
- Best used on a machine where OpenClaw logs are already present
MIT
Usable now.
The current focus is practical observability, not polished visualization. If you want charts later, build them on top of the JSON output instead of bloating the core scripts.