Token waste analyzer for AI agents — find where your money goes and get one-click fix prompts. pip install, bills go down.
Project description
TokenSave v0.4.2
Token waste analyzer for AI agents — find where your money goes and get one-click fix prompts.
pip install tokensave— bills go down.
$ tokensave analyze
Session test_123: 12,000 tokens, ~$0.05, 25% avoidable
#1 duplicate_tool_calls (5x): 3,000 tokens
read_file called 5x with same path
Send to your agent: "Before calling any tool, check if you already have
the result in a previous message..."
tokensave scans your session → finds the waste → gives you the exact prompt to stop it. One command. Paste the output. Bills go down.
All demo numbers above are from real test fixtures in tests/test_analyzer.py
— 12,000 tokens, 3,000 wasted on duplicate reads, 25% avoidable.
No made-up data.
What It Does (Two Modes)
Mode 1: Analyze (tokensave analyze)
Reads Hermes session data from ~/.hermes/state.db (SQLite, primary) or
~/.hermes/sessions/*.json (API error dumps, fallback) and detects four
categories of waste:
| Detector | What it finds |
|---|---|
| Duplicate tool calls | Same tool + same args called 2+ times (exact + near-duplicate) |
| Context bloat | Stale overlapping content, oversized tool outputs, unused tools, session overhead |
| Model mismatch | Simple queries running on expensive models |
| Heartbeat waste | Cron/scheduled/idle-check messages on pro-tier |
Output: ≤5 lines, actionable. Zero config. 100% local.
Mode 2: Pipeline (v0.3.0, unchanged)
Transparent OpenAI wrapper — from tokensave import OpenAI — automatic
normalization, exact-match cache, and context compression. Cuts token usage
without changing your code.
Why TokenSave + Smart Router
| TokenSave | Smart Router | |
|---|---|---|
| When | After the session (diagnosis) | Before each message (prevention) |
| Job | "Here's where you're wasting money" | "Use this model instead" |
| User | Run manually, get insights | Runs automatically, suggests switches |
Use both for maximum savings: Smart Router prevents waste, TokenSave reveals what slipped through.
Install
pip install tokensave
Or as a Hermes skill:
hermes skills install raydatalab/tokensave # from ClawHub
hermes skills install raydatalab/tokensave # from GitHub
Usage
# Analyze your latest session (auto-detect from state.db)
tokensave analyze
# Analyze a specific session by ID
tokensave analyze 20260710_214623_e95335
# Analyze an error request dump
tokensave analyze ~/.hermes/sessions/request_dump_*.json
# Run only specific detectors
tokensave analyze --detectors duplicate_tool_calls,model_mismatch
# Pipeline mode (automatic)
export OPENAI_API_KEY=sk-...
python3 -c "
from tokensave import OpenAI
client = OpenAI()
# All calls go through normalize → cache → compress
"
Benchmarks (Pipeline Mode)
| Scenario | Before | After | Savings |
|---|---|---|---|
| 10MB production logs | ~2,500,000 tok | ~5,000 tok | ~99.8% |
| 2MB code/dataset | ~500,000 tok | ~295,000 tok | 41% |
Full benchmarks → BENCHMARK.md
Tech Stack
| Component | Role |
|---|---|
| Python stdlib | Waste detection, session parsing |
| SQLite (stdlib) | Exact-match cache |
headroom-ai |
SmartCrusher + CodeCompressor (pipeline mode) |
License
Apache 2.0 — see LICENSE.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file tokensave-0.4.3.tar.gz.
File metadata
- Download URL: tokensave-0.4.3.tar.gz
- Upload date:
- Size: 40.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
5614ad17010087e47b809a112229fd327e9ef864b26039a5cbd7c261af953dcd
|
|
| MD5 |
6c611a28d8bda7eb002f2b5832da43bd
|
|
| BLAKE2b-256 |
c8fe691ae5225f26185aee727539c2e620c6428a559653eb981a2080edd3ac91
|
File details
Details for the file tokensave-0.4.3-py3-none-any.whl.
File metadata
- Download URL: tokensave-0.4.3-py3-none-any.whl
- Upload date:
- Size: 36.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
bd0b8072a7369e1c331ab80277d3ad1e2fdc1e9d9261e3dbff6174e375584049
|
|
| MD5 |
3d5440b15deb500d6e3a0f8c7590bd93
|
|
| BLAKE2b-256 |
21c6ca02029ace11008a5afac5125716fb12e20205803b6e087b4a734b2d4d2b
|