TokenSave v0.4.4
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 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 — 5,300 tokens saved with a single paste.
All numbers from tests/test_analyzer.py real test fixtures. 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. Analyze mode is 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.
Metadata
Release files for tokensave 0.4.5
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| tokensave-0.4.5.tar.gz | 40.4 kB | Without provenance | Details for tokensave-0.4.5.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| tokensave-0.4.5-py3-none-any.whl | Python 3 | none | any | Details for tokensave-0.4.5-py3-none-any.whl |
Total release size: 76.8 kB
Release files / tokensave-0.4.5.tar.gz
| Download URL | tokensave-0.4.5.tar.gz |
|---|---|
| Size | 40.4 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
41eac5853d16fa54a582e22b02b9b20f9b8d68d50ad869c54eef3f5a88dd2ef4
|
|
BLAKE2b-256 checksum How to use checksums |
138abdc754af7815e07c3d6ba38f33769a2b528b6e20d9f343aaca76f2bcfa37
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.12.3
|
Release files / tokensave-0.4.5-py3-none-any.whl
| Download URL | tokensave-0.4.5-py3-none-any.whl |
|---|---|
| Size | 36.4 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
5bda471d75af7da02b418adf77fa14cc15c42d844259ee5ecf1e8ae368452396
|
|
BLAKE2b-256 checksum How to use checksums |
b271fa4d719d1c638d4f67ffb7f79200280fe7d3aeae1fd780a2ee547203c8b8
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.12.3
|
Security for tokensave 0.4.5
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.