tokstat 1.0.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
tokstat-1.0.0/PKG-INFO ADDED
@@ -0,0 +1,202 @@
1
+ Metadata-Version: 2.4
2
+ Name: tokstat
3
+ Version: 1.0.0
4
+ Summary: Aggregate and analyze Claude Code token consumption from local JSONL transcripts
5
+ License-Expression: MIT
6
+ Keywords: claude,token,usage,ai,llm,cost
7
+ Classifier: Development Status :: 4 - Beta
8
+ Classifier: Environment :: Console
9
+ Classifier: Intended Audience :: Developers
10
+ Classifier: Programming Language :: Python :: 3
11
+ Classifier: Programming Language :: Python :: 3.10
12
+ Classifier: Programming Language :: Python :: 3.11
13
+ Classifier: Programming Language :: Python :: 3.12
14
+ Classifier: Programming Language :: Python :: 3.13
15
+ Classifier: Topic :: Utilities
16
+ Requires-Python: >=3.10
17
+ Description-Content-Type: text/markdown
18
+
19
+ # claude-token-usage
20
+
21
+ Single-file CLI tool that aggregates and displays token consumption across AI coding assistants. Scans local log files, estimates costs using live [LiteLLM](https://github.com/BerriAI/litellm) pricing data, and prints everything in a color-coded terminal table.
22
+
23
+ ## Supported tools
24
+
25
+ All 7 tools are supported in all modes (default, --prompts, --audit, --anomalies, --plan, --export). The table below shows what data is available from each tool's data sources:
26
+
27
+ | Tool | Data source | Tokens | Text | Tools | Speed |
28
+ |------|-------------|--------|------|-------|-------|
29
+ | Claude Code | `~/.claude/projects/` | ✓ | ✓ | ✓ | ✓ |
30
+ | Codex (OpenAI) | `~/.codex/sessions/` | ✓ | ✓ | — | ✓ |
31
+ | Gemini CLI | `~/.gemini/` | ✓ | — | — | ✓ |
32
+ | Cline | `~/.cline/data/sessions/` | ✓ | — | — | — |
33
+ | OpenCode | `~/.local/share/opencode/` | ✓ | ✓ | ✓ | — |
34
+ | Qwen Coder | `~/.qwen/` | ✓ | ✓ | ✓ | — |
35
+ | Kiro | `~/Library/Application Support/Kiro/` | — | ✓ | ✓ | — |
36
+
37
+ **Not supported:** Cursor (token data is tracked server-side only, not stored in the local database).
38
+
39
+ Tools not installed are silently skipped.
40
+
41
+ ## Installation
42
+
43
+ No dependencies. Requires Python 3.10+.
44
+
45
+ ```sh
46
+ chmod +x claude-token-usage
47
+ ln -s $(pwd)/claude-token-usage ~/.local/bin/claude-token-usage
48
+ ```
49
+
50
+ ## Global options
51
+
52
+ All modes support these filters:
53
+
54
+ ```sh
55
+ --period <period> Time filter — all, hour, "5 hours", today, yesterday, "7 days", "30 days", year (default: today)
56
+ --tool <name> Tool filter — claude, codex, gemini, cline, opencode, qwen, kiro (default: all)
57
+ ```
58
+
59
+ **Periods**: Partial match works (`"7"` = `"Last 7 days"`).
60
+
61
+ **Tools**: Aliases work (`openai` = Codex, `claude-code` = Claude Code). All 7 tools work in all 6 modes.
62
+
63
+ ## Modes
64
+
65
+ ### Default — aggregated overview
66
+
67
+ ```sh
68
+ claude-token-usage # all tools, today (default period)
69
+ claude-token-usage --period all # all tools, all time
70
+ claude-token-usage --tool claude # Claude Code only, today
71
+ claude-token-usage --tool claude --period "7 days"
72
+ ```
73
+
74
+ Displays: consumption by period, by project, by model, output speed, and grand total.
75
+
76
+ ### `--prompts` — per-exchange detail (all tools)
77
+
78
+ ```sh
79
+ claude-token-usage --prompts
80
+ claude-token-usage -p --period today
81
+ claude-token-usage --prompts --tool cursor --period "7 days"
82
+ ```
83
+
84
+ Per-exchange breakdown: user text, model, turns, tokens (input/output/cache), tool calls, cost. Works for all 8 tools.
85
+
86
+ ### `--audit` — behavioral anti-pattern detection
87
+
88
+ ```sh
89
+ claude-token-usage --audit
90
+ claude-token-usage -a --tool opencode --period "30 days"
91
+ ```
92
+
93
+ Scans assistant transcripts for 11 categories of behavioral anti-patterns across all 8 tools (Claude Code, Codex, Gemini CLI, Cline, OpenCode, Qwen Coder, Cursor, Kiro). Each finding is tagged with tool and model. Summary tables show breakdown by category, by tool, and by model with incident rates.
94
+
95
+ #### Detection categories
96
+
97
+ | Abbr. | Category | What it detects |
98
+ |-------|----------|----------------|
99
+ | Gaslt | Gaslighting contextuel | Denying previous statements, rewriting history |
100
+ | Anthr | Anthropomorphisme / fausse empathie | False emotions, fake experience claims |
101
+ | Hedge | Dilution par prudence | Dense hedging clusters in a single sentence |
102
+ | Lazy | Paresse intellectuelle | Deflecting to docs, generic non-answers, filler |
103
+ | Overc | Aplomb trompeur | Confident assertions followed by tool errors |
104
+ | Sycop | Flagornerie / sycophancy | Excessive praise, performative agreement |
105
+ | Compl | Acquiescement performatif | "You're right, but..." patterns |
106
+ | Prem. | Solution prematuree | Declaring victory before verification |
107
+ | Loop | Boucle d'echec | User reports same failure 3+ times |
108
+ | Verb. | Verbosite creuse | Long structured response to short question |
109
+ | FakeU | Comprehension feinte | "I understand" without addressing the issue |
110
+
111
+ All patterns detect both French and English. Metalanguage and code blocks are filtered out.
112
+
113
+ ### `--anomalies` — technical anomaly detection
114
+
115
+ ```sh
116
+ claude-token-usage --anomalies
117
+ claude-token-usage --anomalies --tool claude --period "30 days"
118
+ ```
119
+
120
+ Detects unusual patterns in per-exchange token data across all 8 tools (Claude Code, Codex, Gemini CLI, Cline, OpenCode, Qwen Coder, Cursor, Kiro). Results grouped by project with worktree resolution.
121
+
122
+ | Anomaly | Trigger | Severity |
123
+ |---------|---------|----------|
124
+ | Runaway cost | Prompt costs 10x+ the P90 | HIGH |
125
+ | High cost | Prompt costs 5x+ the P90 | MEDIUM |
126
+ | Tool storm | 30+ tool calls in a single prompt | HIGH >60, MEDIUM >30 |
127
+ | Turn spiral | API turns 5x+ the P90 | HIGH >10x, MEDIUM >5x |
128
+ | Cache thrashing | High cache writes with <50% read-back | MEDIUM |
129
+ | Context bloat | Input/output ratio >50:1 with >10K input | LOW |
130
+ | Empty exchange | 5+ turns but <100 output tokens | MEDIUM |
131
+
132
+ Thresholds are computed dynamically from the user's own data (median, P90).
133
+
134
+ ### `--plan` — plan & optimization recommendations
135
+
136
+ ```sh
137
+ claude-token-usage --plan
138
+ claude-token-usage --plan --tool claude --period "30 days"
139
+ ```
140
+
141
+ Cost breakdown by model, plan recommendation, and data-driven optimization advice.
142
+
143
+ - **Cost table** — per-model: calls, cost, avg/day, projected monthly, cache efficiency, share
144
+ - **Plan mapping** — Free (<$5/mo), Pro (<$18/mo), Max 5x (<$100/mo), Max 20x (<$200/mo), Enterprise (>$500/mo)
145
+ - **Optimization recommendations** (conditional, only when data supports them):
146
+ - **Model selection** — if top model takes >80% of spend, suggests cheaper alternative from same family (looked up dynamically from LiteLLM pricing)
147
+ - **Cache optimization** — if hit rate <70%, suggests longer sessions
148
+ - **Guardrails** — if runaway agents detected, suggests max_turns and hooks
149
+ - **Context reduction** — if cache writes >5M, suggests CLAUDE.md, RTK, Repomix, .claudeignore
150
+ - **Spending hygiene** — if peak day >5x average, suggests budget alerts
151
+ - **Tool diversification** — if using single tool, suggests alternatives with free tiers
152
+
153
+ ```
154
+ All time — 17 active days / 30
155
+
156
+ Model Calls Cost Avg/day Projected/mo Cache Share
157
+ ───────────────── ───── ─────── ──────── ──────────── ───── ─────
158
+ claude-opus-4-6 321 $475.19 $15.84/d $475.19/mo 96% 100%
159
+ claude-sonnet-4-6 8 $0.811 $0.027/d $0.811/mo 96% 0%
160
+ TOTAL 329 $476.00 $15.87/d $476.00/mo 96%
161
+
162
+ Plan (based on All time)
163
+ Max 20x ($200/mo) strongly recommended.
164
+ Projected API cost: $476.00/mo — you'd save ~$276.00/mo
165
+
166
+ Optimization Recommendations
167
+
168
+ Model selection
169
+ 100% of spend is on claude-opus-4-6. claude-sonnet-4-6 is 2x cheaper.
170
+ - Use claude-sonnet-4-6 for simple tasks
171
+ - Switching 30% would save ~$49.78/mo
172
+ ```
173
+
174
+ ### `--export` — conversation export
175
+
176
+ ```sh
177
+ claude-token-usage --export
178
+ claude-token-usage --export out.json --tool kiro --period year
179
+ ```
180
+
181
+ Exports all exchanges to a single JSON file. Works for all 8 tools. Applies all filters (--period, --tool).
182
+
183
+ ```json
184
+ {
185
+ "tool": "Claude Code",
186
+ "model": "claude-opus-4-6",
187
+ "timestamp": "2026-04-08T...",
188
+ "user": "the user prompt text",
189
+ "assistant": ["response 1", "response 2"],
190
+ "turns": 25,
191
+ "tools_used": {"Bash": 3, "Read": 7, "Edit": 2},
192
+ "tool_errors": ["error message"]
193
+ }
194
+ ```
195
+
196
+ ## Pricing
197
+
198
+ Model pricing is fetched from [LiteLLM's model pricing database](https://github.com/BerriAI/litellm/blob/main/model_prices_and_context_window.json) and cached locally at `~/.cache/token-usage/litellm_prices.json` for 24 hours. Falls back to stale cache if fetch fails.
199
+
200
+ ## Project normalization
201
+
202
+ Git worktrees (including Cline worktrees under `~/.cline/worktrees/`) are automatically resolved to their main project, so usage from multiple worktrees is aggregated under a single entry.
@@ -0,0 +1,184 @@
1
+ # claude-token-usage
2
+
3
+ Single-file CLI tool that aggregates and displays token consumption across AI coding assistants. Scans local log files, estimates costs using live [LiteLLM](https://github.com/BerriAI/litellm) pricing data, and prints everything in a color-coded terminal table.
4
+
5
+ ## Supported tools
6
+
7
+ All 7 tools are supported in all modes (default, --prompts, --audit, --anomalies, --plan, --export). The table below shows what data is available from each tool's data sources:
8
+
9
+ | Tool | Data source | Tokens | Text | Tools | Speed |
10
+ |------|-------------|--------|------|-------|-------|
11
+ | Claude Code | `~/.claude/projects/` | ✓ | ✓ | ✓ | ✓ |
12
+ | Codex (OpenAI) | `~/.codex/sessions/` | ✓ | ✓ | — | ✓ |
13
+ | Gemini CLI | `~/.gemini/` | ✓ | — | — | ✓ |
14
+ | Cline | `~/.cline/data/sessions/` | ✓ | — | — | — |
15
+ | OpenCode | `~/.local/share/opencode/` | ✓ | ✓ | ✓ | — |
16
+ | Qwen Coder | `~/.qwen/` | ✓ | ✓ | ✓ | — |
17
+ | Kiro | `~/Library/Application Support/Kiro/` | — | ✓ | ✓ | — |
18
+
19
+ **Not supported:** Cursor (token data is tracked server-side only, not stored in the local database).
20
+
21
+ Tools not installed are silently skipped.
22
+
23
+ ## Installation
24
+
25
+ No dependencies. Requires Python 3.10+.
26
+
27
+ ```sh
28
+ chmod +x claude-token-usage
29
+ ln -s $(pwd)/claude-token-usage ~/.local/bin/claude-token-usage
30
+ ```
31
+
32
+ ## Global options
33
+
34
+ All modes support these filters:
35
+
36
+ ```sh
37
+ --period <period> Time filter — all, hour, "5 hours", today, yesterday, "7 days", "30 days", year (default: today)
38
+ --tool <name> Tool filter — claude, codex, gemini, cline, opencode, qwen, kiro (default: all)
39
+ ```
40
+
41
+ **Periods**: Partial match works (`"7"` = `"Last 7 days"`).
42
+
43
+ **Tools**: Aliases work (`openai` = Codex, `claude-code` = Claude Code). All 7 tools work in all 6 modes.
44
+
45
+ ## Modes
46
+
47
+ ### Default — aggregated overview
48
+
49
+ ```sh
50
+ claude-token-usage # all tools, today (default period)
51
+ claude-token-usage --period all # all tools, all time
52
+ claude-token-usage --tool claude # Claude Code only, today
53
+ claude-token-usage --tool claude --period "7 days"
54
+ ```
55
+
56
+ Displays: consumption by period, by project, by model, output speed, and grand total.
57
+
58
+ ### `--prompts` — per-exchange detail (all tools)
59
+
60
+ ```sh
61
+ claude-token-usage --prompts
62
+ claude-token-usage -p --period today
63
+ claude-token-usage --prompts --tool cursor --period "7 days"
64
+ ```
65
+
66
+ Per-exchange breakdown: user text, model, turns, tokens (input/output/cache), tool calls, cost. Works for all 8 tools.
67
+
68
+ ### `--audit` — behavioral anti-pattern detection
69
+
70
+ ```sh
71
+ claude-token-usage --audit
72
+ claude-token-usage -a --tool opencode --period "30 days"
73
+ ```
74
+
75
+ Scans assistant transcripts for 11 categories of behavioral anti-patterns across all 8 tools (Claude Code, Codex, Gemini CLI, Cline, OpenCode, Qwen Coder, Cursor, Kiro). Each finding is tagged with tool and model. Summary tables show breakdown by category, by tool, and by model with incident rates.
76
+
77
+ #### Detection categories
78
+
79
+ | Abbr. | Category | What it detects |
80
+ |-------|----------|----------------|
81
+ | Gaslt | Gaslighting contextuel | Denying previous statements, rewriting history |
82
+ | Anthr | Anthropomorphisme / fausse empathie | False emotions, fake experience claims |
83
+ | Hedge | Dilution par prudence | Dense hedging clusters in a single sentence |
84
+ | Lazy | Paresse intellectuelle | Deflecting to docs, generic non-answers, filler |
85
+ | Overc | Aplomb trompeur | Confident assertions followed by tool errors |
86
+ | Sycop | Flagornerie / sycophancy | Excessive praise, performative agreement |
87
+ | Compl | Acquiescement performatif | "You're right, but..." patterns |
88
+ | Prem. | Solution prematuree | Declaring victory before verification |
89
+ | Loop | Boucle d'echec | User reports same failure 3+ times |
90
+ | Verb. | Verbosite creuse | Long structured response to short question |
91
+ | FakeU | Comprehension feinte | "I understand" without addressing the issue |
92
+
93
+ All patterns detect both French and English. Metalanguage and code blocks are filtered out.
94
+
95
+ ### `--anomalies` — technical anomaly detection
96
+
97
+ ```sh
98
+ claude-token-usage --anomalies
99
+ claude-token-usage --anomalies --tool claude --period "30 days"
100
+ ```
101
+
102
+ Detects unusual patterns in per-exchange token data across all 8 tools (Claude Code, Codex, Gemini CLI, Cline, OpenCode, Qwen Coder, Cursor, Kiro). Results grouped by project with worktree resolution.
103
+
104
+ | Anomaly | Trigger | Severity |
105
+ |---------|---------|----------|
106
+ | Runaway cost | Prompt costs 10x+ the P90 | HIGH |
107
+ | High cost | Prompt costs 5x+ the P90 | MEDIUM |
108
+ | Tool storm | 30+ tool calls in a single prompt | HIGH >60, MEDIUM >30 |
109
+ | Turn spiral | API turns 5x+ the P90 | HIGH >10x, MEDIUM >5x |
110
+ | Cache thrashing | High cache writes with <50% read-back | MEDIUM |
111
+ | Context bloat | Input/output ratio >50:1 with >10K input | LOW |
112
+ | Empty exchange | 5+ turns but <100 output tokens | MEDIUM |
113
+
114
+ Thresholds are computed dynamically from the user's own data (median, P90).
115
+
116
+ ### `--plan` — plan & optimization recommendations
117
+
118
+ ```sh
119
+ claude-token-usage --plan
120
+ claude-token-usage --plan --tool claude --period "30 days"
121
+ ```
122
+
123
+ Cost breakdown by model, plan recommendation, and data-driven optimization advice.
124
+
125
+ - **Cost table** — per-model: calls, cost, avg/day, projected monthly, cache efficiency, share
126
+ - **Plan mapping** — Free (<$5/mo), Pro (<$18/mo), Max 5x (<$100/mo), Max 20x (<$200/mo), Enterprise (>$500/mo)
127
+ - **Optimization recommendations** (conditional, only when data supports them):
128
+ - **Model selection** — if top model takes >80% of spend, suggests cheaper alternative from same family (looked up dynamically from LiteLLM pricing)
129
+ - **Cache optimization** — if hit rate <70%, suggests longer sessions
130
+ - **Guardrails** — if runaway agents detected, suggests max_turns and hooks
131
+ - **Context reduction** — if cache writes >5M, suggests CLAUDE.md, RTK, Repomix, .claudeignore
132
+ - **Spending hygiene** — if peak day >5x average, suggests budget alerts
133
+ - **Tool diversification** — if using single tool, suggests alternatives with free tiers
134
+
135
+ ```
136
+ All time — 17 active days / 30
137
+
138
+ Model Calls Cost Avg/day Projected/mo Cache Share
139
+ ───────────────── ───── ─────── ──────── ──────────── ───── ─────
140
+ claude-opus-4-6 321 $475.19 $15.84/d $475.19/mo 96% 100%
141
+ claude-sonnet-4-6 8 $0.811 $0.027/d $0.811/mo 96% 0%
142
+ TOTAL 329 $476.00 $15.87/d $476.00/mo 96%
143
+
144
+ Plan (based on All time)
145
+ Max 20x ($200/mo) strongly recommended.
146
+ Projected API cost: $476.00/mo — you'd save ~$276.00/mo
147
+
148
+ Optimization Recommendations
149
+
150
+ Model selection
151
+ 100% of spend is on claude-opus-4-6. claude-sonnet-4-6 is 2x cheaper.
152
+ - Use claude-sonnet-4-6 for simple tasks
153
+ - Switching 30% would save ~$49.78/mo
154
+ ```
155
+
156
+ ### `--export` — conversation export
157
+
158
+ ```sh
159
+ claude-token-usage --export
160
+ claude-token-usage --export out.json --tool kiro --period year
161
+ ```
162
+
163
+ Exports all exchanges to a single JSON file. Works for all 8 tools. Applies all filters (--period, --tool).
164
+
165
+ ```json
166
+ {
167
+ "tool": "Claude Code",
168
+ "model": "claude-opus-4-6",
169
+ "timestamp": "2026-04-08T...",
170
+ "user": "the user prompt text",
171
+ "assistant": ["response 1", "response 2"],
172
+ "turns": 25,
173
+ "tools_used": {"Bash": 3, "Read": 7, "Edit": 2},
174
+ "tool_errors": ["error message"]
175
+ }
176
+ ```
177
+
178
+ ## Pricing
179
+
180
+ Model pricing is fetched from [LiteLLM's model pricing database](https://github.com/BerriAI/litellm/blob/main/model_prices_and_context_window.json) and cached locally at `~/.cache/token-usage/litellm_prices.json` for 24 hours. Falls back to stale cache if fetch fails.
181
+
182
+ ## Project normalization
183
+
184
+ Git worktrees (including Cline worktrees under `~/.cline/worktrees/`) are automatically resolved to their main project, so usage from multiple worktrees is aggregated under a single entry.
@@ -0,0 +1,29 @@
1
+ [build-system]
2
+ requires = ["setuptools>=68", "wheel"]
3
+ build-backend = "setuptools.build_meta"
4
+
5
+ [project]
6
+ name = "tokstat"
7
+ version = "1.0.0"
8
+ description = "Aggregate and analyze Claude Code token consumption from local JSONL transcripts"
9
+ readme = "README.md"
10
+ license = "MIT"
11
+ requires-python = ">=3.10"
12
+ keywords = ["claude", "token", "usage", "ai", "llm", "cost"]
13
+ classifiers = [
14
+ "Development Status :: 4 - Beta",
15
+ "Environment :: Console",
16
+ "Intended Audience :: Developers",
17
+ "Programming Language :: Python :: 3",
18
+ "Programming Language :: Python :: 3.10",
19
+ "Programming Language :: Python :: 3.11",
20
+ "Programming Language :: Python :: 3.12",
21
+ "Programming Language :: Python :: 3.13",
22
+ "Topic :: Utilities",
23
+ ]
24
+
25
+ [project.scripts]
26
+ claude-token-usage = "tokstat.cli:cli"
27
+
28
+ [tool.setuptools.packages.find]
29
+ where = ["src"]
@@ -0,0 +1,4 @@
1
+ [egg_info]
2
+ tag_build =
3
+ tag_date = 0
4
+
@@ -0,0 +1,3 @@
1
+ from tokstat.cli import __version__
2
+
3
+ __all__ = ["__version__"]