claude-cache-tax 0.1.0 → 0.1.1

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 CHANGED
@@ -9,7 +9,7 @@ npx claude-cache-tax
9
9
  ```
10
10
 
11
11
  ```
12
- Sessions: 430, replies: 47766, from 2026-09-25 to 2026-12-04
12
+ Sessions: 430, replies: 47766, over 70 days
13
13
  Cache writes: 236.4M tokens, cache reads: 15232.2M tokens (64 reads per write)
14
14
  Cache lifetime of the writes: 1 hour 74.4%, 5 minutes 25.6%
15
15
 
package/bin/cli.js CHANGED
@@ -1,74 +1,75 @@
1
- #!/usr/bin/env node
2
- 'use strict';
3
-
4
- const { scan, defaultDir } = require('../src/scan');
5
-
6
- const HELP = `claude-cache-tax: see when your Claude Code prompt cache gets rebuilt
7
-
8
- Usage: npx claude-cache-tax [options]
9
-
10
- --dir <path> folder with Claude Code session logs (default: ${defaultDir()})
11
- --days <n> only count the last n days
12
- --json print the raw numbers as JSON
13
- -h, --help show this help
14
-
15
- Reads only timestamps, model names and token counts from the local session
16
- logs. Nothing is sent anywhere.`;
17
-
18
- function parseArgs(argv) {
19
- const opts = { dir: defaultDir(), days: null, json: false };
20
- for (let i = 0; i < argv.length; i++) {
21
- const a = argv[i];
22
- if (a === '-h' || a === '--help') opts.help = true;
23
- else if (a === '--json') opts.json = true;
24
- else if (a === '--dir') opts.dir = argv[++i];
25
- else if (a === '--days') opts.days = Number(argv[++i]);
26
- else throw new Error(`Unknown option: ${a}`);
27
- }
28
- if (opts.days !== null && !(opts.days > 0)) throw new Error('--days needs a positive number');
29
- return opts;
30
- }
31
-
32
- const pct = (part, whole) => (whole ? ((100 * part) / whole).toFixed(1) + '%' : '-');
33
- const mtok = (n) => (n / 1e6).toFixed(1) + 'M';
34
-
35
- function render(r) {
36
- const t = r.total;
37
- const lines = [];
38
- lines.push(`Sessions: ${r.sessions}, replies: ${t.turns}, from ${r.from?.slice(0, 10)} to ${r.to?.slice(0, 10)}`);
39
- lines.push(`Cache writes: ${mtok(t.write)} tokens, cache reads: ${mtok(t.read)} tokens (${(t.read / (t.write || 1)).toFixed(0)} reads per write)`);
40
- lines.push(`Cache lifetime of the writes: 1 hour ${pct(t.write1h, t.write)}, 5 minutes ${pct(t.write5m, t.write)}`);
41
- lines.push('');
42
- lines.push('Where the cache writes happen, by the pause before the reply:');
43
- lines.push(` ${'first reply of a session'.padEnd(26)} ${String(r.firstTurns.turns).padStart(7)} replies ${pct(r.firstTurns.write, t.write).padStart(6)} of writes`);
44
- for (const b of r.buckets) {
45
- lines.push(` ${('after ' + b.label).padEnd(26)} ${String(b.turns).padStart(7)} replies ${pct(b.write, t.write).padStart(6)} of writes`);
46
- }
47
- lines.push('');
48
- lines.push('By model:');
49
- for (const [m, v] of Object.entries(r.models).sort((a, b) => b[1].write - a[1].write)) {
50
- lines.push(` ${m.padEnd(26)} ${String(v.turns).padStart(7)} replies writes ${mtok(v.write).padStart(7)} reads ${mtok(v.read).padStart(8)}`);
51
- }
52
- return lines.join('\n');
53
- }
54
-
55
- async function main() {
56
- let opts;
57
- try {
58
- opts = parseArgs(process.argv.slice(2));
59
- } catch (e) {
60
- console.error(e.message + '\n\n' + HELP);
61
- process.exit(2);
62
- }
63
- if (opts.help) return console.log(HELP);
64
- const since = opts.days ? Date.now() - opts.days * 86400e3 : null;
65
- try {
66
- const r = await scan(opts.dir, { since });
67
- console.log(opts.json ? JSON.stringify(r, null, 2) : render(r));
68
- } catch (e) {
69
- console.error(e.message);
70
- process.exit(1);
71
- }
72
- }
73
-
74
- main();
1
+ #!/usr/bin/env node
2
+ 'use strict';
3
+
4
+ const { scan, defaultDir } = require('../src/scan');
5
+
6
+ const HELP = `claude-cache-tax: see when your Claude Code prompt cache gets rebuilt
7
+
8
+ Usage: npx claude-cache-tax [options]
9
+
10
+ --dir <path> folder with Claude Code session logs (default: ${defaultDir()})
11
+ --days <n> only count the last n days
12
+ --json print the raw numbers as JSON
13
+ -h, --help show this help
14
+
15
+ Reads only timestamps, model names and token counts from the local session
16
+ logs. Nothing is sent anywhere.`;
17
+
18
+ function parseArgs(argv) {
19
+ const opts = { dir: defaultDir(), days: null, json: false };
20
+ for (let i = 0; i < argv.length; i++) {
21
+ const a = argv[i];
22
+ if (a === '-h' || a === '--help') opts.help = true;
23
+ else if (a === '--json') opts.json = true;
24
+ else if (a === '--dir') opts.dir = argv[++i];
25
+ else if (a === '--days') opts.days = Number(argv[++i]);
26
+ else throw new Error(`Unknown option: ${a}`);
27
+ }
28
+ if (opts.days !== null && !(opts.days > 0)) throw new Error('--days needs a positive number');
29
+ return opts;
30
+ }
31
+
32
+ const pct = (part, whole) => (whole ? ((100 * part) / whole).toFixed(1) + '%' : '-');
33
+ const mtok = (n) => (n / 1e6).toFixed(1) + 'M';
34
+
35
+ function render(r) {
36
+ const t = r.total;
37
+ const lines = [];
38
+ const days = r.from ? Math.max(1, Math.round((Date.parse(r.to) - Date.parse(r.from)) / 86400e3)) : 0;
39
+ lines.push(`Sessions: ${r.sessions}, replies: ${t.turns}, over ${days} days`);
40
+ lines.push(`Cache writes: ${mtok(t.write)} tokens, cache reads: ${mtok(t.read)} tokens (${(t.read / (t.write || 1)).toFixed(0)} reads per write)`);
41
+ lines.push(`Cache lifetime of the writes: 1 hour ${pct(t.write1h, t.write)}, 5 minutes ${pct(t.write5m, t.write)}`);
42
+ lines.push('');
43
+ lines.push('Where the cache writes happen, by the pause before the reply:');
44
+ lines.push(` ${'first reply of a session'.padEnd(26)} ${String(r.firstTurns.turns).padStart(7)} replies ${pct(r.firstTurns.write, t.write).padStart(6)} of writes`);
45
+ for (const b of r.buckets) {
46
+ lines.push(` ${('after ' + b.label).padEnd(26)} ${String(b.turns).padStart(7)} replies ${pct(b.write, t.write).padStart(6)} of writes`);
47
+ }
48
+ lines.push('');
49
+ lines.push('By model:');
50
+ for (const [m, v] of Object.entries(r.models).sort((a, b) => b[1].write - a[1].write)) {
51
+ lines.push(` ${m.padEnd(26)} ${String(v.turns).padStart(7)} replies writes ${mtok(v.write).padStart(7)} reads ${mtok(v.read).padStart(8)}`);
52
+ }
53
+ return lines.join('\n');
54
+ }
55
+
56
+ async function main() {
57
+ let opts;
58
+ try {
59
+ opts = parseArgs(process.argv.slice(2));
60
+ } catch (e) {
61
+ console.error(e.message + '\n\n' + HELP);
62
+ process.exit(2);
63
+ }
64
+ if (opts.help) return console.log(HELP);
65
+ const since = opts.days ? Date.now() - opts.days * 86400e3 : null;
66
+ try {
67
+ const r = await scan(opts.dir, { since });
68
+ console.log(opts.json ? JSON.stringify(r, null, 2) : render(r));
69
+ } catch (e) {
70
+ console.error(e.message);
71
+ process.exit(1);
72
+ }
73
+ }
74
+
75
+ main();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "claude-cache-tax",
3
- "version": "0.1.0",
3
+ "version": "0.1.1",
4
4
  "description": "See when your Claude Code prompt cache gets rebuilt: cache writes by the pause before each reply, 1-hour vs 5-minute cache, per model. Reads local logs only.",
5
5
  "bin": {
6
6
  "claude-cache-tax": "bin/cli.js"
package/src/scan.js CHANGED
@@ -38,7 +38,8 @@ function turnFromLine(line) {
38
38
  }
39
39
  const m = d && d.type === 'assistant' ? d.message : null;
40
40
  const u = m && typeof m === 'object' ? m.usage : null;
41
- if (!u || !d.timestamp) return null;
41
+ // Claude Code logs "<synthetic>" replies (interrupts, local errors) that never reached a model.
42
+ if (!u || !d.timestamp || m.model === '<synthetic>') return null;
42
43
  const cc = u.cache_creation || {};
43
44
  return {
44
45
  id: m.id || null,