Agent Token Usage
/install agent-token-usage
agent-token-usage
Accurately attribute LLM token consumption across all OpenClaw agents for a given day.
Why this skill exists
sessions_list returns each session's totalTokens field which is the last context window size, NOT the cumulative consumption across all LLM calls in that session. For long-running sessions with many turns, real consumption can be 100×+ larger than what sessions_list shows. This skill reads the authoritative trajectory.jsonl files where each LLM call writes a usage object, and sums them per agent.
Quick start
# default = today, Asia/Shanghai local date
python ~/.openclaw/workspace/skills/agent-token-usage/scripts/agent_token_usage.py
# specific date
python ~/.openclaw/workspace/skills/agent-token-usage/scripts/agent_token_usage.py --date 2026-05-20
# also show equivalent billable token (cacheRead × 0.1 + cacheWrite × 1.25 + input + output)
python ~/.openclaw/workspace/skills/agent-token-usage/scripts/agent_token_usage.py --date 2026-05-20 --billable
# JSON for downstream tools
python ~/.openclaw/workspace/skills/agent-token-usage/scripts/agent_token_usage.py --date 2026-05-20 --format json
What the columns mean
| 字段 | 含义 | 计费权重 |
|---|---|---|
input |
新的、未缓存的 prompt token | 1.0× |
output |
模型生成的 token | 1.0× (typically 5× input price) |
cacheRead |
命中 prompt cache 的 token | ~0.1× |
cacheWrite |
写入 prompt cache 的 token | ~1.25× |
total |
四者之和(真实通过 LLM 的 token 量) | |
~bill |
等效计费 token(按权重折算) |
用 total 看「谁在烧 LLM 算力」,用 ~bill 看「谁更费钱」。 两者结论可能完全不同 —— 高 cacheRead 的 agent 看似巨大其实便宜,低 cacheWrite 但全 input 的 agent 看似小其实贵。
How it works
- Walk
~/.openclaw/agents/\x3Cagent>/sessions/*.trajectory.jsonl - For each line, check
tsstartswith target date (ISOYYYY-MM-DD) - DFS-search the
datafield for ausagedict with token counters - Sum per agent; also track session count and models used
Trajectory files use schema openclaw-trajectory v1. The usage object lives inside model-response events emitted by the runtime.
Common follow-ups
- "按等效成本排名" →
--billable - "昨天的" →
--date YYYY-MM-DD - "导出给我" →
--format json > /tmp/usage.json - "为什么 sessions_list 的数字差这么多" → 解释:
sessions_list.totalTokens是 context size,不是 cumulative spend。本 skill 直接累加每次 LLM 调用的 usage。
Caveats
- Only counts events that have a
usageobject — non-LLM tool calls (exec, read, write) are excluded by design - The 0.1× / 1.25× cache multipliers are Anthropic ballpark numbers; for OpenAI / other providers adjust mentally
- Does NOT compute USD cost — use the
model-usageskill (CodexBar cost log) when the user asks for $ amounts --dateis matched against ISO timestamps in trajectory (which are UTC); for very late-night events this can shift by a day relative to local time. For Asia/Shanghai users this matters between 00:00-08:00 local
- 确保已安装 OpenClaw(本地或 Docker 部署)
- 在对话框中输入安装命令:
/install agent-token-usage - 安装完成后,直接呼叫该 Skill 的名称或使用
/agent-token-usage触发 - 根据 Skill 的参数说明提供必要输入,即可获得结构化输出
Agent Token Usage 是什么?
Summarize daily LLM token usage per OpenClaw agent from trajectory logs, showing input, output, cache reads/writes, total, and optional billable token estima... 它是一个面向 Claude Code / OpenClaw 的 AI Agent Skill 插件,目前累计下载 43 次。
如何安装 Agent Token Usage?
在 OpenClaw 或 Claude Code 对话框中运行命令「/install agent-token-usage」即可一键安装,无需额外配置。
Agent Token Usage 是免费的吗?
是的,Agent Token Usage 完全免费,采用 MIT-0 许可证,可自由下载、安装和使用。
Agent Token Usage 支持哪些平台?
Agent Token Usage 跨平台运行,可在任意部署了 OpenClaw / Claude Code 的环境中使用(cross-platform)。
谁开发了 Agent Token Usage?
由 SymbolStar(@symbolstar)开发并维护,当前版本 v0.1.0。