← Back to Skills Marketplace
symbolstar

Agent Token Usage

by SymbolStar · GitHub ↗ · v0.1.0 · MIT-0
cross-platform ✓ Security Clean
43
Downloads
0
Stars
0
Active Installs
1
Versions
Install in OpenClaw
/install agent-token-usage
Description
Summarize daily LLM token usage per OpenClaw agent from trajectory logs, showing input, output, cache reads/writes, total, and optional billable token estima...
README (SKILL.md)

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

  1. Walk ~/.openclaw/agents/\x3Cagent>/sessions/*.trajectory.jsonl
  2. For each line, check ts startswith target date (ISO YYYY-MM-DD)
  3. DFS-search the data field for a usage dict with token counters
  4. 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.totalTokenscontext size,不是 cumulative spend。本 skill 直接累加每次 LLM 调用的 usage。

Caveats

  • Only counts events that have a usage object — 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-usage skill (CodexBar cost log) when the user asks for $ amounts
  • --date is 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
Usage Guidance
Do not treat this as a complete security review. Install only after metadata.json and the artifact directory are successfully inspected by a reviewer or scanner.
Capability Assessment
Purpose & Capability
Review is incomplete because workspace file access failed before metadata.json or artifact contents could be read.
Instruction Scope
No artifact instructions were available to assess for scope, overrides, or unsafe agent behavior.
Install Mechanism
No install specification or manifest content was available to evaluate.
Credentials
No artifact evidence was available to judge whether requested environment access is proportionate.
Persistence & Privilege
No artifact evidence was available showing persistence, privilege use, or credential handling.
How to Use
  1. Make sure OpenClaw is installed (local or Docker)
  2. Run the install command in chat: /install agent-token-usage
  3. After installation, invoke the skill by name or use /agent-token-usage
  4. Provide required inputs per the skill's parameter spec and get structured output
Version History
v0.1.0
Initial release: per-agent daily LLM token consumption from OpenClaw trajectory files, with billable-equivalent estimate
Metadata
Slug agent-token-usage
Version 0.1.0
License MIT-0
All-time Installs 0
Active Installs 0
Total Versions 1
Frequently Asked Questions

What is 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... It is an AI Agent Skill for Claude Code / OpenClaw, with 43 downloads so far.

How do I install Agent Token Usage?

Run "/install agent-token-usage" in the OpenClaw or Claude Code chat to install it in one step — no extra setup required.

Is Agent Token Usage free?

Yes, Agent Token Usage is completely free, licensed under MIT-0. You can download, install and use it at no cost.

Which platforms does Agent Token Usage support?

Agent Token Usage is cross-platform and runs anywhere OpenClaw / Claude Code is available (cross-platform).

Who created Agent Token Usage?

It is built and maintained by SymbolStar (@symbolstar); the current version is v0.1.0.

💬 Comments