claude-usage-explorer 1.0.1 → 1.1.5

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.
@@ -1,39 +0,0 @@
1
- import fs from 'node:fs';
2
- import path from 'node:path';
3
-
4
- // Claude Desktop's plan-usage-history.json is undocumented, optional cached data.
5
- // Read only known numeric utilization fields; never expose organization identifiers.
6
- export function planUsageFromSamples(samples, now=Date.now()) {
7
- if (!Array.isArray(samples)) return null;
8
- const valid=samples.filter(s=>s && Number.isFinite(s.t) && s.u &&
9
- (Number.isFinite(s.u.fh)||Number.isFinite(s.u.sd)))
10
- .map(s=>({timestamp:s.t<1e12?s.t*1000:s.t,
11
- fiveHour:Number.isFinite(s.u.fh)?s.u.fh:null,
12
- sevenDay:Number.isFinite(s.u.sd)?s.u.sd:null}))
13
- .filter(s=>s.timestamp>0 && s.timestamp<=now+86400000)
14
- .sort((a,b)=>a.timestamp-b.timestamp);
15
- if (!valid.length)return null;
16
- const latest=valid.at(-1);
17
- return { ...latest, stale:now-latest.timestamp>15*60*1000,
18
- samples:valid.slice(-100),source:'Claude Desktop cached history'};
19
- }
20
- export function readPlanUsage({platform=process.platform,localAppData=process.env.LOCALAPPDATA,home=process.env.HOME,now=Date.now()}={}){
21
- const roots=[];
22
- if(platform==='win32'&&localAppData)roots.push(path.join(localAppData,'Claude-Data'));
23
- if(platform==='darwin'&&home){roots.push(path.join(home,'Library','Application Support','Claude-Data'));roots.push(path.join(home,'Library','Application Support','Claude'));}
24
- let best=null;
25
- for(const root of roots){
26
- let folders=[];
27
- try{folders=fs.readdirSync(root,{withFileTypes:true}).filter(x=>x.isDirectory()&&x.name.startsWith('claude_')).map(x=>path.join(root,x.name));}catch{continue;}
28
- for(const folder of folders){
29
- try{
30
- const file=path.join(folder,'plan-usage-history.json');
31
- if(fs.statSync(file).size>2_000_000)continue;
32
- const data=JSON.parse(fs.readFileSync(file,'utf8'));
33
- const result=planUsageFromSamples(data.samples,now);
34
- if(result&&(!best||result.timestamp>best.timestamp))best=result;
35
- }catch{}
36
- }
37
- }
38
- return best;
39
- }