Session Cost
by @khaney64
Analyze OpenClaw session logs to report token usage, costs, and performance metrics grouped by agent and model. Use when the user asks about API spending, to...
clawhub install session-costπ About This Skill
name: session-cost description: Analyze OpenClaw session logs to report token usage, costs, and performance metrics grouped by agent and model. Use when the user asks about API spending, token usage, session costs, or wants a usage summary. metadata: {"openclaw":{"emoji":"π","requires":{"bins":["node"]}}}
Session Cost
Analyze OpenClaw session logs for token usage, costs, and performance metrics grouped by agent and model.
By default, scans all agents in ~/.openclaw/agents/. Each agent's sessions are read from ~/.openclaw/agents/.
Quick Start
# Summary across all agents
node /home/claw/.openclaw/workspace/skills/session-cost/scripts/session-cost.jsShow all session details
node /home/claw/.openclaw/workspace/skills/session-cost/scripts/session-cost.js --detailsShow details for a specific session (searches across all agents)
node /home/claw/.openclaw/workspace/skills/session-cost/scripts/session-cost.js --details abc123
Options
--path β Directory to scan for .jsonl files (overrides agent auto-discovery)--agent β Filter by agent name (e.g., main, codegen)--offset β Only include sessions from the last N units (30m, 2h, 7d)--provider β Filter by model provider (anthropic, openai, ollama, etc.)--details [session-id] β Show per-session details. Optionally pass a session ID to show just that session (searches across all agents for .jsonl )--table β Show details in compact table format (use with --details)--format β Output format: text (default), json, or discord--json β Shorthand for --format json (backwards compat)--help, -h β Show help messageExamples
# Last 24 hours summary
node /home/claw/.openclaw/workspace/skills/session-cost/scripts/session-cost.js --offset 24hOnly the main agent
node /home/claw/.openclaw/workspace/skills/session-cost/scripts/session-cost.js --agent mainLast 7 days, JSON output
node /home/claw/.openclaw/workspace/skills/session-cost/scripts/session-cost.js --offset 7d --jsonDiscord-friendly format (for bots/chat)
node /home/claw/.openclaw/workspace/skills/session-cost/scripts/session-cost.js --format discordDiscord format with filters
node /home/claw/.openclaw/workspace/skills/session-cost/scripts/session-cost.js --format discord --offset 24h --provider anthropicFilter by provider
node /home/claw/.openclaw/workspace/skills/session-cost/scripts/session-cost.js --provider anthropicAll sessions in compact table format
node /home/claw/.openclaw/workspace/skills/session-cost/scripts/session-cost.js --details --tableCustom path with details (overrides agent discovery, scans exact directory)
node /home/claw/.openclaw/workspace/skills/session-cost/scripts/session-cost.js --path /other/dir --detailsSingle session detail (found automatically across agents)
node /home/claw/.openclaw/workspace/skills/session-cost/scripts/session-cost.js --details 9df7a399-8254-411b-a875-e7337df73d29Anthropic sessions from last 24h in table format
node /home/claw/.openclaw/workspace/skills/session-cost/scripts/session-cost.js --provider anthropic --offset 24h --details --table
Output Format
Text Summary (Default)
Results are grouped by agent, then by model within each agent. A grand total section shows per-agent subtotals and a combined total.
Found 52 .jsonl files across 2 agents, 52 matched====================================================================================================
SUMMARY BY AGENT
====================================================================================================
Agent: main
anthropic/claude-sonnet-4-5-20250929
--------------------------------------------------------------------------------
Sessions: 30
Tokens: 1,234,567 (input: 900,000, output: 334,567)
Cache: read: 500,000 tokens, write: 200,000 tokens
Cost: $12.3456
Input: $5.4000
Output: $5.0185
Cache read: $1.5000 (included in total, discounted rate)
Cache write: $0.4271 (included in total)
anthropic/claude-opus-4-6
--------------------------------------------------------------------------------
Sessions: 5
Tokens: 250,000 (input: 180,000, output: 70,000)
...
Agent: codegen
anthropic/claude-sonnet-4-5-20250929
--------------------------------------------------------------------------------
Sessions: 17
...
====================================================================================================
GRAND TOTAL
====================================================================================================
main β 35 sessions, $15.8200
codegen β 17 sessions, $8.5600
All agents (2)
--------------------------------------------------------------------------------
Sessions: 52
Tokens: ...
Cost: $24.3800
...
When only a single agent is present, the grand total shows "All models (N)" instead.
Text Details (--details)
Shows per-session breakdown (session ID, agent, model, duration, timestamps, tokens, cache, cost) followed by the agent/model summary.
Table Format (--details --table)
Compact table view. When multiple agents are present, an Agent column is included.
SESSION DETAILS
============================================================================================================================================
Agent Model Duration Tokens Cache Cost Session
ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
main anthropic/claude-sonnet-4.5 45 min 128.5K 15.2K / 8.1K $0.3245 abc123def456
codegen anthropic/claude-sonnet-4.5 12 min 45.3K 2.1K / 1.5K $0.8921 xyz789abc012
With a single agent, the Agent column is omitted and the table matches the previous format.
JSON (--format json)
Results are nested by agent. Each agent contains its model summaries and an agent-level totals object. A top-level grandTotal aggregates across all agents.
{
"agents": {
"main": {
"models": {
"anthropic/claude-sonnet-4-5-20250929": {
"sessions": 30,
"tokens": { "input": 900000, "output": 334567, "total": 1234567 },
"cache": { "read": 500000, "write": 200000 },
"cost": { "total": 12.3456, "input": 5.4, "output": 5.0185, "cacheRead": 1.5, "cacheWrite": 0.4271 }
}
},
"totals": {
"sessions": 35,
"tokens": { "input": 1080000, "output": 404567, "total": 1484567 },
"cache": { "read": 600000, "write": 250000 },
"cost": { "total": 15.82, ... }
}
},
"codegen": {
"models": { ... },
"totals": { ... }
}
},
"grandTotal": {
"sessions": 52,
"tokens": { "input": 1500000, "output": 600000, "total": 2100000 },
"cache": { "read": 800000, "write": 350000 },
"cost": { "total": 24.38, ... }
}
}
Discord (--format discord)
Optimized for chat platforms (Discord, Slack, etc.) - concise, markdown-friendly, no tables:
π° Usage Summary
(last 24h)Total Cost: $24.38
Total Tokens: 2.1M
Sessions: 52
By Agent:
β’ main: $15.82 (35 sessions)
β’ codegen: $8.56 (17 sessions)
By Provider:
β’ anthropic: $22.50 (1.9M tokens)
β’ openai: $1.88 (200K tokens)
Top Models:
β’ anthropic/claude-sonnet-4.5: $18.20 (1.5M tokens)
β’ anthropic/claude-opus-4: $4.30 (400K tokens)
β’ openai/gpt-4o: $1.88 (200K tokens)
The "By Agent" section is shown only when multiple agents are present.
Output Fields
~/.openclaw/agents/)Notes
--path is provided, it overrides agent auto-discovery and scans exactly that directory. The agent name is inferred from the path (e.g., .../agents/main/sessions β "main").--agent and --provider filters can be combined (e.g., --agent main --provider anthropic).--details ) searches across all discovered agents to find the session file.*.trajectory.jsonl files are skipped β they use a different schema and would otherwise show up as unknown/unknown rows with zero tokens.(not reported by model) next to the token counts so they can be distinguished from sessions with no assistant activity.π‘ Examples
# Last 24 hours summary
node /home/claw/.openclaw/workspace/skills/session-cost/scripts/session-cost.js --offset 24hOnly the main agent
node /home/claw/.openclaw/workspace/skills/session-cost/scripts/session-cost.js --agent mainLast 7 days, JSON output
node /home/claw/.openclaw/workspace/skills/session-cost/scripts/session-cost.js --offset 7d --jsonDiscord-friendly format (for bots/chat)
node /home/claw/.openclaw/workspace/skills/session-cost/scripts/session-cost.js --format discordDiscord format with filters
node /home/claw/.openclaw/workspace/skills/session-cost/scripts/session-cost.js --format discord --offset 24h --provider anthropicFilter by provider
node /home/claw/.openclaw/workspace/skills/session-cost/scripts/session-cost.js --provider anthropicAll sessions in compact table format
node /home/claw/.openclaw/workspace/skills/session-cost/scripts/session-cost.js --details --tableCustom path with details (overrides agent discovery, scans exact directory)
node /home/claw/.openclaw/workspace/skills/session-cost/scripts/session-cost.js --path /other/dir --detailsSingle session detail (found automatically across agents)
node /home/claw/.openclaw/workspace/skills/session-cost/scripts/session-cost.js --details 9df7a399-8254-411b-a875-e7337df73d29Anthropic sessions from last 24h in table format
node /home/claw/.openclaw/workspace/skills/session-cost/scripts/session-cost.js --provider anthropic --offset 24h --details --table
βοΈ Configuration
--path β Directory to scan for .jsonl files (overrides agent auto-discovery)--agent β Filter by agent name (e.g., main, codegen)--offset β Only include sessions from the last N units (30m, 2h, 7d)--provider β Filter by model provider (anthropic, openai, ollama, etc.)--details [session-id] β Show per-session details. Optionally pass a session ID to show just that session (searches across all agents for .jsonl )--table β Show details in compact table format (use with --details)--format β Output format: text (default), json, or discord--json β Shorthand for --format json (backwards compat)--help, -h β Show help messageπ Tips & Best Practices
--path is provided, it overrides agent auto-discovery and scans exactly that directory. The agent name is inferred from the path (e.g., .../agents/main/sessions β "main").--agent and --provider filters can be combined (e.g., --agent main --provider anthropic).--details ) searches across all discovered agents to find the session file.*.trajectory.jsonl files are skipped β they use a different schema and would otherwise show up as unknown/unknown rows with zero tokens.(not reported by model) next to the token counts so they can be distinguished from sessions with no assistant activity.