Scan your Claude Code logs and find the habits silently burning your tokens. No LLM calls, no dependencies, runs offline.
Project description
tokenhabit
What's leaking your Claude Code tokens? Scan your local logs and find out in one command.
ccusage tells you how much you spent. tokenhabit tells you which habits spent it — and how to stop.
No LLM calls. No dependencies. Runs fully offline on your own ~/.claude logs.
Sample run on synthetic logs — your real numbers will differ.
$ uvx tokenhabit
════════════════════════════════════════════════════════════════
tokenhabit — habit scan 2026-06-15 17:29
Window: last 7d | session files: 236 | analyzed: 236
════════════════════════════════════════════════════════════════
[Totals] tokens: 9,166,840 | input: 4,775,023 | output: 4,390,643
cache hits: 1,251,474,403 (95.3%)
Token Waste Score: C — ~14% of your tokens were likely wasted (8,370,759 tok)
[Detected habits] (by catalog ID, most frequent first)
────────────────────────────────────────────────────────────────
[H1-03] Compaction overrun (token pile-up) ×217
est. waste: ~3,255,000 tokens
fix: Run /compact [focus] manually before you hit ~50K tokens.
[H1-01] Topic drift / marathon session ×221
est. waste: ~2,210,000 tokens
fix: At ~35 min / ~50K tokens, /compact or /clear and start a fresh session.
[H4-03] Cache-kill switch (cache hit-rate crash) ×78
est. waste: ~1,638,000 tokens
fix: Avoid switching model/effort mid-session. Open a new session when you must switch.
... (3 more)
Share: I was wasting ~14% of my Claude Code tokens. Top leak: Compaction overrun. — tokenhabit
Quick start
No install needed:
uvx tokenhabit # with uv (recommended)
pipx run tokenhabit # with pipx
Or install it:
uv tool install tokenhabit
# or
pip install tokenhabit
Then just run tokenhabit. It scans ~/.claude/projects/*.jsonl for the last 7 days and prints your report.
Prefer the bleeding edge? Run straight from the repo:
uvx --from git+https://github.com/epoko77-ai/tokenhabit tokenhabit
Usage
tokenhabit # last 7 days, all projects
tokenhabit --days 14 # last 14 days
tokenhabit --project /path # a single project directory
tokenhabit --session run.jsonl # a single session file
tokenhabit --lang ko # Korean report
tokenhabit --json # machine-readable (CI / piping)
tokenhabit --ccusage # also show `npx ccusage daily` totals
What it detects
tokenhabit reads your raw session logs and flags the habits that quietly burn tokens. The ten it can measure directly from logs:
| ID | Habit | Fix |
|---|---|---|
| H1-01 | Topic drift / marathon session | /clear or /compact at topic switches |
| H1-03 | Compaction overrun (token pile-up) | Manual /compact [focus] before ~50K |
| H2-01 | Re-reading the same file | Reference what's already in context |
| H2-02 | Dumping full logs / stdout flood | Filter with grep/head first |
| H2-04 | Stranded web results (signal) | Delegate research to a subagent |
| H4-03 | Cache-kill switch (hit-rate crash) | Don't switch model/effort mid-session |
| H5-04 | Inviting verbose output | Cap output ("in 2 lines") |
| H8-01 | Main-thread exploration | Delegate sweeps to a subagent |
| H8-02 | stdout flood (large Bash output) | Pipe to head/save to file |
| H8-03 | Subagent overuse (signal) | Delegate only big independent work |
These are 10 of a larger 28-pattern habit catalog (signal = frequency-only, not scored into the waste total). The remaining patterns (prompt clarity, CLAUDE.md hygiene, MCP setup, …) can't be judged from logs alone — for full interactive coaching, see the Claude Code skill below.
How the score works
The Token Waste Score is the share-worthy headline: estimated wasted tokens as a percentage of your billable work tokens (input + output + cache creation). Cache reads are deliberately excluded from the denominator — they're cheap and so voluminous they'd dilute every score to ~1%.
All numbers are trend-spotting approximations, not exact billing. The point is to surface which habit dominates, not to reconcile your invoice.
How it differs from ccusage
| ccusage | tokenhabit | |
|---|---|---|
| Question | How much did I spend? | Which habits spent it? |
| Output | Cost/token totals | Ranked habits + copy-paste fixes |
| LLM calls | none | none |
| Use them together | tokenhabit --ccusage shows both |
They're complementary. ccusage measures; tokenhabit diagnoses and prescribes.
The Claude Code skill
tokenhabit also ships as a Claude Code skill for interactive coaching across
the full 28-pattern catalog (session triage, prompt rewriting, runtime guard
hooks). See skill/. The CLI is the fast offline scan; the skill is
the deeper coach.
Privacy
Everything runs locally. tokenhabit only reads your own ~/.claude log files and
never sends anything anywhere. (The optional --ccusage flag shells out to
npx ccusage, which is also local.)
License
MIT © Seunghyun Lee
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 tokenhabit-1.2.1.tar.gz.
File metadata
- Download URL: tokenhabit-1.2.1.tar.gz
- Upload date:
- Size: 4.8 MB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.14.4
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
15fb18bdded8affc351c05c4590644aec3cfca0d45d9cfe2b678276b7e50a55b
|
|
| MD5 |
053945e13eebb8b481b3666efb4f727f
|
|
| BLAKE2b-256 |
402cdbeb16ce0de921d8a6d33ae55bb1a531db9f99f93aed0664db908c313a58
|
File details
Details for the file tokenhabit-1.2.1-py3-none-any.whl.
File metadata
- Download URL: tokenhabit-1.2.1-py3-none-any.whl
- Upload date:
- Size: 15.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.14.4
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
f5324e0ca4ae4a9a038b6246d99564f8f31e3c77aa3869cd43608c0c43c1f676
|
|
| MD5 |
37fde459f30b12bd8777ab34e414efd0
|
|
| BLAKE2b-256 |
62c8eea8c57f63b4fa662db81eb7c7aba9e0b8a8b772fe6c724706a4c5d2530c
|