Documents

Token Usage Tracker

Try it

Track, aggregate, and report OpenClaw token usage and costs across sessions.

What it does

Parse OpenClaw and Codex session JSONL files to extract token usage, aggregate by date/model/session, and generate cost reports across providers.

The skill document

Token Usage Tracker

Parse OpenClaw and Codex session JSONL files to extract token usage, aggregate by date/model/session, and generate cost reports across providers.

When to Use

  • User asks "how many tokens did I use today/this week"
  • User wants to know session costs or model breakdown
  • Budget monitoring and anomaly detection
  • Before/after optimization comparisons

Workflow

  1. Locate sessions — Find .jsonl files in OpenClaw agent sessions and nested Codex rollout sessions
  2. Parse usage — Extract OpenClaw message usage or Codex event_msg/token_count per-turn usage
  3. Aggregate — Group by date, model, session ID
  4. Report — Output summaries, trends, cost estimates

Commands

Parse and aggregate current sessions (OpenClaw + Codex)

python3 ~/.openclaw/skills/token-usage/scripts/parse.py --today

Weekly report with cost estimates

python3 ~/.openclaw/skills/token-usage/scripts/parse.py --week --costs

Report by cron job (daily breakdown per job)

python3 ~/.openclaw/skills/token-usage/scripts/parse.py --week --by-cron

Weekly cron report with costs (JSON output)

python3 ~/.openclaw/skills/token-usage/scripts/parse.py --week --by-cron --costs --json

All-time summary by model

python3 ~/.openclaw/skills/token-usage/scripts/parse.py --all --by-model

Export to JSON for external dashboards

python3 ~/.openclaw/skills/token-usage/scripts/parse.py --week --json > /tmp/token-report.json

Data Format

Sessions are stored as JSONL with lines like:

{"type":"message","message":{"role":"assistant",...},"usage":{"input":1000,"output":500,"totalTokens":1500},...}

Cost Estimation

Uses model pricing from scripts/pricing.json (user-editable). The bundled table includes Kimi, OpenAI/GPT, Anthropic/Claude, and OpenRouter models. Unknown models are reported without a cost estimate rather than silently priced as Kimi.

Default examples (USD per 1M tokens):

  • Kimi k2.7: $0.50/1M input, $2.00/1M output
  • Claude Sonnet 4: $3.00/1M input, $15.00/1M output
  • GPT-4o: $2.50/1M input, $10.00/1M output

Costs are approximate. Cache read/write pricing applied when available.

Important: What "Total" Means

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.

Output Locations

  • Daily summaries: ~/.openclaw/skills/token-usage/logs/YYYY-MM-DD.md
  • Weekly reports: ~/.openclaw/skills/token-usage/logs/week-YYYY-Www.md
  • Raw JSON exports: user-specified or /tmp/token-usage-*.json

Limitations

  • OpenClaw records are parsed from message.usage; Codex rollouts are parsed from payload.info.last_token_usage in token_count events
  • input + output is the new-usage metric; Codex cached input is reported separately as cacheRead
  • Historical sessions before JSONL format are not supported
  • Costs are estimates; actual billing may differ

Related skills

Stores durable facts in a categorized, plain-markdown vault on disk, alongside your agent's built-in memory.

by Iván558 installs18 stars

Generate and edit Draw.io, Mermaid, and Excalidraw diagrams from natural language using a structured JSON spec.

by nssa.io1.0k installs47 stars

Find why your productivity system keeps failing, then apply the smallest fix — capacity math, bottleneck routing, durable local notes.

by Iván855 installs69 stars

Join a video meeting as an AI bot with voice, avatar, and screenshare across four operating modes.

by johnpatternai21 installs8 stars

Fetch raw ad creative, app, ranking, and revenue data from AdMapix as structured JSON.

by fly0pants4.3k installs296 stars

More from space-cadet

Browse all skills

Memory Bank Update Workflow — v6.12 compliant with project-repo awareness. Use when the user invokes $mem-update or asks for this workflow by name. Triggers on "update memory bank", "create edit chunk", "update tasks.md", "update session cache", "memory bank update workflow". NOT for database-native workflows (use mb-db-workflow instead).

by space-cadet2 installs

Memory Bank Template Compliance Cleaner Workflow Use when the user invokes $mem-format or asks for this workflow by name.

by space-cadet1 installs

Global Memory Bank Deep Scan and Task Analysis Workflow — Multi-repo aware. Use when the user invokes $mem-scan or asks for this workflow by name.

by space-cadet1 installs

Initialize a memory bank for a new or existing project following the v6.12 protocol. Use when starting work on a project that lacks memory-bank documentation...

by space-cadet

Combined network + gateway status with VPN info, IP location, and system health

by space-cadet

Record and read Memory Bank state via mb-cli. Use for projects with memory-bank/database/ and a memory_bank.db. Triggers on: db workflow, record session work...

by space-cadet