Install
openclaw skills install @space-cadet/token-usageTrack, aggregate, and report OpenClaw token usage and costs across sessions.
openclaw skills install @space-cadet/token-usageParse OpenClaw and Codex session files to extract token usage, aggregate by date/model/session, and generate provider-aware cost reports. Works across OpenClaw storage eras — pre-9.x JSONL, 9.x SQLite, and transitional mixed storage.
.jsonl files in OpenClaw agent sessions and nested Codex rollout sessionstoken_count per-turn usage| Flag | Description | Example |
|---|---|---|
--today | Current calendar day (local timezone) | --today |
--yesterday | Previous calendar day (local timezone) | --yesterday |
--week | Last 7 calendar days | --week |
--days N | Last N calendar days | --days 3 |
--hours N | Rolling window: last N hours | --hours 24 |
--since TIME | Start time (ISO, date, or relative) | --since 24h, --since 2d, --since "2026-07-20T09:00:00" |
--until TIME | End time (ISO, date, or relative) | --until 1h |
--all | All time | --all |
Relative time shorthand: 1h = 1 hour ago, 2d = 2 days ago, 30m = 30 minutes ago.
# Past 24 hours, model breakdown with cost estimates
python3 ~/.openclaw/skills/token-usage/scripts/parse.py --hours 24 --by-model --costs
# Today so far
python3 ~/.openclaw/skills/token-usage/scripts/parse.py --today --by-model --costs
# Yesterday
python3 ~/.openclaw/skills/token-usage/scripts/parse.py --yesterday --by-model --costs
# Since a specific time
python3 ~/.openclaw/skills/token-usage/scripts/parse.py --since "2026-07-20T09:00:00" --by-model --costs
# Last 2 hours
python3 ~/.openclaw/skills/token-usage/scripts/parse.py --since 2h --by-model --costs
python3 ~/.openclaw/skills/token-usage/scripts/parse.py --week --by-cron
python3 ~/.openclaw/skills/token-usage/scripts/parse.py --all --by-model
python3 ~/.openclaw/skills/token-usage/scripts/parse.py --week --json > /tmp/token-report.json
| Flag | Description |
|---|---|
--cache | Include cache read/write columns in report |
--session-detail | Show per-session breakdown with models used |
--json | Output machine-readable JSON |
--costs | Add cost estimates (requires pricing data) |
--today and --yesterday use the local system timezone (Asia/Calcutta / IST by default). This ensures daily reports align with your local day even when cron jobs run at off-UTC hours (e.g., 04:00 IST = 22:30 UTC previous day).
Session files may store model names in short form (k3, k2.7) or long form (kimi/k3). The parser normalizes these for pricing lookup:
k3) → tries k3 then kimi/k3kimi/k3) → direct lookupSessions are stored as JSONL with lines like:
{"type":"message","message":{"role":"assistant",...},"usage":{"input":1000,"output":500,"totalTokens":1500},...}
Uses model pricing from scripts/pricing.json (user-editable). Default prices:
Costs are approximate. Cache read/write pricing applied when available. Unprefixed model names (e.g. k3) are automatically mapped to their full form (kimi/k3) for pricing lookup.
Session files accumulate over time. The ~/.openclaw/agents/main/sessions/ directory can grow to several GB with thousands of files, slowing down reports.
Current usage check:
# Total size and file count
du -sh ~/.openclaw/agents/main/sessions/
ls ~/.openclaw/agents/main/sessions/*.jsonl | wc -l
# Size by month (to identify heavy periods)
ls -l ~/.openclaw/agents/main/sessions/*.jsonl | awk '
{month = substr($6, 1, 3); year = $8; size += $5; count++}
END {printf "Total: %.2f MB across %d files\n", size/1024/1024, count}'
Archiving old sessions:
# Compress sessions older than 30 days (preserves access, saves ~80% space)
find ~/.openclaw/agents/main/sessions/*.jsonl -mtime +30 -exec gzip {} \;
# Move very old sessions to archive (after verifying no longer needed)
mkdir -p ~/.openclaw/agents/main/sessions/archive
find ~/.openclaw/agents/main/sessions/*.jsonl -mtime +90 -exec mv {} ~/.openclaw/agents/main/sessions/archive/ \;
Note: The parser already skips .trajectory.jsonl and temp files, and uses mtime filtering to skip unmodified files when --since is specified.
The script reports input + output tokens as the usage metric. This is the actual new token consumption per turn.
The totalTokens field in session files includes cacheRead (cached context window), which gets re-counted at every turn. Summing totalTokens across messages would massively overcount — a 10K context used for 100 turns would appear as 1M tokens. The script avoids this by only summing input and output.
~/.openclaw/skills/token-usage/logs/YYYY-MM-DD.md~/.openclaw/skills/token-usage/logs/week-YYYY-Www.md/tmp/token-usage-*.jsonmessage.usage or top-level usage)event_msg → token_count → last_token_usage)scripts/pricing.jsoninput + output; cached input is reported separately--since are fast due to mtime filtering