Skip to content
Back to skills

Cache Monitor

ASecurity

Analyze Claude Code and OpenClaw session costs and cache efficiency. Parses JSONL session files to report cache hit rates, token waste, cost by project/agent. Use to optimize the $100/month budget.

  • 6 stars
  • 0 votes
  • 0 copies
  • 2 views
  • Added June 1, 2026
ai-agentsgobash

Works with

  • claude code

Security analysis

A100/100

Scanned June 1, 2026

npx -y skills add KevinZai/commander --skill cache-monitor --agent claude-code

Installs into .claude/skills of the current project.

Are you the author of Cache Monitor?

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

Security grade badge for Cache Monitor
[![Security: A β€” Skills Directory](https://www.skillsdirectory.com/api/skills/kevinzai-cache-monitor/badge)](https://www.skillsdirectory.com/skills/kevinzai-cache-monitor)

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: cache-monitor
description: |
  Analyze Claude Code and OpenClaw session costs and cache efficiency.
  Parses JSONL session files to report cache hit rates, token waste,
  cost by project/agent. Use to optimize the $100/month budget.
allowed-tools:
  - Bash
  - Read
  - Write
---

# Cache Monitor

## When to Use
- Weekly cost review
- After noticing expensive sessions
- After changing CLAUDE.md or settings.json (check for cache busting)
- When Kevin asks "how much did that cost?"

## Analysis Commands

### Per-Session Cost (Claude Code)
```bash
# Find today's sessions
find ~/.claude/projects/ -name "*.jsonl" -mtime -1 2>/dev/null | head -20
```

### Per-Agent Cost (OpenClaw)
```bash
# Cost by agent (last 24h)
for dir in ~/.openclaw/agents/*/; do
  agent=$(basename "$dir")
  cost=$(find "$dir/sessions/" -name "*.jsonl" -mtime -1 -exec grep -h '"totalCost"' {} \; 2>/dev/null | \
    jq -s '[.[].totalCost // 0] | add' 2>/dev/null || echo "0")
  if [ "$cost" != "0" ] && [ "$cost" != "null" ]; then
    echo "$agent: \$$cost"
  fi
done | sort -t'$' -k2 -rn
```

### Cache Hit Rate
```bash
# Check cache_read_input_tokens vs input_tokens ratio
# Higher ratio = better caching = lower cost
find ~/.openclaw/agents/*/sessions/ -name "*.jsonl" -mtime -1 -exec \
  grep -h '"cache_read_input_tokens"' {} \; 2>/dev/null | \
  jq -s 'if length > 0 then
    { total_input: ([.[].input_tokens // 0] | add),
      cache_read: ([.[].cache_read_input_tokens // 0] | add) } |
    .cache_rate = (if .total_input > 0 then (.cache_read / .total_input * 100 | round) else 0 end)
  else { note: "no data" } end'
```

## Output Report
```markdown
# Cost & Cache Report β€” YYYY-MM-DD

## Summary
- Period: Last 24h / 7d / 30d
- Total cost: $X.XX
- Budget remaining: $XX.XX of $100/month
- Cache hit rate: XX%

## By Agent (top 10)
| Agent | Sessions | Cost | Cache Rate |
|-------|----------|------|-----------|

## By Project (top 10)
| Project | Sessions | Cost | Notes |
|---------|----------|------|-------|

## Alerts
- πŸ”΄ Agents with <30% cache rate (settings misconfigured?)
- 🟑 Agents with cost >$5/day
- βœ… Well-optimized agents (>70% cache rate)

## Recommendations
- Specific actions to reduce cost
```

## Gotchas
- JSONL format varies by OpenClaw version β€” some fields may be nested differently
- Cache rate of 0% for first session is normal (cold start)
- Opus sessions will always cost more β€” that's by design for complex work
- Agent-HQ at localhost:3001 has aggregated data too

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.

Comments

Loading comments…

Newsletter

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