token-ledger

Audit-grade token and cost ledger for OpenClaw. Use when you need to (1) record every model call’s usage (input/output/cache read/cache write/cost) into SQLite, (2) install/manage the ledger watcher LaunchAgent, (3) query ledger.db for daily usage/cost, fixed overhead, or historical billing reconciliation, or (4) generate low-token financial reports from SQL.

Safety Notice

This listing is from the official public ClawHub registry. Review SKILL.md and referenced scripts before running.

Copy this and send it to your AI assistant to learn

Install skill "token-ledger" with this command: npx skills add JonathanJing/token-ledger

Token Ledger (SQLite)

What this skill provides

  • A SQLite ledger at ~/.openclaw/ledger.db with per-call usage rows.
  • A watcher daemon that tails OpenClaw session JSONL files and writes usage into SQLite (near-real-time).
  • Deterministic, low-token SQL-first finance reports (no JSONL rescans).

This skill is designed to be public/reusable: prefer stable paths, versioned pricing (price_versions table), and minimal assumptions.

Canonical usage definitions (do not mix these)

  • input_tokens: uncached input tokens for the call (can be tiny)
  • cache_write_tokens: tokens written to cache (can be huge)
  • cache_read_tokens: tokens read from cache (can be huge)
  • output_tokens: generated tokens
  • total_context_tokens (effective prompt size) = input_tokens + cache_write_tokens + cache_read_tokens

Files & paths

  • SQLite DB: ~/.openclaw/ledger.db
  • Checkpoint: ~/.openclaw/ledger-checkpoint.json
  • Sessions JSONL source: ~/.openclaw/agents/main/sessions/*.jsonl

Skill scripts:

  • scripts/ledger_watcher.py — watcher daemon (supports --once)
  • scripts/ledger_schema.sql — DDL
  • scripts/com.openclaw.token-ledger-watcher.plist — LaunchAgent template

Standard operations (use exec)

1) One-shot backfill (safe)

python3 ~/.openclaw/workspace/skills/token-ledger/scripts/ledger_watcher.py --once

2) Install / start daemon (macOS LaunchAgent)

This renders the plist with your local $HOME (no hard-coded username paths):

python3 ~/.openclaw/workspace/skills/token-ledger/scripts/render_plist.py \
  > ~/Library/LaunchAgents/com.openclaw.token-ledger-watcher.plist
launchctl load ~/Library/LaunchAgents/com.openclaw.token-ledger-watcher.plist
launchctl list | rg token-ledger-watcher

3) Stop daemon

launchctl unload ~/Library/LaunchAgents/com.openclaw.token-ledger-watcher.plist

4) Quick sanity query

sqlite3 ~/.openclaw/ledger.db \
  "select provider, model, count(*) calls, round(sum(cost_total),4) cost from calls where ts >= date('now') group by 1,2 order by cost desc limit 20;"

How to build low-token Finance reports

Preferred flow:

  1. Run SQL queries directly against ledger.db.
  2. Format results with a deterministic template (no long reasoning).
  3. Only if numbers look anomalous: drill into calls for the specific session/model.

For daily reports, use:

  • per-model totals
  • cached vs uncached mix
  • top sessions by cost
  • cost_source breakdown (provider|calculated|local|unknown)

Notes / caveats

  • Provider billing can still exceed ledger totals due to retries/timeouts/streaming interruptions. Ledger is auditable, not magical.
  • Keep pricing versioned. Do not retroactively reprice historical calls unless explicitly requested.

Preset queries (safe)

python3 ~/.openclaw/workspace/skills/token-ledger/scripts/ledger_query.py today
python3 ~/.openclaw/workspace/skills/token-ledger/scripts/ledger_query.py history --days 30
python3 ~/.openclaw/workspace/skills/token-ledger/scripts/ledger_query.py top-sessions --days 7 --limit 20

Deterministic daily report (no LLM)

python3 ~/.openclaw/workspace/skills/token-ledger/scripts/ledger_report_daily.py

Source Transparency

This detail page is rendered from real SKILL.md content. Trust labels are metadata-based hints, not a safety guarantee.

Related Skills

Related by shared tags or category signals.

Security

Web Security Client-Side Scanner 1773654191

Perform a thorough client-side / browser-facing security assessment of a target web application. Use this skill whenever the user asks to pentest, audit, or...

Registry SourceRecently Updated
Security

Cybersecurity & Hacking Events Trader

Trades Polymarket prediction markets on major cyberattacks, ransomware incidents, data breaches, zero-day exploits, and national cybersecurity legislation.

Registry SourceRecently Updated
40Profile unavailable
Security

Skill Reviewer

Use this skill to audit, review, or validate Claude Code skills (.md files in .claude/commands/). Invoke when user wants to check skill quality, cross-platfo...

Registry SourceRecently Updated
1700Profile unavailable
Security

Skill Guard

Skill Security Scanner - Scan for risks before download/use. Use when: installing unknown skills, evaluating third-party code, or security auditing. / Skill安...

Registry SourceRecently Updated
190Profile unavailable