cctotals 1.0.1 → 1.0.3
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/.github/workflows/publish.yml +29 -3
- package/README.md +67 -0
- package/package.json +1 -1
- package/token-graph.js +38 -45
|
@@ -9,17 +9,43 @@ jobs:
|
|
|
9
9
|
runs-on: ubuntu-latest
|
|
10
10
|
steps:
|
|
11
11
|
- uses: actions/checkout@v4
|
|
12
|
+
with:
|
|
13
|
+
fetch-depth: 0
|
|
12
14
|
|
|
13
15
|
- uses: actions/setup-node@v4
|
|
14
16
|
with:
|
|
15
17
|
node-version: '20'
|
|
16
18
|
registry-url: 'https://registry.npmjs.org'
|
|
17
19
|
|
|
18
|
-
- name:
|
|
20
|
+
- name: Setup git and npm
|
|
19
21
|
run: |
|
|
22
|
+
git config --local user.email "github-actions[bot]@users.noreply.github.com"
|
|
23
|
+
git config --local user.name "github-actions[bot]"
|
|
20
24
|
echo "//registry.npmjs.org/:_authToken=$NPM_TOKEN" > .npmrc
|
|
21
25
|
npm install -g npm
|
|
22
|
-
npm version patch --git-tag-version=false
|
|
23
|
-
npm publish --access public
|
|
24
26
|
env:
|
|
25
27
|
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
|
|
28
|
+
|
|
29
|
+
- name: Get latest npm version
|
|
30
|
+
id: npm_version
|
|
31
|
+
run: |
|
|
32
|
+
LATEST=$(npm view cctotals version 2>/dev/null || echo "0.0.0")
|
|
33
|
+
echo "latest=$LATEST" >> $GITHUB_OUTPUT
|
|
34
|
+
|
|
35
|
+
- name: Bump and publish
|
|
36
|
+
run: |
|
|
37
|
+
CURRENT=$(node -p "require('./package.json').version")
|
|
38
|
+
NPM_LATEST=${{ steps.npm_version.outputs.latest }}
|
|
39
|
+
|
|
40
|
+
echo "Package version: $CURRENT, npm latest: $NPM_LATEST"
|
|
41
|
+
|
|
42
|
+
# Check if npm already has this version
|
|
43
|
+
if npm view cctotals@$CURRENT version &>/dev/null; then
|
|
44
|
+
echo "Version $CURRENT exists on npm, bumping..."
|
|
45
|
+
npm version patch
|
|
46
|
+
fi
|
|
47
|
+
|
|
48
|
+
NEW_VERSION=$(node -p "require('./package.json').version")
|
|
49
|
+
echo "Publishing $NEW_VERSION..."
|
|
50
|
+
git push origin HEAD:main --tags
|
|
51
|
+
npm publish --access public
|
package/README.md
ADDED
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
# cctotals
|
|
2
|
+
|
|
3
|
+
📊 Analyze and visualize your Claude Code token usage with beautiful weekly graphs in the terminal.
|
|
4
|
+
|
|
5
|
+
## Quick Start
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
bun x cctotals
|
|
9
|
+
# or
|
|
10
|
+
npx cctotals
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
## Features
|
|
14
|
+
|
|
15
|
+
- 📈 Weekly token totals bar chart
|
|
16
|
+
- 🤖 Breakdown by model (Sonnet, Haiku, etc.)
|
|
17
|
+
- 🎨 Colorful terminal output
|
|
18
|
+
- 📊 Statistics: total, average, per-week data
|
|
19
|
+
|
|
20
|
+
## Installation
|
|
21
|
+
|
|
22
|
+
```bash
|
|
23
|
+
npm install -g cctotals
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
## Usage
|
|
27
|
+
|
|
28
|
+
```bash
|
|
29
|
+
cctotals
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
### Output Example
|
|
33
|
+
|
|
34
|
+
```
|
|
35
|
+
══════════════════════════════════════════════════════════════════════
|
|
36
|
+
WEEKLY TOKEN USAGE GRAPH
|
|
37
|
+
══════════════════════════════════════════════════════════════════════
|
|
38
|
+
|
|
39
|
+
Week Start | Tokens (scaled)
|
|
40
|
+
────────────┼────────────────────────────────────────────────────────────
|
|
41
|
+
2026-02-23 │███████████████████████████████████████████████████████████ 2,382,993
|
|
42
|
+
2026-03-02 │█ 15,378
|
|
43
|
+
────────────┼────────────────────────────────────────────────────────────
|
|
44
|
+
|
|
45
|
+
Total: 2,398,371 tokens across 2 weeks
|
|
46
|
+
Average: 1,199,186 tokens/week
|
|
47
|
+
|
|
48
|
+
══════════════════════════════════════════════════════════════════════
|
|
49
|
+
|
|
50
|
+
DETAILED BREAKDOWN BY MODEL
|
|
51
|
+
──────────────────────────────────────────────────
|
|
52
|
+
claude-sonnet-4-6 1,327,999 (55.4%)
|
|
53
|
+
claude-haiku-4-5-20251001 1,070,372 (44.6%)
|
|
54
|
+
```
|
|
55
|
+
|
|
56
|
+
## How It Works
|
|
57
|
+
|
|
58
|
+
Reads from Claude Code's telemetry data at `~/.claude/stats-cache.json` and aggregates token usage by week.
|
|
59
|
+
|
|
60
|
+
## Requirements
|
|
61
|
+
|
|
62
|
+
- Node.js 18+ or Bun
|
|
63
|
+
- Claude Code with telemetry enabled
|
|
64
|
+
|
|
65
|
+
## License
|
|
66
|
+
|
|
67
|
+
MIT
|
package/package.json
CHANGED
package/token-graph.js
CHANGED
|
@@ -15,7 +15,6 @@ const stats = JSON.parse(fs.readFileSync(statsPath, 'utf8'));
|
|
|
15
15
|
// Group daily tokens into weeks
|
|
16
16
|
function getWeekKey(dateStr) {
|
|
17
17
|
const date = new Date(dateStr);
|
|
18
|
-
// Get ISO week start (Monday)
|
|
19
18
|
const day = date.getDay();
|
|
20
19
|
const diff = date.getDate() - day + (day === 0 ? -6 : 1);
|
|
21
20
|
const weekStart = new Date(date.setDate(diff));
|
|
@@ -24,7 +23,6 @@ function getWeekKey(dateStr) {
|
|
|
24
23
|
|
|
25
24
|
const weeklyTokens = {};
|
|
26
25
|
|
|
27
|
-
// Process daily model tokens
|
|
28
26
|
for (const dayData of stats.dailyModelTokens) {
|
|
29
27
|
const weekKey = getWeekKey(dayData.date);
|
|
30
28
|
if (!weeklyTokens[weekKey]) {
|
|
@@ -37,67 +35,60 @@ for (const dayData of stats.dailyModelTokens) {
|
|
|
37
35
|
}
|
|
38
36
|
}
|
|
39
37
|
|
|
40
|
-
// Sort weeks chronologically
|
|
41
38
|
const sortedWeeks = Object.keys(weeklyTokens).sort();
|
|
42
|
-
|
|
43
|
-
// Find max for scaling
|
|
44
39
|
const maxTokens = Math.max(...sortedWeeks.map(w => weeklyTokens[w].total));
|
|
45
40
|
|
|
46
|
-
//
|
|
47
|
-
const
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
const colors = {
|
|
54
|
-
header: '\x1b[36m', // Cyan
|
|
55
|
-
label: '\x1b[33m', // Yellow
|
|
56
|
-
bar: '\x1b[32m', // Green
|
|
57
|
-
total: '\x1b[35m', // Magenta
|
|
58
|
-
reset: '\x1b[0m'
|
|
41
|
+
// Colors
|
|
42
|
+
const c = {
|
|
43
|
+
hdr: '\x1b[36m',
|
|
44
|
+
lbl: '\x1b[33m',
|
|
45
|
+
bar: '\x1b[32m',
|
|
46
|
+
num: '\x1b[35m',
|
|
47
|
+
res: '\x1b[0m'
|
|
59
48
|
};
|
|
60
49
|
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
50
|
+
// Terminal width
|
|
51
|
+
const W = process.stdout.columns || 80;
|
|
52
|
+
const CHART_W = Math.min(50, W - 30);
|
|
53
|
+
const PAD = Math.floor((W - CHART_W - 30) / 2);
|
|
65
54
|
|
|
66
|
-
//
|
|
67
|
-
console.log(
|
|
55
|
+
// Header
|
|
56
|
+
console.log('\n' + c.hdr + '═'.repeat(W));
|
|
57
|
+
console.log(' '.repeat(PAD) + 'WEEKLY TOKEN USAGE GRAPH');
|
|
58
|
+
console.log('═'.repeat(W) + c.res);
|
|
59
|
+
console.log();
|
|
68
60
|
|
|
69
|
-
//
|
|
70
|
-
const
|
|
71
|
-
|
|
72
|
-
console.log(
|
|
61
|
+
// Column headers
|
|
62
|
+
const hdr = ' Week Tokens';
|
|
63
|
+
console.log(c.lbl + hdr + ' '.repeat(CHART_W - hdr.length + 5) + '| Bar' + c.res);
|
|
64
|
+
console.log(c.lbl + '─'.repeat(W) + c.res);
|
|
73
65
|
|
|
74
66
|
let grandTotal = 0;
|
|
75
67
|
for (const week of sortedWeeks) {
|
|
76
68
|
const data = weeklyTokens[week];
|
|
77
|
-
const barLen = Math.max(1, Math.floor(data.total /
|
|
78
|
-
const bar = colors.bar + '█'.repeat(barLen) + colors.reset;
|
|
79
|
-
const label = colors.label + week + colors.reset;
|
|
80
|
-
const spaces = ' '.repeat(Math.max(0, LABEL_WIDTH - label.length));
|
|
69
|
+
const barLen = Math.max(1, Math.floor((data.total / maxTokens) * CHART_W));
|
|
81
70
|
|
|
82
|
-
// Format
|
|
71
|
+
// Format: week left-aligned, tokens right-aligned
|
|
72
|
+
const weekStr = week;
|
|
83
73
|
const tokenStr = data.total.toLocaleString();
|
|
84
|
-
const
|
|
74
|
+
const bar = c.bar + '█'.repeat(barLen) + c.res;
|
|
85
75
|
|
|
86
|
-
|
|
76
|
+
const line = ` ${c.lbl}${weekStr}${c.res} ${c.num}${tokenStr}${c.res} ${bar}`;
|
|
77
|
+
console.log(line);
|
|
87
78
|
grandTotal += data.total;
|
|
88
79
|
}
|
|
89
80
|
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
console.log(
|
|
94
|
-
console.log(
|
|
81
|
+
console.log(c.lbl + '─'.repeat(W) + c.res);
|
|
82
|
+
|
|
83
|
+
const avg = Math.round(grandTotal / sortedWeeks.length);
|
|
84
|
+
console.log(`\n Total: ${c.num}${grandTotal.toLocaleString()}${c.res} tokens (${sortedWeeks.length} weeks)`);
|
|
85
|
+
console.log(` Average: ${c.num}${avg.toLocaleString()}${c.res} tokens/week`);
|
|
86
|
+
console.log('\n' + c.hdr + '═'.repeat(W) + c.res + '\n');
|
|
95
87
|
|
|
96
|
-
//
|
|
97
|
-
console.log(
|
|
98
|
-
console.log('─'.repeat(
|
|
88
|
+
// Model breakdown
|
|
89
|
+
console.log(c.hdr + ' MODEL BREAKDOWN' + c.res);
|
|
90
|
+
console.log(c.lbl + '─'.repeat(W) + c.res);
|
|
99
91
|
|
|
100
|
-
// Aggregate model stats
|
|
101
92
|
const modelTotals = {};
|
|
102
93
|
for (const week of sortedWeeks) {
|
|
103
94
|
for (const [model, tokens] of Object.entries(weeklyTokens[week].byModel)) {
|
|
@@ -105,8 +96,10 @@ for (const week of sortedWeeks) {
|
|
|
105
96
|
}
|
|
106
97
|
}
|
|
107
98
|
|
|
99
|
+
const maxModelLen = Math.max(...Object.keys(modelTotals).map(m => m.length));
|
|
108
100
|
for (const [model, tokens] of Object.entries(modelTotals)) {
|
|
109
101
|
const pct = ((tokens / grandTotal) * 100).toFixed(1);
|
|
110
|
-
|
|
102
|
+
const padded = model.padEnd(maxModelLen);
|
|
103
|
+
console.log(` ${c.lbl}${padded}${c.res} ${c.num}${tokens.toLocaleString()}${c.res} (${pct}%)`);
|
|
111
104
|
}
|
|
112
105
|
console.log();
|