Pre-flight token analyzer and usage tracker for Claude — gas optimization for LLM prompts
Project description
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.
Project details
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 promptmeter-0.2.3.tar.gz.
File metadata
- Download URL: promptmeter-0.2.3.tar.gz
- Upload date:
- Size: 768.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
5b2304c3b50fb7de72373e7a325e1e2d6ee48eed248a36e9eff8246febc01588
|
|
| MD5 |
0d0d348c3d5abb10297352c577cf93de
|
|
| BLAKE2b-256 |
736265135d2eea0ab81062fb6806902f5c1b542a56b879071f111bf3b625dc8d
|
Provenance
The following attestation bundles were made for promptmeter-0.2.3.tar.gz:
Publisher:
publish.yml on emam07/Token-tracker
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
promptmeter-0.2.3.tar.gz -
Subject digest:
5b2304c3b50fb7de72373e7a325e1e2d6ee48eed248a36e9eff8246febc01588 - Sigstore transparency entry: 1506000009
- Sigstore integration time:
-
Permalink:
emam07/Token-tracker@b6237d4167877d725fbd00b1ddbc41ab94eb94f6 -
Branch / Tag:
refs/tags/v0.2.3 - Owner: https://github.com/emam07
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@b6237d4167877d725fbd00b1ddbc41ab94eb94f6 -
Trigger Event:
push
-
Statement type:
File details
Details for the file promptmeter-0.2.3-py3-none-any.whl.
File metadata
- Download URL: promptmeter-0.2.3-py3-none-any.whl
- Upload date:
- Size: 24.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
11ca0f041c088e2d935b1f02ebf445f9f58608ab4083beabfa6148964cff5edc
|
|
| MD5 |
0c0629fd529969f397991956b1be55d5
|
|
| BLAKE2b-256 |
6d19b20f5acdd3af6416ec3c25460d2236a0c78d75824f7c500d109edc9bf868
|
Provenance
The following attestation bundles were made for promptmeter-0.2.3-py3-none-any.whl:
Publisher:
publish.yml on emam07/Token-tracker
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
promptmeter-0.2.3-py3-none-any.whl -
Subject digest:
11ca0f041c088e2d935b1f02ebf445f9f58608ab4083beabfa6148964cff5edc - Sigstore transparency entry: 1506000093
- Sigstore integration time:
-
Permalink:
emam07/Token-tracker@b6237d4167877d725fbd00b1ddbc41ab94eb94f6 -
Branch / Tag:
refs/tags/v0.2.3 - Owner: https://github.com/emam07
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@b6237d4167877d725fbd00b1ddbc41ab94eb94f6 -
Trigger Event:
push
-
Statement type: