tokenleak 0.1.0
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.
- package/README.md +166 -0
- package/package.json +35 -0
- package/tokenleak.js +2382 -0
package/README.md
ADDED
|
@@ -0,0 +1,166 @@
|
|
|
1
|
+
# Tokenleak
|
|
2
|
+
|
|
3
|
+
A CLI tool that surfaces your AI coding-assistant token usage as beautiful heatmaps, terminal dashboards, and shareable cards. Supports **Claude Code**, **Codex**, and **Open Code**.
|
|
4
|
+
|
|
5
|
+
## Features
|
|
6
|
+
|
|
7
|
+
- Heatmap visualisation of daily token usage (contribution-graph style)
|
|
8
|
+
- Terminal dashboard with ANSI colours and Unicode block characters
|
|
9
|
+
- SVG and PNG image export for sharing
|
|
10
|
+
- JSON export for downstream tooling
|
|
11
|
+
- Streak tracking (current and longest)
|
|
12
|
+
- Cost estimation with per-model pricing
|
|
13
|
+
- Rolling 30-day window statistics
|
|
14
|
+
- Day-of-week usage breakdown
|
|
15
|
+
- Multi-provider support with automatic detection
|
|
16
|
+
- Configuration file support (`~/.tokenleakrc`)
|
|
17
|
+
|
|
18
|
+
## Quick Start
|
|
19
|
+
|
|
20
|
+
```bash
|
|
21
|
+
# Install globally with bun
|
|
22
|
+
bun install -g tokenleak
|
|
23
|
+
|
|
24
|
+
# Or clone and build from source
|
|
25
|
+
git clone https://github.com/ya-nsh/tokenleak.git
|
|
26
|
+
cd tokenleak
|
|
27
|
+
bun install
|
|
28
|
+
bun run build
|
|
29
|
+
|
|
30
|
+
# Run
|
|
31
|
+
bun run packages/cli/dist/cli.js
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
## Usage
|
|
35
|
+
|
|
36
|
+
```bash
|
|
37
|
+
# Terminal dashboard (default)
|
|
38
|
+
tokenleak
|
|
39
|
+
|
|
40
|
+
# JSON output
|
|
41
|
+
tokenleak --format json
|
|
42
|
+
|
|
43
|
+
# SVG heatmap
|
|
44
|
+
tokenleak --format svg --output usage.svg
|
|
45
|
+
|
|
46
|
+
# PNG heatmap
|
|
47
|
+
tokenleak --format png --output usage.png
|
|
48
|
+
|
|
49
|
+
# Filter to last 90 days
|
|
50
|
+
tokenleak --days 90
|
|
51
|
+
|
|
52
|
+
# Custom date range
|
|
53
|
+
tokenleak --since 2025-01-01 --until 2025-12-31
|
|
54
|
+
|
|
55
|
+
# Filter to a specific provider
|
|
56
|
+
tokenleak --provider claude-code
|
|
57
|
+
|
|
58
|
+
# Compare two date ranges
|
|
59
|
+
tokenleak --compare 2025-01-01..2025-06-30
|
|
60
|
+
|
|
61
|
+
# Dark theme (default) / light theme
|
|
62
|
+
tokenleak --theme light
|
|
63
|
+
|
|
64
|
+
# Disable ANSI colours
|
|
65
|
+
tokenleak --no-color
|
|
66
|
+
|
|
67
|
+
# Write output to a file (format inferred from extension)
|
|
68
|
+
tokenleak --output report.json
|
|
69
|
+
```
|
|
70
|
+
|
|
71
|
+
### All Flags
|
|
72
|
+
|
|
73
|
+
| Flag | Alias | Description |
|
|
74
|
+
|------|-------|-------------|
|
|
75
|
+
| `--format` | `-f` | Output format: `json`, `svg`, `png`, `terminal` |
|
|
76
|
+
| `--theme` | `-t` | Colour theme: `dark`, `light` |
|
|
77
|
+
| `--since` | `-s` | Start date (`YYYY-MM-DD`) |
|
|
78
|
+
| `--until` | `-u` | End date (`YYYY-MM-DD`), defaults to today |
|
|
79
|
+
| `--days` | `-d` | Number of days to look back (default: 365) |
|
|
80
|
+
| `--output` | `-o` | Output file path |
|
|
81
|
+
| `--width` | `-w` | Terminal width (default: 80) |
|
|
82
|
+
| `--no-color` | | Disable ANSI colours in terminal output |
|
|
83
|
+
| `--no-insights` | | Hide the insights panel |
|
|
84
|
+
| `--compare` | | Compare two date ranges (`YYYY-MM-DD..YYYY-MM-DD`) |
|
|
85
|
+
| `--provider` | `-p` | Filter to specific provider(s), comma-separated |
|
|
86
|
+
| `--version` | `-v` | Print version |
|
|
87
|
+
| `--help` | `-h` | Print usage information |
|
|
88
|
+
|
|
89
|
+
## Supported Providers
|
|
90
|
+
|
|
91
|
+
### Claude Code
|
|
92
|
+
|
|
93
|
+
Reads JSONL conversation logs from the Claude Code configuration directory.
|
|
94
|
+
|
|
95
|
+
- **macOS/Linux**: `~/.claude/projects/*/`
|
|
96
|
+
- **Custom**: Set `CLAUDE_CONFIG_DIR` environment variable
|
|
97
|
+
|
|
98
|
+
### Codex
|
|
99
|
+
|
|
100
|
+
Reads JSONL session logs from the Codex home directory.
|
|
101
|
+
|
|
102
|
+
- **Default**: `~/.codex/sessions/`
|
|
103
|
+
- **Custom**: Set `CODEX_HOME` environment variable
|
|
104
|
+
|
|
105
|
+
### Open Code
|
|
106
|
+
|
|
107
|
+
Reads usage data from the Open Code SQLite database or legacy JSON files.
|
|
108
|
+
|
|
109
|
+
- **Default**: `~/.opencode/opencode.db`
|
|
110
|
+
|
|
111
|
+
## Configuration
|
|
112
|
+
|
|
113
|
+
Create a `~/.tokenleakrc` file with JSON to set defaults:
|
|
114
|
+
|
|
115
|
+
```json
|
|
116
|
+
{
|
|
117
|
+
"format": "terminal",
|
|
118
|
+
"theme": "dark",
|
|
119
|
+
"days": 365,
|
|
120
|
+
"width": 120,
|
|
121
|
+
"noColor": false,
|
|
122
|
+
"noInsights": false
|
|
123
|
+
}
|
|
124
|
+
```
|
|
125
|
+
|
|
126
|
+
CLI flags always override configuration file values.
|
|
127
|
+
|
|
128
|
+
## Environment Variables
|
|
129
|
+
|
|
130
|
+
| Variable | Default | Description |
|
|
131
|
+
|----------|---------|-------------|
|
|
132
|
+
| `TOKENLEAK_FILE_PROCESS_CONCURRENCY` | `4` | Number of files to process concurrently |
|
|
133
|
+
| `TOKENLEAK_MAX_JSONL_RECORD_BYTES` | `67108864` (64 MB) | Maximum size of a single JSONL record |
|
|
134
|
+
| `TOKENLEAK_PRICING_OVERRIDE` | | Path to a custom pricing JSON file |
|
|
135
|
+
| `CLAUDE_CONFIG_DIR` | `~/.claude` | Claude Code configuration directory |
|
|
136
|
+
| `CODEX_HOME` | `~/.codex` | Codex home directory |
|
|
137
|
+
|
|
138
|
+
## Output Formats
|
|
139
|
+
|
|
140
|
+
| Format | Description |
|
|
141
|
+
|--------|-------------|
|
|
142
|
+
| `terminal` | ANSI dashboard with heatmap and stats, rendered in the shell |
|
|
143
|
+
| `json` | Structured JSON export with daily data, insights, and aggregated stats |
|
|
144
|
+
| `svg` | SVG heatmap with stats and insights panels |
|
|
145
|
+
| `png` | PNG heatmap rendered via `@napi-rs/canvas` |
|
|
146
|
+
|
|
147
|
+
## Project Structure
|
|
148
|
+
|
|
149
|
+
```
|
|
150
|
+
tokenleak/
|
|
151
|
+
packages/
|
|
152
|
+
cli/ -- Main CLI entrypoint
|
|
153
|
+
core/ -- Data types, aggregation engine
|
|
154
|
+
registry/ -- Provider parsers (Claude Code, Codex, Open Code)
|
|
155
|
+
renderers/ -- JSON, SVG, PNG, terminal renderers
|
|
156
|
+
tooling/
|
|
157
|
+
typescript-config/
|
|
158
|
+
```
|
|
159
|
+
|
|
160
|
+
## Contributing
|
|
161
|
+
|
|
162
|
+
See [CONTRIBUTING.md](./CONTRIBUTING.md) for development setup, PR workflow, and coding guidelines.
|
|
163
|
+
|
|
164
|
+
## License
|
|
165
|
+
|
|
166
|
+
MIT
|
package/package.json
ADDED
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "tokenleak",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "Visualise your AI coding-assistant token usage across providers — heatmaps, dashboards, and shareable cards.",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"bin": {
|
|
7
|
+
"tokenleak": "./tokenleak.js"
|
|
8
|
+
},
|
|
9
|
+
"files": [
|
|
10
|
+
"tokenleak.js"
|
|
11
|
+
],
|
|
12
|
+
"dependencies": {
|
|
13
|
+
"sharp": "^0.34.0"
|
|
14
|
+
},
|
|
15
|
+
"engines": {
|
|
16
|
+
"bun": ">=1.0.0"
|
|
17
|
+
},
|
|
18
|
+
"keywords": [
|
|
19
|
+
"ai",
|
|
20
|
+
"tokens",
|
|
21
|
+
"usage",
|
|
22
|
+
"claude",
|
|
23
|
+
"codex",
|
|
24
|
+
"opencode",
|
|
25
|
+
"heatmap",
|
|
26
|
+
"dashboard",
|
|
27
|
+
"cli"
|
|
28
|
+
],
|
|
29
|
+
"repository": {
|
|
30
|
+
"type": "git",
|
|
31
|
+
"url": "https://github.com/ya-nsh/tokenleak.git"
|
|
32
|
+
},
|
|
33
|
+
"license": "MIT",
|
|
34
|
+
"author": "ya-nsh"
|
|
35
|
+
}
|