Run it, pick an agent, see the stats. Every time.
You have multiple AI assistants on your machine (Hermes, Claude Code, CodeX, OpenClaw…).
agent-usage-stats lets you choose one and see how many tokens it's consuming.
⚠️ Important: this tool only reads local agent data on this machine. If you run agents on different PCs or servers, each machine stores its own data and needs its own installation ofagent-usage-stats. Cross-machine statistics are not supported.All statistics are queried based on the specific agent you select, not a global total.
agent-usage-stats reads local data directly — works across agents, models, and platforms. Zero dependencies, pure Python stdlib.
| Feature | Command | Description |
|---|---|---|
| Token stats — by time range | agent-usage-stats -a hermes --month |
Multi-agent (Hermes / Claude Code / CodeX / OpenClaw), multi-model. Input/output/cache tokens + call counts, only models with data |
| Live monitor — context tracking | agent-usage-stats -a hermes --watch |
Per-round delta + cumulative, warns above 90%. macOS / Linux / Windows |
| Compare — side-by-side periods | --compare --a yesterday --b today |
Any time range, multi-model comparison with diff column |
| Export — XLSX / JSON | --export |
Multi-agent, multi-period combinations. Interactive directory picker |
| Model detect — proxy API verification | agent-usage-stats -a <name> |
Auto-detects 69 models from 13 providers by actual API response name |
Before installing agent-usage-stats, make sure you have these:
ai-ai-agent-usage-stats 本身是纯 Python 脚本,依赖标准库(含 tomllib 用于模型价格配置),不需要额外 pip 装任何包。
# Check (Windows users: use python --version)
python3 --version
# If missing → https://www.python.org/downloads/agent-usage-stats is distributed via ClawHub CLI, a Node.js command-line tool.
# Check
node --version
# If missing → https://nodejs.org (get the LTS version)Node.js includes npm, which is used to install ClawHub.
# Install
npm install -g clawhub
# Verify
clawhub -V # show version💡 On macOS with Homebrew-installed Node.js,
npm install -g clawhubputs it at/opt/homebrew/bin/clawhub, which is usually already in your PATH.
💡 If you're in China and npm is slow, use the npmmirror registry:
npm install -g clawhub --registry=https://registry.npmmirror.com
After meeting the requirements above, two commands:
macOS / Linux:
cd ~
clawhub install ai-agent-usage-stats
python3 ~/skills/ai-agent-usage-stats/agent-usage-stats.py setupWindows (PowerShell):
cd ~
clawhub install ai-agent-usage-stats
python $HOME\skills\ai-agent-usage-stats\agent-usage-stats.py setup
cd ~ensures the skill installs to your home directory (always writable on all OSes). Ifpythonis not found, trypython3(Microsoft Store Python usespython3). If you getcan't open file '...~...', see: PowerShell path expansion.
setupautomatically adds~/.local/binto your system PATH. Open a new terminal for it to take effect.
That's it. Open a new terminal and run agent-usage-stats.
# Check 1: version
agent-usage-stats --version
# Output: agent-usage-stats v2.3.8
# Check 2: list installed agents
agent-usage-stats --list-backends
# Example output:
# ✅ Hermes
# ✅ Claude Code
# ❌ CodeX
# ❌ OpenClaw
# Check 3: view stats for an agent
agent-usage-stats -a hermes
# Example output:
# 📊 Hermes
# deepseek-v4-flash | 上下文 62.4K/1.05M (6.0%) | 入 57.1K | 出 5.4K | 缓 0 | 总计/+缓存 62.4K/62.4K | 调用 13 次If all three checks produce output, installation is successful 🎉
clawhub update ai-agent-usage-stats
agent-usage-stats --version
updatereplaces files in-place — wrapper and PATH carry over, no re-setup required.
💡 Version not changing? Use
--forceto pull the latest:clawhub install ai-agent-usage-stats --force
| What you want to do | Command | Scope |
|---|---|---|
| Check today's token usage | agent-usage-stats --all -t |
All agents |
| Check this month's usage | agent-usage-stats --all -m |
All agents |
| View Claude Code only | agent-usage-stats -a claude-code |
Single agent |
| Real-time monitoring | agent-usage-stats -a claude-code -w |
Single agent |
| Compare last week vs this week | agent-usage-stats -a claude-code --compare --a last-week --b this-week |
Single agent |
| Export to Excel | agent-usage-stats -a claude-code -m -e |
Single / All agents |
| Interactive menu | agent-usage-stats |
Interactive |
| Short | Long | What it does |
|---|---|---|
-a |
--agent |
Pick which agent: hermes / claude-code / codex / openclaw. Use commas for multiple |
-t |
--today |
Today only |
-m |
--month |
This month (1st to today) |
-y |
--year |
This year (Jan 1 to today) |
-w |
--watch |
Live monitor, refreshes every 5 seconds, Ctrl+C to stop |
-e |
--export |
Export to XLSX / CSV / JSON file |
-v |
--version |
Show version number |
-l |
--list-backends |
List installed AI assistants |
--all |
View all agents at once |
Short options can be combined. For example,
-a claude-code -t -emeans "Claude Code only, today, export."
Replace claude-code with your agent (hermes / codex / openclaw).
All history (no time filter):
agent-usage-stats -a claude-codeToday only:
agent-usage-stats -a claude-code -tYesterday:
agent-usage-stats -a claude-code --yesterdayThis month (1st to today):
agent-usage-stats -a claude-code -mThis year (Jan 1 to today):
agent-usage-stats -a claude-code --yearThis week (Monday to today):
agent-usage-stats -a claude-code --weekLast 7 days:
agent-usage-stats -a claude-code --last-7dCustom date range:
# From Jan 1 to May 18
agent-usage-stats -a claude-code --from 2026-01-01 --to 2026-05-18Example output:
📊 Claude Code
deepseek-v4-flash | In 2.02M | Out 77.48K | Cache 8.36M | Total/+Cache 2.1M/10.46M | Calls 349
deepseek-v4-pro | In 4.9M | Out 1.19M | Cache 451.87M | Total/+Cache 6.09M/457.96M | Calls 2348
Subtotal | In 6.93M | Out 1.27M | Cache 460.24M | Total/+Cache 8.2M/468.44M | Calls 2702
────────────────────────────────────
Sub-agents: 17 | Sessions: 20 | Projects: 4
Pick specific agents (comma-separated):
# Hermes and Claude Code, this month
agent-usage-stats -a hermes,claude-code -mAll agents on this machine:
# All history
agent-usage-stats --all
# All agents, today
agent-usage-stats --all -t
# All agents, this month
agent-usage-stats --all -m
# All agents, this year
agent-usage-stats --all --yearagent-usage-stats -l
# or
agent-usage-stats --list-backendsOutput shows which agents are detected (✅) and which are not (❌).
Side-by-side comparison showing input/output/cache/total/total_with_cache/calls for each model, with a delta column.
Yesterday vs today:
agent-usage-stats -a claude-code --compare --a yesterday --b todayLast week vs this week:
agent-usage-stats -a claude-code --compare --a last-week --b this-weekLast month vs this month:
agent-usage-stats -a claude-code --compare --a last-month --b this-monthLast year vs this year:
agent-usage-stats -a claude-code --compare --a last-year --b this-yearTwo custom dates:
# Two specific days
agent-usage-stats -a claude-code --compare --a 2026-01-01 --b 2026-01-15
# Two date ranges (connected with ~)
agent-usage-stats -a claude-code --compare --a 2026-01-01~2026-01-07 --b 2026-01-08~2026-01-14Supported labels: today / yesterday / this-week / last-week / this-month / last-month / this-year / last-year / YYYY-MM-DD / YYYY-MM-DD~YYYY-MM-DD
Watch token usage in real time as you chat with the agent. Press Ctrl+C to stop and see a summary.
Default 5-second refresh:
agent-usage-stats -a claude-code -wCustom interval (e.g., 2 seconds):
agent-usage-stats -a claude-code -w 2Watch mode only supports a single agent.
Three formats: XLSX (Excel), CSV, JSON. Yearly exports automatically split by month.
Export a single agent:
# All history (prompts for format and directory)
agent-usage-stats -a claude-code -e
# Today
agent-usage-stats -a claude-code -t -e
# This month
agent-usage-stats -a claude-code -m -e
# This year (auto-split by month)
agent-usage-stats -a claude-code --year -e
# Specify output directory directly
agent-usage-stats -a claude-code -m -e ~/DesktopExport all agents:
# All agents, this month
agent-usage-stats --all -m -e
# All agents, this year (monthly columns, single sheet)
agent-usage-stats --all --year -eChoosing format non-interactively:
# XLSX (press Enter = default)
echo 1 | agent-usage-stats -a claude-code -m -e ~/Desktop
# CSV
echo 2 | agent-usage-stats -a claude-code -m -e ~/Desktop
# JSON
echo 3 | agent-usage-stats -a claude-code -m -e ~/DesktopRun without arguments to pick an agent from a menu:
agent-usage-statsShow help (all commands):
agent-usage-stats --helpShow current version:
agent-usage-stats -v
# or
agent-usage-stats --versionUpdate to the latest version:
agent-usage-stats updateIf the version doesn't change after update, force reinstall:
clawhub install ai-agent-usage-stats --forceUninstall agent-usage-stats:
# Step 1: Remove wrapper + PATH
agent-usage-stats --uninstall
# Step 2: Remove skill files
clawhub uninstall ai-agent-usage-stats| Agent | Snapshot | Time range |
|---|---|---|
| Hermes | Context % + input/output/cache + calls + session count | Total + session count |
| Claude Code | Total + input/output/cache + calls + sub-agents/projects | Same |
| CodeX | Total + thread count | Same |
| OpenClaw | Context % + input/output/cache + calls | Total + calls |
| Agent | Reads from |
|---|---|
| Hermes | ~/.hermes/state.db → sessions table |
| Claude Code | ~/.claude/projects/**/*.jsonl |
| CodeX | ~/.codex/state_*.sqlite → threads table |
| OpenClaw | ~/.openclaw/agents/main/sessions/ |
When your agent runs inside WSL2, agent-usage-stats automatically detects and reads data from the Windows side. Even if Hermes is running (database locked), it reads via wsl.exe internally; output is labeled (WSL).
- WSL distro must be running — open a WSL terminal first
- Username agnostic — auto-detects the WSL user's home directory
- Proxy unaffected — VPN/proxy only affects WSL networking, not local file access
Prefix matching is supported. Unknown models default to 128K.
| Provider | Models | Context |
|---|---|---|
| Anthropic / Claude | claude-opus-4-7, claude-opus-4-5, claude-opus-4, claude-sonnet-4-6, claude-sonnet-4-5, claude-sonnet-4, claude-haiku-4-5, claude-haiku-3.5, claude-3.5-sonnet, claude-3.5-haiku, claude-3-opus, claude-3-sonnet, claude-3-haiku |
200K |
| OpenAI / GPT | gpt-4.1, gpt-4.1-mini, gpt-4.1-nano |
1M |
gpt-4o, gpt-4o-mini, gpt-4-turbo, gpt-4 |
128K | |
o4-mini, o3, o3-mini, o1, o1-pro |
200K | |
| Google / Gemini | gemini-2.5-pro, gemini-2.5-flash, gemini-2.5-flash-lite, gemini-2.0-flash |
1M |
| DeepSeek | deepseek-v4-pro, deepseek-v4-flash, deepseek-v4, deepseek-chat, deepseek-reasoner, deepseek-r1 |
1M |
deepseek-v3 |
128K | |
| Qwen / Alibaba | qwen3, qwen3-coder, qwen2.5-coder, qwen-plus, qwen-max, qwen-turbo |
128K |
| Kimi / Moonshot | moonshot-v1-128k, moonshot-v1-32k, moonshot-v1-8k, kimi-latest |
8K~128K |
| GLM / Zhipu | glm-4-plus, glm-4-long (1M), glm-4-air, glm-4-flash, glm-4, glm-3-turbo |
128K~1M |
| Doubao / ByteDance | doubao-pro-128k, doubao-pro-32k, doubao-lite-32k |
32K~128K |
| ERNIE / Baidu | ernie-4.0-turbo, ernie-4.0, ernie-3.5 |
8K~128K |
| Meta / Llama | llama-4, llama-3.1, llama-3 |
128K |
| Mistral | mistral-large-2, mistral-large, mistral-small |
128K |
| xAI / Grok | grok-3, grok-2 |
128K |
| Yi / 01.AI | yi-large, yi-lightning |
16K~32K |
How much did I spend today?
agent-usage-stats --all --todayThis month — all agents summary
agent-usage-stats --all --monthThis month — all agents export
agent-usage-stats --all --month --exportThis year — all agents export
agent-usage-stats --all --year --exportThis week vs last week
agent-usage-stats -a hermes --compare --a last-week --b this-weekThis month vs last month
agent-usage-stats -a hermes --compare --a last-month --b this-monthWatch consumption in real time
agent-usage-stats -a hermes --watch
# Switch to Hermes, watch tokens update liveMultiple agents + time range
agent-usage-stats -a hermes,claude-code --month# Step 1: Clean up global command + PATH (automatic)
agent-usage-stats --uninstall
# Step 2: Remove skill files
clawhub uninstall ai-agent-usage-stats
--uninstallautomatically removes the wrapper, cleans the PATH entry, and deletes config files. Works on all platforms.
| Platform | Status |
|---|---|
| macOS | ✅ Full support |
| Linux | ✅ Full support |
| Windows | ✅ Supported (.cmd wrapper) |
| Requirement | Details |
|---|---|
| Python | 3.8+ (stdlib only, no pip dependencies) |
| Node.js | Required only for installation (ClawHub CLI) |
Possible cause: network issue or outdated Node.js.
# Check Node.js version (needs v18+)
node --version
# Reinstall ClawHub
npm install -g clawhub
# In China with slow network:
npm install -g clawhub --registry=https://registry.npmmirror.comWhen: setup fails with file not found.
Cause: clawhub install was run from a different directory (not home). Skills are placed under ./skills/ relative to the working directory.
Fix:
cd ~
clawhub install ai-agent-usage-stats --forceThen follow the install steps above. The home directory (~) is always writable on all OSes.
Cause: PowerShell does not expand ~ when passed as a command argument, treating it as a literal directory name.
Error example:
python: can't open file 'C:\\Users\\xxx\\~\\skills\\...': No such file or directory
Fix: use $HOME instead of ~:
# ❌ Wrong
python ~\skills\ai-agent-usage-stats\agent-usage-stats.py setup
# ✅ Correct
python $HOME\skills\ai-agent-usage-stats\agent-usage-stats.py setup
$HOMEis a built-in PowerShell variable that always expands to the current user directory.
Cause 1: Haven't run setup yet → Follow the install steps above.
Cause 2: Ran setup but haven't opened a new terminal → setup writes PATH to system config. Open a new terminal for it to take effect.
Cause 3: setup PATH write failed → Re-run setup and check for errors. If needed, add PATH manually:
macOS (zsh):
echo 'export PATH="$PATH:$HOME/.local/bin"' >> ~/.zshrc
source ~/.zshrcLinux (bash):
echo 'export PATH="$PATH:$HOME/.local/bin"' >> ~/.bashrc
source ~/.bashrcWindows (PowerShell, current session only):
$env:PATH += ';' + "$env:USERPROFILE\.local\bin"macOS / Linux only. Cause: wrapper script lacks execute permission.
chmod +x ~/.local/bin/agent-usage-stats
# Or just re-run setup
python3 ~/skills/ai-agent-usage-stats/agent-usage-stats.py setupWindows users are not affected (
.cmdfiles don't need execute permission).
Cause: agent-usage-stats checks for specific config files. These paths must exist:
| Agent | Detection path |
|---|---|
| Hermes | ~/.hermes/state.db |
| Claude Code | ~/.claude/projects/ |
| CodeX | ~/.codex/state_*.sqlite |
| OpenClaw | ~/.openclaw/agents/main/sessions/sessions.json |
Run agent-usage-stats --list-backends to see what's detected.
Possible causes:
- Agent is installed but never used → use it first, then check again
- Data file path is wrong → confirm with
agent-usage-stats --list-backends - Time range has no data → if using
--todayor--from, check that sessions exist in that period
Hermes DB has sessions with empty model field — doesn't affect accuracy. Diagnose with:
sqlite3 ~/.hermes/state.db "SELECT DISTINCT model FROM sessions WHERE model IS NULL OR model = ''"Windows users without
sqlite3can use Python instead:python3 -c "import sqlite3; c=sqlite3.connect(r'$env:USERPROFILE\.hermes\state.db'); print('\n'.join(r[0] or '(NULL)' for r in c.execute('SELECT DISTINCT model FROM sessions WHERE model IS NULL OR model = \"\"')))"
Cause: the directory path you entered doesn't exist. Create it first:
mkdir -p ~/Desktop/my-data
agent-usage-stats -a hermes --export
# Enter: ~/Desktop/my-dataCause: clawhub install was run from a directory other than home, or your system has ~/.openclaw/ (which redirects ClawHub's install target).
Fix for all OSes:
cd ~
clawhub install ai-agent-usage-stats --force
python3 ~/skills/ai-agent-usage-stats/agent-usage-stats.py setup # Windows: python $HOME\skills\...
agent-usage-stats --versionThis ensures the skill is installed to ~/skills/ — the predictable home-directory location.
Cause: Some OpenClaw versions (especially older builds on Linux) don't record token usage (input/output counts) in their data files. The tool detects session files and model names, but the usage field in .jsonl is populated as 0.
Notable data: 0 tokens + non-zero call count → confirms usage recording is missing at the source.
Resolution: This is an OpenClaw data recording limitation, not a agent-usage-stats bug. agent-usage-stats reads whatever the agent wrote down. Options:
- Upgrade OpenClaw to a newer version that records token usage
- No workaround available in agent-usage-stats itself
Possible cause: neither period has session records. Check with --today first.
⚠️ agent-usage-statsonly reads local data. No cross-machine aggregation.
- Same API key on multiple machines? → Each machine's stats are isolated
- Example: Same key used on PC A and PC B → PC A's
agent-usage-statsonly sees PC A's usageagent-usage-statsreads disk files — no network calls, no API dashboard queries- To see another machine's stats, install
agent-usage-statsthere too🕐 Timezone:
--today/--yesterdayuse your local system timezone. E.g. on UTC+8 (Beijing),--todayspans 00:00–23:59 CST. Machines in different timezones see different ranges.
Stats accuracy depends on whether the relay passes through the real API's usage field unchanged. agent-usage-stats reads what your Agent wrote locally — it does not verify against the real API.
agent-usage-stats reads local data files (SQLite / JSONL) written by each Agent, aggregating input_tokens, output_tokens, cache_read_tokens, and call counts from the usage object.
API returns usage → Agent writes locally → agent-usage-stats reads & aggregates
Results may differ from your API billing dashboard because:
- Cache tokens may be counted multiple times (once per cache hit)
- Agent recording gaps — some Agents/versions don't record all fields
- Timezone mismatch — API dashboards use UTC, this tool uses local time
- Relay modification — some relays alter or drop the
usagefield
This is a local ledger — it shows what your Agent recorded, not the upstream billing.