tokenmeter - AI Usage & Cost Tracking for OpenClaw
Track your AI token usage and costs across all providers — locally, privately.
Slash Command Examples
- -
/tokenmeter — show today's dashboard - INLINECODE1 — weekly cost report
- INLINECODE2 — model split analysis
- INLINECODE3 — pull in new usage data
- INLINECODE4 — show API vs subscription savings
Overview
tokenmeter is a CLI tool that tracks LLM API usage and calculates real-time cost estimates. For OpenClaw users on the Claude Max plan, it helps:
- 1. Prove Max plan value - Show what you would have paid on API billing
- Monitor usage patterns - Understand which models you use most
- Catch overages early - Know if you're using expensive models too much
- Unified tracking - Track usage across multiple OpenClaw instances
All data stays local (SQLite at ~/.tokenmeter/usage.db). No telemetry, no cloud sync.
Installation
The bot handles everything automatically.
When first needed, the bot will:
CODEBLOCK0
After first setup: Bot just activates venv and runs commands.
No admin action needed - the bot clones, installs, and configures automatically when you first ask it to check usage or costs.
How the Bot Uses This Tool
When You Ask: "How much did I spend this week?"
Step 1: Bot reads this SKILL.md
- - Skill matching triggers on keywords: "spend", "cost", "usage", "tokens"
- Bot loads this entire file into context
Step 2: Bot checks if tokenmeter exists
CODEBLOCK1
Step 3: Bot imports latest usage
CODEBLOCK2
This reads all OpenClaw session files and logs them to the database.
Step 4: Bot runs the appropriate command
CODEBLOCK3
Step 5: Bot parses the output
CODEBLOCK4
Step 6: Bot responds to you in plain English
"You spent $1,142 this week (API-equivalent). Opus cost $742 (65%), Sonnet cost $400 (35%). Your Max plan ($100/month = ~$25/week) saved you $1,117 this week."
Bot Command Reference
Standard pattern:
CODEBLOCK5
Common commands the bot will use:
# Import latest usage
tokenmeter import --auto
# Quick overview
tokenmeter dashboard
# Weekly breakdown
tokenmeter costs --period week
# Monthly summary
tokenmeter summary --period month
Usage
Quick Commands
CODEBLOCK7
Integration with OpenClaw
Automatic Import (Recommended)
OpenClaw writes token usage to session JSONL files at:
CODEBLOCK8
Step 1: Discover session sources
CODEBLOCK9
This shows all discovered session directories:
- -
.clawdbot/agents/main/sessions/ (OpenClaw) - INLINECODE7 (Claude Code)
- Any other compatible session formats
Step 2: Import all at once
CODEBLOCK10
This will:
- - Parse all discovered session files
- Extract token usage from each LLM call
- Log to tokenmeter with API-equivalent costs
- Skip already-imported entries (idempotent)
- Show total records and cost
Options:
CODEBLOCK11
Recommended: Run tokenmeter import --auto daily via cron or manually after heavy usage.
Manual Logging (Fallback)
If you need to log usage manually:
CODEBLOCK12
Options:
- -
--provider / -p: anthropic, openai, google, azure - INLINECODE11 /
-m: Model name (see tokenmeter models) - INLINECODE14 /
-i: Input tokens - INLINECODE16 /
-o: Output tokens - INLINECODE18 /
-a: Application name (e.g., "openclaw")
Understanding the Data
Model Pricing (as of Feb 2026)
| Token Type | claude-sonnet-4 | claude-opus-4 | claude-3.5-haiku |
|---|
| Input | $3.00/1M | $15.00/1M | $0.80/1M |
| Output |
$15.00/1M | $75.00/1M | $4.00/1M |
|
Cache Write | $3.75/1M | $18.75/1M | $1.00/1M |
|
Cache Read | $0.30/1M | $1.50/1M | $0.08/1M |
Understanding Cache Tokens
What are cache tokens?
OpenClaw (and Claude) use prompt caching to store parts of your conversation in memory. This means you don't send the same context repeatedly.
Two types of cache tokens:
- 1. Cache WRITE tokens - Tokens sent ONCE and stored in cache
- Example: Your entire codebase, documentation, system prompts
- Slightly more expensive than regular input (~25% markup)
- Only paid once, then reused for free (almost)
- 2. Cache READ tokens - Tokens reused from cache
- You're NOT sending these again - Claude reads them from memory
-
90% cheaper than regular input tokens
- This is where massive savings come from
Real example from our usage:
CODEBLOCK13
Without caching, we'd send ~1.2 BILLION tokens as regular input ($3,600+).
With caching: We only pay $307 for those cache reads.
Savings: $3,293 from caching alone this month! 🎉
Reading the Dashboard
CODEBLOCK14
Reading the columns:
- - Input: Fresh tokens sent to Claude
- Output: Tokens Claude generated
- Cache R: Tokens reused from cache (READ)
- Cache W: Tokens written to cache (WRITE)
- Total: Input + Output (regular tokens only)
- Cost: API-equivalent cost
Why Cache R is so large: Every time you continue a conversation, Claude reads your entire context from cache instead of you sending it fresh. Over many turns, this adds up to billions of tokens reused.
Cost breakdown:
- - Regular tokens: Expensive ($3-15 per 1M)
- Cache Write: Slightly more expensive (~25% markup)
- Cache Read: 90% cheaper ($0.30-1.50 per 1M)
This is why the cost stays low despite huge cache numbers.
Comparing to Claude Max Plan
Your Max plan: $100/month flat rate
If tokenmeter shows $800 this month:
- - API-equivalent cost: $800
- Max plan cost: $100
- Savings: $700 ✅
If tokenmeter shows $90 this month:
- - API-equivalent cost: $90
- Max plan cost: $100
- Overpaying by $10 (but you get peace of mind!)
Workflows
Daily Check-In
CODEBLOCK15
Weekly Review
CODEBLOCK16
Look for:
- - Heavy Opus usage (expensive!)
- Unusual spikes
- High output token counts (code generation, long responses)
Monthly Billing Comparison
At month end:
CODEBLOCK17
Compare to your Anthropic invoice:
- - Max plan: $100 flat
- API-equivalent (tokenmeter): $XXX
- Delta = savings (or loss)
Cron Automation (Optional)
Add to your HEARTBEAT.md or run via cron:
CODEBLOCK18
This keeps tokenmeter in sync without manual effort.
Multi-Bot Tracking
If you run multiple OpenClaw instances (e.g., Cheenu + Chhotu):
- 1. Both bots import to tokenmeter on their respective machines
- Each uses
--app flag to distinguish:
tokenmeter log -p anthropic -m claude-sonnet-4 -i 1000 -o 500 --app cheenu
tokenmeter log -p anthropic -m claude-sonnet-4 -i 800 -o 400 --app chhotu
- 3. Nagaconda can aggregate reports from both to see total team usage
Troubleshooting
"tokenmeter: command not found"
Activate the virtual environment:
CODEBLOCK20
Empty dashboard after import
Check:
- 1. OpenClaw session files exist: INLINECODE21
- Import command ran successfully (no errors)
- Database has entries: INLINECODE22
Prices seem wrong
Pricing is based on API rates as of Feb 2026. If Anthropic changes pricing, update tokenmeter/pricing.py or open an issue on GitHub.
Examples
Example 1: Check today's usage
CODEBLOCK21
Analysis: $4.23 today, trending toward ~$30/week. Well within Max plan ($100/mo).
Example 2: Weekly cost breakdown
CODEBLOCK22
Analysis: Using Opus for 40% of costs but only ~7% of token volume. Consider using Sonnet more.
Example 3: Month-end comparison (Real Data - Feb 2026)
CODEBLOCK23
Analysis:
- - API-equivalent cost: $1,246.55
- Max plan cost: $100.00
- Savings: $1,146.55 ✅
Opus usage (59.6% of cost) shows heavy extended-thinking use. Max plan absolutely paid for itself this month!
FAQ
Q: Does tokenmeter send data anywhere?
A: No. Everything is stored locally in ~/.tokenmeter/usage.db. Zero telemetry.
Q: What if I delete the database?
A: You lose history, but can rebuild by re-importing OpenClaw sessions (idempotent).
Q: Can I use this with non-OpenClaw tools?
A: Yes! It supports Claude Code, Cursor, and manual logging for any LLM tool.
Q: Will this slow down OpenClaw?
A: No. Import runs separately and reads logs after-the-fact.
Q: What about cache tokens?
A: tokenmeter includes cache read/write tokens in its calculations (OpenClaw tracks them).
References
- - GitHub: https://github.com/jugaad-lab/tokenmeter
- OpenClaw Docs: https://docs.openclaw.ai
- Anthropic Pricing: https://anthropic.com/pricing
Changelog
2026-02-06 (v2)
- - ✅
tokenmeter scan - Auto-discover session sources - ✅
tokenmeter import --auto - Import all discovered sessions - ✅ Real data example showing $1,146 monthly savings on Max plan
- ✅ Updated workflows with new commands
- ✅ Tested on actual OpenClaw + Claude Code sessions
2026-02-06 (v1)
- - Initial skill creation
- Documented installation and usage
- Added workflow examples
Built to answer the question: "How much is my Max plan really saving me?" 💰
tokenmeter - OpenClaw的AI使用与成本追踪
跨所有提供商追踪您的AI令牌使用量和成本 — 本地化、私密化。
斜杠命令示例
- - /tokenmeter — 显示今日仪表盘
- /tokenmeter how much did we spend this week? — 每周成本报告
- /tokenmeter costs breakdown by model — 模型拆分分析
- /tokenmeter import latest sessions — 拉取新的使用数据
- /tokenmeter compare max plan savings — 显示API与订阅节省对比
概述
tokenmeter 是一个CLI工具,用于追踪LLM API使用情况并计算实时成本估算。对于使用Claude Max计划的OpenClaw用户,它有助于:
- 1. 证明Max计划价值 - 显示在API计费下本应支付的费用
- 监控使用模式 - 了解最常使用的模型
- 及早发现超额使用 - 了解是否过度使用昂贵模型
- 统一追踪 - 跨多个OpenClaw实例追踪使用情况
所有数据保留在本地(~/.tokenmeter/usage.db的SQLite)。无遥测,无云同步。
安装
机器人会自动处理一切。
首次需要时,机器人将:
bash
1. 如果仓库不存在则克隆
if [ ! -d ~/clawd/tokenmeter ]; then
cd ~/clawd
git clone https://github.com/jugaad-lab/tokenmeter.git
fi
2. 如果Python虚拟环境不存在则设置
cd ~/clawd/tokenmeter
if [ ! -d .venv ]; then
python3 -m venv .venv
source .venv/bin/activate
pip install -e .
fi
3. 激活并使用
source .venv/bin/activate
tokenmeter import --auto
首次设置后: 机器人只需激活虚拟环境并运行命令。
无需管理员操作 - 当您首次要求检查使用量或成本时,机器人会自动克隆、安装和配置。
机器人如何使用此工具
当您询问:我这周花了多少钱?
步骤1:机器人读取此SKILL.md
- - 技能匹配在关键词上触发:spend、cost、usage、tokens
- 机器人将整个文件加载到上下文中
步骤2:机器人检查tokenmeter是否存在
bash
if [ ! -d ~/clawd/tokenmeter ]; then
cd ~/clawd
git clone https://github.com/jugaad-lab/tokenmeter.git
cd tokenmeter
python3 -m venv .venv
source .venv/bin/activate
pip install -e .
fi
步骤3:机器人导入最新使用数据
bash
cd ~/clawd/tokenmeter
source .venv/bin/activate
tokenmeter import --auto
这会读取所有OpenClaw会话文件并将其记录到数据库中。
步骤4:机器人运行相应命令
bash
tokenmeter costs --period week
步骤5:机器人解析输出
Model Cost % of Total
────────────────────────────────────────────
anthropic/claude-opus-4 $741.95 65.0%
anthropic/claude-sonnet-4 $400.26 35.0%
────────────────────────────────────────────
Total $1,142.22
步骤6:机器人用通俗语言回复您
您本周花费了1,142美元(API等效)。Opus花费742美元(65%),Sonnet花费400美元(35%)。您的Max计划(100美元/月 ≈ 25美元/周)本周为您节省了1,117美元。
机器人命令参考
标准模式:
bash
cd ~/clawd/tokenmeter && source .venv/bin/activate && tokenmeter [command]
机器人将使用的常用命令:
bash
导入最新使用数据
tokenmeter import --auto
快速概览
tokenmeter dashboard
每周细分
tokenmeter costs --period week
每月摘要
tokenmeter summary --period month
使用方法
快速命令
bash
发现会话来源(OpenClaw、Claude Code等)
tokenmeter scan
导入所有发现的会话
tokenmeter import --auto
预览导入而不写入
tokenmeter import --auto --dry-run
显示今日使用情况
tokenmeter dashboard
每周摘要
tokenmeter summary --period week
按模型划分的成本细分
tokenmeter costs --period month
列出所有支持的模型 + 定价
tokenmeter models
查看近期历史
tokenmeter history --limit 20
与OpenClaw集成
自动导入(推荐)
OpenClaw将令牌使用情况写入会话JSONL文件,位置在:
~/.clawdbot/agents//sessions/.jsonl
步骤1:发现会话来源
bash
cd ~/clawd/tokenmeter
source .venv/bin/activate
tokenmeter scan
这会显示所有发现的会话目录:
- - .clawdbot/agents/main/sessions/(OpenClaw)
- .claude/projects/*/sessions/(Claude Code)
- 任何其他兼容的会话格式
步骤2:一次性全部导入
bash
tokenmeter import --auto
这将:
- - 解析所有发现的会话文件
- 从每次LLM调用中提取令牌使用量
- 以API等效成本记录到tokenmeter
- 跳过已导入的条目(幂等性)
- 显示总记录数和成本
选项:
bash
tokenmeter import --auto --dry-run # 预览而不写入
tokenmeter import --path ~/.clawdbot/agents/main/sessions/ # 导入特定目录
建议: 每天通过cron或手动在高使用量后运行tokenmeter import --auto。
手动记录(备用)
如果需要手动记录使用情况:
bash
tokenmeter log \
--provider anthropic \
--model claude-sonnet-4 \
--input 1500 \
--output 500 \
--app openclaw
选项:
- - --provider / -p:anthropic、openai、google、azure
- --model / -m:模型名称(参见tokenmeter models)
- --input / -i:输入令牌数
- --output / -o:输出令牌数
- --app / -a:应用程序名称(例如openclaw)
理解数据
模型定价(截至2026年2月)
| 令牌类型 | claude-sonnet-4 | claude-opus-4 | claude-3.5-haiku |
|---|
| 输入 | $3.00/1M | $15.00/1M | $0.80/1M |
| 输出 |
$15.00/1M | $75.00/1M | $4.00/1M |
|
缓存写入 | $3.75/1M | $18.75/1M | $1.00/1M |
|
缓存读取 | $0.30/1M | $1.50/1M | $0.08/1M |
理解缓存令牌
什么是缓存令牌?
OpenClaw(和Claude)使用提示缓存将对话部分存储在内存中。这意味着您不必重复发送相同的上下文。
两种类型的缓存令牌:
- 1. 缓存写入令牌 - 一次性发送并存储在缓存中的令牌
- 示例:您的整个代码库、文档、系统提示
- 比常规输入略贵(约25%加价)
- 仅支付一次,然后几乎免费重用
- 2. 缓存读取令牌 - 从缓存中重用的令牌
- 您不再发送这些令牌 - Claude从内存中读取它们
-
比常规输入令牌便宜90%
- 这是大量节省的来源
来自我们使用情况的真实示例:
本月:
常规输入: 119.5K 令牌 ($0.36)
常规输出: 3.8M 令牌 ($57.00)
缓存写入: 157.2M 令牌 ($589.50 - 一次性支付)
缓存读取: 1,024.3M 令牌 ($307.29 - 90%折扣!)
总计:$954.15
如果没有缓存,我们将发送约12亿令牌作为常规输入($3,600+)。
有了缓存:我们仅为这些缓存读取支付$307。
节省: 仅本月缓存就节省了$3,293!🎉
阅读仪表盘
╭─────────────────── tokenmeter ───────────────────╮
│ 今日 $122.42 (396.9K 令牌)