Install
openclaw skills install @raydatalab/tokensaveUse when the user explicitly asks to analyze token waste, costs, or API bills. Finds duplicate tool calls, context bloat, model mismatch, and heartbeat waste. Analyze mode is 100% local, zero config.
openclaw skills install @raydatalab/tokensave$ tokensave analyze
Session 20260711_a1b2c3: 12,000 tokens, ~$0.05, 44% avoidable.
Top wastes:
1. duplicate_tool_calls (5x): ~3,000 tokens — read_file called 5x with same path
2. context_bloat (1x): ~1,800 tokens — 40% of input is stale context
3. model_mismatch (3x): ~500 tokens — simple queries routed through pro
Send to your agent: "Before calling any tool, check if you already have
the result in a previous message..."
One session. 12K tokens. 44% could have been avoided — that's 5,300 tokens saved with a single paste. Run after every session, bills drop immediately.
All numbers above are from tests/test_analyzer.py real test fixtures.
12,000 input + output tokens, captured waste across all 4 detectors.
No made-up data.
tokensave analyze <session_id>tokensave analyze <session_id> over auto-detecting the latest session
when the user has not explicitly asked for itWhen the user has explicitly asked to run an analysis, use:
tokensave analyze
If the user has provided a specific session ID or path, use that instead:
tokensave analyze <session_id> # specific session from state.db
tokensave analyze <file.json> # error request dump
tokensave analyze <directory/> # latest JSON in directory
tokensave analyze --detectors dup,bloat # specific detectors only
Always confirm with the user before analyzing if they haven't provided a specific session target. Auto-detect only when the user has explicitly asked for their "latest session" or "current session."
Copy the output and paste it into your response. The user sees:
Session abc123: 12,400 tokens, ~$0.19, 41% avoidable.
Top wastes:
#1 duplicate_tool_calls (8x): ~4,800 tokens
#2 model_mismatch (5x): ~860 tokens
#3 context_bloat: ~3,700 tokens
Send to your agent: "Before reading a file, check if you already..."
Four waste detectors run against your session:
| Detector | What it finds |
|---|---|
| Duplicate tool calls | Same tool + same args called 2+ times (exact + near-duplicate) |
| Context bloat | Stale/redundant context, oversized tool outputs, unused tool definitions, session overhead |
| Model mismatch | Simple queries running on expensive models — tells you which cheaper model to use |
| Heartbeat waste | Cron jobs and idle/status checks that could run on a cheaper model |
TokenSave reads from two sources (no config needed):
| Source | Format | What's there |
|---|---|---|
~/.hermes/state.db | SQLite | Primary — full session transcripts with token counts, costs, and metadata |
~/.hermes/sessions/*.json | JSON | API error request dumps — partial data but useful when SQLite is unavailable |
Auto-detect tries SQLite first, falls back to JSON, then gives a clear error message.
pip install tokensaveOPENAI_API_KEY and makes API callstokensave also works as a transparent OpenAI wrapper that cuts token usage
automatically. This mode requires an API key and makes network calls to
your configured API endpoint. If the user has installed it with
from tokensave import OpenAI, their API calls go through normalize → cache
→ compress. But that's automatic — you don't need to do anything.
This mode is separate from tokensave analyze. The analyze command never
makes network calls; it only reads local session data.
| Tier | What it checks | Output |
|---|---|---|
analyze | SQLite sessions + JSON error dumps | Waste report + fix prompt |
pipeline | Transparent proxy | Automatic token savings |
tokensave analyze returns no results, the session
may not have been written to state.db yet. Hermes writes state.db on session end —
try again after /new.