Token Tracker
Gas optimization for LLM prompts. A pre-flight analyzer + usage tracker for the Claude API. Catches vague, wasteful, or open-ended prompts before they hit the wire — and suggests a leaner rewrite.
The idea
Solidity devs use a gas estimator before deploying. LLM devs send blind prompts and wait for the bill.
Token Tracker fixes that. It wraps the Anthropic SDK and adds three layers:
| Layer | What it does | Analogy |
|---|---|---|
| Token Tracker | Logs every API call — tokens in/out, cost, session | Gas meter |
| Pre-flight Analyzer | Scores your prompt before sending — flags 8 patterns of waste | Gas estimator + linter |
| Prompt Optimizer | Rewrites bad prompts into leaner versions, side-by-side | Compiler optimizer |
All analysis is offline — zero extra API calls. Storage is local SQLite.
Demo
Run tt demo yourself to see all features without using any API credits.
Quickstart
pip install promptmeter
export ANTHROPIC_API_KEY="sk-ant-..."
As a drop-in for the Anthropic SDK
from token_tracker import TrackedClient
client = TrackedClient(session_name="my-app")
response = client.messages.create(
model="claude-sonnet-4-6",
max_tokens=512,
messages=[{"role": "user", "content": "List 3 Python web frameworks."}],
)
That's it. Every call is now analyzed, logged, and reportable.
As a standalone CLI
tt analyze "Please could you kindly tell me something about Python"
tt report # today's usage summary
tt report --week # last 7 days
tt cost-model # cost breakdown by model
tt top-waste # most expensive flagged prompts
tt sessions # list named sessions
tt demo # guided walkthrough — zero API calls
What the pre-flight catches
8 rules, each with severity and a suggested fix:
| Rule | Severity | Detects |
|---|---|---|
VAGUE_INTENT |
high | "tell me something about X" — no clear task |
OPEN_ENDED_TASK |
high | "explain everything about X" — unbounded scope |
WALL_OF_TEXT |
high | unstructured 500+ token dumps |
MISSING_FORMAT |
medium | asks for a list without specifying format |
MISSING_SCOPE |
medium | "explain X" with no length/depth limit |
REDUNDANT_CONTEXT |
medium | the same sentence twice |
FILLER_WORDS |
low | "please", "could you kindly", "thank you in advance" |
AMBIGUOUS_PRONOUN |
low | "fix it" — fix what? |
Each rule contributes to a 0–100 efficiency score. Below 60 triggers a warning. Below 40 hard-blocks (in interactive mode).
Try the walkthrough
tt demo
Runs through every feature with three example prompts (good, bad, terrible) and renders the live dashboard. No API calls, safe to run anytime.
How it actually saves tokens
| Without Token Tracker | With Token Tracker |
|---|---|
| Vague prompt → Claude asks clarifying questions → 2-3 round trips | Pre-flight catches vagueness → fix once → one round trip |
"explain X" → Claude writes 800 words when you needed 100 |
MISSING_SCOPE flags it → add "in 3 sentences" → 6× cheaper output |
| Same context pasted in every message | REDUNDANT_CONTEXT warns → use prompt caching → 90% cheaper input |
| No visibility into spend → no behavior change | Daily report shows cost per session → habits adjust |
Conservative real-world reduction: 30–50% of token spend for a developer who acts on warnings.
Configuration
TrackedClient(
api_key="sk-ant-...",
session_name="my-app", # tag this session in the DB
analyze=True, # run pre-flight before every call
interactive=True, # prompt user on flagged prompts (s/o/c menu)
warn_threshold=60, # show warning when score drops below this
)
Where data lives
A single SQLite file at ~/.token_tracker/usage.db. Two tables: sessions, usage_records. Open it with DB Browser for SQLite to poke around.
Token Tracker stores a hash of each prompt — never the full text. Your prompts stay in your process.
Contributing
The lowest-friction first contribution is adding a new rule in token_tracker/analyzer/rules.py — about 10 lines of Python. See CONTRIBUTING.md.
Found a false positive? Open an issue with the prompt and the rule that misfired.
License
MIT — see LICENSE.
Metadata
Release files for promptmeter 0.2.3
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 |
|---|---|---|---|---|
| promptmeter-0.2.3.tar.gz | 768.0 kB | With provenance | Details for promptmeter-0.2.3.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| promptmeter-0.2.3-py3-none-any.whl | Python 3 | none | any | Details for promptmeter-0.2.3-py3-none-any.whl |
Total release size: 792.9 kB
Release files / promptmeter-0.2.3.tar.gz
| Download URL | promptmeter-0.2.3.tar.gz |
|---|---|
| Size | 768.0 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
5b2304c3b50fb7de72373e7a325e1e2d6ee48eed248a36e9eff8246febc01588
|
|
BLAKE2b-256 checksum How to use checksums |
736265135d2eea0ab81062fb6806902f5c1b542a56b879071f111bf3b625dc8d
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.13.12
|
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.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on May 11, 2026.
Transparency logRelease files / promptmeter-0.2.3-py3-none-any.whl
| Download URL | promptmeter-0.2.3-py3-none-any.whl |
|---|---|
| Size | 24.9 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
11ca0f041c088e2d935b1f02ebf445f9f58608ab4083beabfa6148964cff5edc
|
|
BLAKE2b-256 checksum How to use checksums |
6d19b20f5acdd3af6416ec3c25460d2236a0c78d75824f7c500d109edc9bf868
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.13.12
|
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.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on May 11, 2026.
Transparency logSecurity for promptmeter 0.2.3
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.
Full provenance
Both files in this release have been uploaded with provenance metadata.
Attestation for promptmeter-0.2.3.tar.gz
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on May 11, 2026.
Transparency logA 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.