# daily-stats

Daily token usage and message statistics for OpenClaw.

## Trigger

When user asks for daily statistics:
- "daily stats"
- "昨日统计"
- "昨天 token"

## Description

Query OpenClaw session data from all agents and calculate daily usage:
- Input tokens consumed
- Output tokens generated
- Cache read/write tokens
- Message count per agent
- Agent count
- **Accurate cost estimation**: Calculates costs based on actual pricing models
- Automatic model detection from config

## Usage

```bash
cd ~/.openclaw/workspace/skills/daily-stats
bash run.sh

# Specify date
bash run.sh 2026-03-05
```

## Output Format

### Example 1: MiniMax Model
```
========================================
📊 OpenClaw Daily Stats - 2026-03-05
========================================

📈 Token Usage
   Input:       1,234,567
   Output:      99,367
   Cache Read:  21,937,554
   Cache Write: 7,628,887
   ────────────────────────────────
   Total:       30,900,375

💬 Messages: ~2321 (3 agents)

💰 Cost Estimate (MiniMax)
   $0.19

⚙️  Model: abab6.5s-chat
========================================
```

### Example 2: Bedrock Model
```
========================================
📊 OpenClaw Daily Stats - 2026-03-05
========================================

📈 Token Usage
   Input:       2,000,000
   Output:      150,000
   Cache Read:  10,000,000
   Cache Write: 5,000,000
   ────────────────────────────────
   Total:       17,150,000

💬 Messages: ~1500 (2 agents)

💰 Cost Estimate (Bedrock (Claude))
   $27.00

⚙️  Model: claude-3-5-sonnet-20241022
========================================
```

## Data Sources

- Session logs: `~/.openclaw/agents/*/sessions/*.jsonl` (all agents)
- Config: `~/.openclaw/openclaw.json` (model detection)

## Features

- **Multi-agent support**: Aggregates statistics from all agents
- **Smart cost calculation**: Automatically detects model and shows relevant pricing
  - MiniMax models: Shows MiniMax pricing only
  - Claude/Bedrock models: Shows Bedrock pricing only
  - Unknown models: Shows both estimates for comparison
- **Model detection**: Automatically detects current model from config
- **Formatted output**: Numbers formatted with thousands separators
- **Cross-platform date parsing**: Supports both GNU date and BSD date

## Pricing (Reference)

### MiniMax M2.5
- **Input**: $0.14/1M tokens (¥1/1M, ¥7.2=$1)
- **Output**: $0.14/1M tokens
- **Cache**: Typically included (not separately billed)

### AWS Bedrock Claude 3.5 Sonnet
- **Input**: $3/1M tokens
- **Output**: $15/1M tokens
- **Cache Read**: $0.30/1M tokens
- **Cache Write**: $3.75/1M tokens

## Cost Calculation Methods

**MiniMax**: Only counts input + output tokens (cache is free)
```
Cost = (Input / 1M × $0.14) + (Output / 1M × $0.14)
```

**Bedrock**: Counts all token types
```
Cost = (Input / 1M × $3) + (Output / 1M × $15) +
       (Cache Read / 1M × $0.30) + (Cache Write / 1M × $3.75)
```
