Install
openclaw skills install @baijian/token-stats-skillopenclaw skills install @baijian/token-stats-skillUse token-stats sources to diagnose coverage, token-stats usage for daily collection, and token-stats report range for historical analysis. The CLI reads local agent logs and databases and stores normalized daily reports.
Public distribution: baijian/token-stats.
The release baseline verified on 2026-09-09 is v0.0.2, binary commit c17d30954d39. Check latest release when installing or updating. This repository distributes binaries and documentation, not CLI source code. Its README at the v0.0.2 tag still describes v0.0.1; use the v0.0.2 release notes and matching binary help for current coverage. The skill directory and invocation name are token-stats-skill.
token-stats from PATH. If missing or older than the required feature, install the matching release archive after checksum verification; see the reference for platform selection. The public repository's automatic source archives do not contain the CLI implementation. v0.0.2 has no self-update command.--output json.--agent all for machine-level accounting. Single-agent selectors are codex, claude, openclaw, hermes, opencode, deepseek, workbuddy, and workbuddy-ai; usage itself defaults to codex. The two WorkBuddy applications remain separate sources.usage report refreshes automatically unless --refresh=false is explicit. Historical usage and every report range query read stored records unless --refresh is supplied. Refresh missing days or a requested rebuild; cached all records do not automatically gain newly supported agents.~/.local/data/cycling-health-cli/token-usage/<agent>/<YYYY-MM-DD>.json as the durable daily record store unless the user sets --data-dir.all excludes them. Unsupported or undetected sources are coverage gaps, not verified zero usage. Never estimate missing counters from chat text, credits, or context-window occupancy.Read references/token-recording.md for installation, scheduling, source paths, JSON fields, and attribution limits.
Confirm the CLI:
token-stats version --output json.sources.token-stats sources --output json with the same home overrides as collection. supported means a collector exists; detected only means a source path exists, not that token counters are present or complete. The command checks paths without reading chat contents.Refresh or read the target day:
token-stats usage --agent all --day YYYY-MM-DD --refresh --output jsontoken-stats usage --agent all --day YYYY-MM-DD --output jsontoken-stats report range --agent all --from YYYY-MM-DD --to YYYY-MM-DD --output json--refresh to a range query to rescan and persist every day in that range. Without dates, the range is the latest seven days, including today.Set up periodic recording when requested:
scripts/install-launchd-token-recorder.sh on macOS. Installing the CLI alone does not create a scheduler.scripts/record-token-usage.sh as the scheduler command on other systems.Analyze history:
report range for multi-day totals; use a daily report for session-level investigation.total.totalTokens directly, with inputTokens, cachedInputTokens, cacheWriteTokens, outputTokens, and reasoningOutputTokens as reported breakdowns. Do not add overlapping cache/reasoning fields to the total again.byAgent, byModel, byDay, and byRateLimit where available. Range reports contain days summaries; only daily reports contain sessions.Run the bundled wrapper when this skill folder is available:
AI_TOKEN_AGENT=all ./scripts/record-token-usage.sh
Or call the CLI directly:
token-stats usage --agent all --day "$(date +%F)" --refresh --output json
The CLI writes or overwrites the durable daily record. The wrapper can also keep per-run snapshots when AI_TOKEN_RUN_DIR is set.
Use the bundled installer from the skill directory:
./scripts/install-launchd-token-recorder.sh --interval 1800 --agent all --bin "$HOME/.local/bin/token-stats"
This creates a user LaunchAgent that periodically runs record-token-usage.sh, refreshes today's token-stats daily record, and writes operational logs under ~/Library/Logs/ai-token-ayalysis.
For custom WorkBuddy locations, pass --workbuddy-home PATH and/or --workbuddy-ai-home PATH. See the reference for stopping the task without deleting historical data.
token-stats sources --output json
token-stats usage --agent workbuddy --refresh --output json
token-stats usage --agent workbuddy-ai --refresh --output json
The last two commands require v0.0.2 and write separate daily namespaces. Refresh the requested historical all range after upgrading to include both sources; an upgrade does not migrate cached reports.
For one day:
token-stats usage --agent all --day 2026-07-10 --output json
For a stored date range:
token-stats report range --agent all --from 2026-09-01 --to 2026-09-06 --output json
A missing daily record makes the range query fail with refresh guidance; it is not zero usage. Add --refresh for a first collection or rebuild, including backfilling newly supported agents. Do not sum the all namespace together with individual-agent namespaces, or add repeated per-run snapshots together.
scripts/record-token-usage.sh: scheduler-safe wrapper around token-stats usage.scripts/install-launchd-token-recorder.sh: macOS LaunchAgent installer for periodic local recording.references/token-recording.md: detailed CLI flags, storage layout, scheduling guidance, and analysis notes.