Skip to content
Back to skills

Session Cost

ASecurity

Analyze OpenClaw session logs to report token usage, costs, and performance metrics grouped by model. Use when the user asks about API spending, token usage, session costs, or wants a usage summary.

  • 2 stars
  • 0 votes
  • 0 copies
  • 0 views
  • Added November 11, 2026
ai-agentsbashnodeapiperformance

Works with

  • api

Security analysis

A100/100

Pro scans all 3 files and shows the line behind each finding

Scanned November 11, 2026

npx -y skills add johnalbertini14-glitch/openclaw-skills --skill session-cost --agent claude-code

Installs into .claude/skills of the current project.

Are you the author of Session Cost?

Add the live security badge to your README. It updates with every re-scan.

Security grade badge for Session Cost
[![Security: A β€” Skills Directory](https://www.skillsdirectory.com/api/skills/johnalbertini14-glitch-session-cost/badge)](https://www.skillsdirectory.com/skills/johnalbertini14-glitch-session-cost)

More formats (shields.io, HTML) on the badges page. Keep it an A: scan every change in CI with Pro.

Download with Pro
SKILL.md
---
name: session-cost
description: Analyze OpenClaw session logs to report token usage, costs, and performance metrics grouped by 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 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.

## Quick Start

```bash
# 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
```

## Options

- `--path <dir>` β€” Directory to scan for `.jsonl` files (default: `~/.openclaw/agents/main/sessions/`)
- `--offset <time>` β€” Only include sessions from the last N units (`30m`, `2h`, `7d`)
- `--provider <name>` β€” 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 `<id>.jsonl`)
- `--table` β€” Show details in compact table format (use with `--details`)
- `--format <type>` β€” Output format: `text` (default), `json`, or `discord`
- `--json` β€” Shorthand for `--format json` (backwards compat)
- `--help`, `-h` β€” Show help message

## Examples

```bash
# 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
```

## Output Format

### Text Summary (Default)

```
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)
```

### Text Details (`--details`)

Shows per-session breakdown (session ID, model, duration, timestamps, tokens, cache, cost) followed by the model summary.

### Table Format (`--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
```

### JSON (`--format json`)

```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": { ... }
}
```

### Discord (`--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)
```

## Output Fields

- **Sessions** β€” Number of session files analyzed
- **Tokens** β€” Total, input, and output token counts
- **Cache** β€” Cache read and write token counts
- **Cost** β€” Total cost broken down by input, output, cache read, and cache write
- **Duration** β€” Session duration in minutes (details mode)
- **Timestamps** β€” First and last activity timestamps (details mode)

Files in this skill

  • SKILL.md5.4 KB
  • _meta.json456 B
  • scripts/session-cost.js17.1 KB

Attribution

Is this your skill, or is something wrong with this listing? Request removal or report an issue. Author removals are honored within 72 hours.

View all in ai-agents β†’

Comments

Loading comments…

Newsletter

Get the weekly list of safe new skills, and the ones we pulled.