session-costAnalyze OpenClaw session logs to report token usage, costs, and performance metrics grouped by model. Use when the user asks about API spending, token usage,...
Install via ClawdBot CLI:
clawdbot install khaney64/session-costAnalyze OpenClaw session logs for token usage, costs, and performance metrics grouped by model.
Note: Currently limited to the main agent (default path: ~/.openclaw/agents/main/sessions/). If other agents are added in the future, this could be modified to accept an --agent parameter to specify which agent's sessions to analyze.
# Summary of all sessions (default path: ~/.openclaw/agents/main/sessions/)
node scripts/session-cost.js
# Show all session details
node scripts/session-cost.js --details
# Show details for a specific session
node scripts/session-cost.js --details abc123
--path ā Directory to scan for .jsonl files (default: ~/.openclaw/agents/main/sessions/)--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 (looks 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# Last 24 hours summary
node scripts/session-cost.js --offset 24h
# Last 7 days, JSON output
node scripts/session-cost.js --offset 7d --json
# Discord-friendly format (for bots/chat)
node scripts/session-cost.js --format discord
# Discord format with filters
node scripts/session-cost.js --format discord --offset 24h --provider anthropic
# Filter by provider
node scripts/session-cost.js --provider anthropic
# All sessions in compact table format
node scripts/session-cost.js --details --table
# Custom path with details
node scripts/session-cost.js --path /other/dir --details
# Single session detail
node scripts/session-cost.js --details 9df7a399-8254-411b-a875-e7337df73d29
# Anthropic sessions from last 24h in table format
node scripts/session-cost.js --provider anthropic --offset 24h --details --table
Found 42 .jsonl files, 42 matched
====================================================================================================
SUMMARY BY MODEL
====================================================================================================
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)
--details)Shows per-session breakdown (session ID, model, duration, timestamps, tokens, cache, cost) followed by the model summary.
--details --table)Compact table view with columns: Session, Model, Duration, Tokens, Cache (read/write), Cost.
SESSION DETAILS
=============================================================================================================================
Model Duration Tokens Cache Cost Session
āāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāā
anthropic/claude-sonnet-4.5 45 min 128.5K 15.2K / 8.1K $0.3245 abc123def456
anthropic/claude-opus-4 12 min 45.3K 2.1K / 1.5K $0.8921 xyz789abc012
--format json){
"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 }
}
},
"grandTotal": { ... }
}
--format discord)Optimized for chat platforms (Discord, Slack, etc.) - concise, markdown-friendly, no tables:
š° **Usage Summary**
(last 24h)
**Total Cost:** $12.34
**Total Tokens:** 1.2M
**Sessions:** 42
**By Provider:**
⢠anthropic: $10.50 (950K tokens)
⢠openai: $1.84 (250K tokens)
**Top Models:**
⢠anthropic/claude-sonnet-4.5: $8.20 (800K tokens)
⢠openai/gpt-4o: $1.84 (250K tokens)
⢠anthropic/claude-opus-4: $2.30 (150K tokens)
Generated Mar 1, 2026
Development teams building AI applications can use this skill to track API spending across different models and sessions. This helps identify expensive models, optimize prompts, and manage budgets by analyzing token usage patterns over time.
Independent consultants offering AI services can generate detailed usage reports for clients. The session breakdown helps justify costs, demonstrate work volume, and provide transparent billing based on actual API consumption.
Large organizations deploying AI across departments can monitor usage by provider and model. This enables cost allocation, compliance tracking, and optimization decisions while maintaining oversight of AI expenditures.
Research institutions can analyze experimental sessions to compare model performance and costs. The detailed metrics help evaluate cost-effectiveness of different approaches and justify research budgets.
SaaS companies embedding AI features can track per-customer usage patterns. This helps with pricing strategy, resource planning, and identifying high-value customers based on their AI consumption.
Companies can implement pay-per-use pricing by tracking exact API consumption through session logs. This allows transparent billing where customers pay only for the tokens they actually use, with detailed breakdowns available.
Offer this tool as a service to help businesses monitor and optimize their AI spending. Provide analytics dashboards, cost alerts, and optimization recommendations based on session analysis.
Integrate this analysis capability into existing development tools or platforms. Offer it as a premium feature for teams needing advanced cost tracking and optimization insights.
š¬ Integration Tip
Start by running basic summaries to understand usage patterns, then use filters like --offset and --provider to focus on specific time periods or models for deeper analysis.
Transform AI agents from task-followers into proactive partners that anticipate needs and continuously improve. Now with WAL Protocol, Working Buffer, Autonomous Crons, and battle-tested patterns. Part of the Hal Stack š¦
Use the ClawdHub CLI to search, install, update, and publish agent skills from clawdhub.com. Use when you need to fetch new skills on the fly, sync installed skills to latest or a specific version, or publish new/updated skill folders with the npm-installed clawdhub CLI.
Clawdbot documentation expert with decision tree navigation, search scripts, doc fetching, version tracking, and config snippets for all Clawdbot features
Interact with Moltbook social network for AI agents. Post, reply, browse, and analyze engagement. Use when the user wants to engage with Moltbook, check their feed, reply to posts, or track their activity on the agent social network.
OpenClaw CLI wrapper ā gateway, channels, models, agents, nodes, browser, memory, security, automation.
MoltGuard ā runtime security plugin for OpenClaw agents by OpenGuardrails. Helps users install, register, activate, and check the status of MoltGuard. Use wh...