claude-cost 1.0.0 → 1.0.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 +57 -5
- package/dist/index.js +3 -3
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -1,15 +1,67 @@
|
|
|
1
1
|
# claude-cost
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Beautiful TUI dashboard for Claude Code usage analytics.
|
|
4
|
+
|
|
5
|
+

|
|
6
|
+
|
|
7
|
+
## Install
|
|
4
8
|
|
|
5
9
|
```bash
|
|
6
|
-
|
|
10
|
+
npm install -g claude-cost
|
|
11
|
+
# or
|
|
12
|
+
bun install -g claude-cost
|
|
7
13
|
```
|
|
8
14
|
|
|
9
|
-
|
|
15
|
+
## Usage
|
|
10
16
|
|
|
11
17
|
```bash
|
|
12
|
-
|
|
18
|
+
# Run the interactive TUI dashboard
|
|
19
|
+
claude-cost
|
|
20
|
+
|
|
21
|
+
# Or run directly without installing
|
|
22
|
+
npx claude-cost
|
|
23
|
+
bunx claude-cost
|
|
24
|
+
|
|
25
|
+
# Output stats as JSON (for scripts)
|
|
26
|
+
claude-cost --json
|
|
13
27
|
```
|
|
14
28
|
|
|
15
|
-
|
|
29
|
+
## Keyboard Controls
|
|
30
|
+
|
|
31
|
+
| Key | Action |
|
|
32
|
+
|-----|--------|
|
|
33
|
+
| `↑/↓` | Scroll through lists |
|
|
34
|
+
| `Tab` | Switch between views |
|
|
35
|
+
| `1/2/3/4` | Filter by time (today/week/month/all) |
|
|
36
|
+
| `r` | Refresh data |
|
|
37
|
+
| `q` | Quit |
|
|
38
|
+
|
|
39
|
+
## Data Source
|
|
40
|
+
|
|
41
|
+
Reads usage data from `~/.claude/projects/*/*.jsonl`
|
|
42
|
+
|
|
43
|
+
## JSON Output
|
|
44
|
+
|
|
45
|
+
```bash
|
|
46
|
+
$ bunx claude-cost --json
|
|
47
|
+
{
|
|
48
|
+
"totalCost": "$2.02K",
|
|
49
|
+
"totalTokens": "2924.70M",
|
|
50
|
+
"sessions": 796,
|
|
51
|
+
"messages": 39838,
|
|
52
|
+
"breakdown": {
|
|
53
|
+
"Haiku 4.5": {
|
|
54
|
+
"cost": "$24.95",
|
|
55
|
+
"tokens": "110.71M"
|
|
56
|
+
},
|
|
57
|
+
"Opus 4.5": {
|
|
58
|
+
"cost": "$1.98K",
|
|
59
|
+
"tokens": "2800.40M"
|
|
60
|
+
},
|
|
61
|
+
"Sonnet 4.5": {
|
|
62
|
+
"cost": "$11.33",
|
|
63
|
+
"tokens": "13.59M"
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
```
|
package/dist/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
var
|
|
3
|
-
`).filter(Boolean);for(let F of b)try{let P=JSON.parse(F);if(P.type!=="assistant")continue;let $=P.message;if(!$?.usage||!$?.model)continue;let g=$.usage,f=g.input_tokens||0,X=g.output_tokens||0,H=g.cache_creation_input_tokens||0,r=g.cache_read_input_tokens||0;if(f===0&&X===0&&H===0&&r===0)continue;let n=Xo($.model,f,X,H,r);o.push({timestamp:new Date(P.timestamp),model:$.model,usage:{inputTokens:f,outputTokens:X,cacheCreationTokens:H,cacheReadTokens:r},cost:n,sessionId:P.sessionId||"unknown",project:P.cwd||"unknown",messageId:$.id||P.uuid||"unknown"})}catch{}}catch{}return o}function zo(){let c=[];if(!Ro(go))return c;try{let o=Zo(go,{withFileTypes:!0});for(let A of o){if(!A.isDirectory())continue;let b=x(go,A.name),F=Zo(b).filter((P)=>P.endsWith(".jsonl"));for(let P of F)c.push(x(b,P))}}catch{}return c}function t(c,o){let A=zo(),b=[];for(let g of A){let f=Lo(g);b.push(...f)}let F=b;if(c)F=F.filter((g)=>g.timestamp>=c);if(o)F=F.filter((g)=>g.timestamp<=o);let P=new Set,$=[];F.sort((g,f)=>f.timestamp.getTime()-g.timestamp.getTime());for(let g of F){let f=`${g.sessionId}-${g.messageId}`;if(!P.has(f))P.add(f),$.push(g)}return $.sort((g,f)=>g.timestamp.getTime()-f.timestamp.getTime()),yo($)}function yo(c){let o={inputTokens:0,outputTokens:0,cacheCreationTokens:0,cacheReadTokens:0},A=0,b={},F=new Map,P=new Map,$=new Map,g=new Date;g.setHours(0,0,0,0);for(let r of c){if(A+=r.cost,o.inputTokens+=r.usage.inputTokens,o.outputTokens+=r.usage.outputTokens,o.cacheCreationTokens+=r.usage.cacheCreationTokens,o.cacheReadTokens+=r.usage.cacheReadTokens,!b[r.model])b[r.model]={cost:0,tokens:{inputTokens:0,outputTokens:0,cacheCreationTokens:0,cacheReadTokens:0},displayName:Uo(r.model)};let n=b[r.model];if(n.cost+=r.cost,n.tokens.inputTokens+=r.usage.inputTokens,n.tokens.outputTokens+=r.usage.outputTokens,n.tokens.cacheCreationTokens+=r.usage.cacheCreationTokens,n.tokens.cacheReadTokens+=r.usage.cacheReadTokens,!F.has(r.sessionId))F.set(r.sessionId,[]);F.get(r.sessionId).push(r);let Y=`${r.timestamp.getFullYear()}-${String(r.timestamp.getMonth()+1).padStart(2,"0")}-${String(r.timestamp.getDate()).padStart(2,"0")}`;if(!P.has(Y))P.set(Y,[]);if(P.get(Y).push(r),r.timestamp>=g){let p=r.timestamp.getHours();if(!$.has(p))$.set(p,{cost:0,tokens:0,messageCount:0});let K=$.get(p);K.cost+=r.cost,K.tokens+=r.usage.inputTokens+r.usage.outputTokens+r.usage.cacheCreationTokens+r.usage.cacheReadTokens,K.messageCount+=1}}let f=[];for(let[r,n]of F){let Y=n.sort((T,co)=>T.timestamp.getTime()-co.timestamp.getTime()),p={inputTokens:0,outputTokens:0,cacheCreationTokens:0,cacheReadTokens:0},K=0;for(let T of Y)K+=T.cost,p.inputTokens+=T.usage.inputTokens,p.outputTokens+=T.usage.outputTokens,p.cacheCreationTokens+=T.usage.cacheCreationTokens,p.cacheReadTokens+=T.usage.cacheReadTokens;let R=Y[0],B=Y[Y.length-1];f.push({sessionId:r,project:R.project,firstMessage:R.timestamp,lastMessage:B.timestamp,totalCost:K,totalTokens:p,messageCount:Y.length,model:B.model})}f.sort((r,n)=>n.lastMessage.getTime()-r.lastMessage.getTime());let X=[];for(let[r,n]of P){let Y={inputTokens:0,outputTokens:0,cacheCreationTokens:0,cacheReadTokens:0},p=0,K={},R=new Set;for(let B of n){if(p+=B.cost,Y.inputTokens+=B.usage.inputTokens,Y.outputTokens+=B.usage.outputTokens,Y.cacheCreationTokens+=B.usage.cacheCreationTokens,Y.cacheReadTokens+=B.usage.cacheReadTokens,R.add(B.sessionId),!K[B.model])K[B.model]={cost:0,tokens:{inputTokens:0,outputTokens:0,cacheCreationTokens:0,cacheReadTokens:0}};let T=K[B.model];T.cost+=B.cost,T.tokens.inputTokens+=B.usage.inputTokens,T.tokens.outputTokens+=B.usage.outputTokens,T.tokens.cacheCreationTokens+=B.usage.cacheCreationTokens,T.tokens.cacheReadTokens+=B.usage.cacheReadTokens}X.push({date:r,totalCost:p,totalTokens:Y,sessionCount:R.size,messageCount:n.length,byModel:K})}X.sort((r,n)=>n.date.localeCompare(r.date));let H=[];for(let[r,n]of $)H.push({hour:r,cost:n.cost,tokens:n.tokens,messageCount:n.messageCount});return H.sort((r,n)=>r.hour-n.hour),{entries:c,sessions:f,daily:X,hourly:H,totalCost:A,totalTokens:o,byModel:b}}function G(c){if(c>=1000)return`$${(c/1000).toFixed(2)}K`;if(c>=1)return`$${c.toFixed(2)}`;if(c>=0.01)return`$${c.toFixed(2)}`;return`${(c*100).toFixed(2)}¢`}function L(c){if(c>=1e6)return`${(c/1e6).toFixed(2)}M`;if(c>=1000)return`${(c/1000).toFixed(1)}K`;return c.toString()}function Ao(c){let o=c.split("/");return o[o.length-1]||c}var wo,go;var E=$o(()=>{Yo();wo=x(Co(),".claude"),go=x(wo,"projects")});import{render as Fc}from"ink";import{useState as w,useEffect as vo}from"react";import{Box as _,Text as k,useApp as ao,useInput as so}from"ink";import{Box as no,Text as W}from"ink";import{jsxDEV as l}from"react/jsx-dev-runtime";function j(){return l(no,{flexDirection:"column",alignItems:"center",marginBottom:1,children:[l(no,{children:[l(W,{color:"#FF6B6B",bold:!0,children:"C"},void 0,!1,void 0,this),l(W,{color:"#FF8E53",bold:!0,children:"L"},void 0,!1,void 0,this),l(W,{color:"#FFBA49",bold:!0,children:"A"},void 0,!1,void 0,this),l(W,{color:"#7BED9F",bold:!0,children:"U"},void 0,!1,void 0,this),l(W,{color:"#70A1FF",bold:!0,children:"D"},void 0,!1,void 0,this),l(W,{color:"#5352ED",bold:!0,children:"E"},void 0,!1,void 0,this),l(W,{color:"white",children:" "},void 0,!1,void 0,this),l(W,{color:"#A29BFE",bold:!0,children:"C"},void 0,!1,void 0,this),l(W,{color:"#FD79A8",bold:!0,children:"O"},void 0,!1,void 0,this),l(W,{color:"#FF6B6B",bold:!0,children:"S"},void 0,!1,void 0,this),l(W,{color:"#FF8E53",bold:!0,children:"T"},void 0,!1,void 0,this),l(W,{color:"gray",dimColor:!0,children:" │ Usage Analytics Dashboard"},void 0,!1,void 0,this)]},void 0,!0,void 0,this),l(no,{children:[l(W,{color:"gray",children:"Press "},void 0,!1,void 0,this),l(W,{color:"yellow",children:"↑↓"},void 0,!1,void 0,this),l(W,{color:"gray",children:" scroll • "},void 0,!1,void 0,this),l(W,{color:"yellow",children:"tab"},void 0,!1,void 0,this),l(W,{color:"gray",children:" switch view • "},void 0,!1,void 0,this),l(W,{color:"yellow",children:"r"},void 0,!1,void 0,this),l(W,{color:"gray",children:" refresh • "},void 0,!1,void 0,this),l(W,{color:"yellow",children:"q"},void 0,!1,void 0,this),l(W,{color:"gray",children:" quit"},void 0,!1,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this)}import{Box as h,Text as u}from"ink";import{Box as bo,Text as D}from"ink";import{jsxDEV as V}from"react/jsx-dev-runtime";function M({title:c,children:o,width:A,borderColor:b="gray",titleColor:F="white"}){return V(bo,{flexDirection:"column",borderStyle:"round",borderColor:b,paddingX:1,width:A,children:[c&&V(bo,{marginBottom:0,children:V(D,{color:F,bold:!0,children:c},void 0,!1,void 0,this)},void 0,!1,void 0,this),o]},void 0,!0,void 0,this)}function fo({value:c,max:o,width:A=20,color:b="green",showPercent:F=!1}){let P=o>0?Math.min(c/o,1):0,$=Math.round(P*A),g=A-$,f="█".repeat($)+"░".repeat(g);return V(bo,{children:[V(D,{color:b,children:f},void 0,!1,void 0,this),F&&V(D,{color:"gray",children:[" ",(P*100).toFixed(0),"%"]},void 0,!0,void 0,this)]},void 0,!0,void 0,this)}var Fo=["▁","▂","▃","▄","▅","▆","▇","█"];function qo({data:c,width:o=20,color:A="cyan"}){if(c.length===0)return V(D,{color:"gray",children:"─".repeat(o)},void 0,!1,void 0,this);let b=[],F=Math.max(1,Math.floor(c.length/o));for(let H=0;H<c.length;H+=F){let r=c.slice(H,Math.min(H+F,c.length));b.push(r.reduce((n,Y)=>n+Y,0)/r.length)}let P=Math.max(...b,0.001),$=Math.min(...b,0),g=P-$||1,X=b.slice(-o).map((H)=>{let r=(H-$)/g,n=Math.min(Math.floor(r*Fo.length),Fo.length-1);return Fo[n]}).join("").padStart(o," ");return V(D,{color:A,children:X},void 0,!1,void 0,this)}E();import{startOfWeek as io,startOfMonth as Vo}from"date-fns";import{jsxDEV as z}from"react/jsx-dev-runtime";function Qo({stats:c,periodLabel:o}){let A=c.totalTokens.inputTokens+c.totalTokens.outputTokens+c.totalTokens.cacheCreationTokens+c.totalTokens.cacheReadTokens,b=c.totalTokens.cacheReadTokens/1e6*3,F=c.totalTokens.cacheReadTokens/1e6*0.3,P=Math.max(0,b-F),$=c.daily.slice().reverse().map((g)=>g.totalCost);return z(M,{title:`\uD83D\uDCB0 ${o} Summary`,borderColor:"green",titleColor:"green",children:z(h,{flexDirection:"column",gap:0,children:[z(h,{children:[z(h,{width:18,children:z(u,{color:"gray",children:"Total Cost"},void 0,!1,void 0,this)},void 0,!1,void 0,this),z(u,{color:"green",bold:!0,children:G(c.totalCost)},void 0,!1,void 0,this)]},void 0,!0,void 0,this),z(h,{children:[z(h,{width:18,children:z(u,{color:"gray",children:"Total Tokens"},void 0,!1,void 0,this)},void 0,!1,void 0,this),z(u,{color:"cyan",children:L(A)},void 0,!1,void 0,this)]},void 0,!0,void 0,this),z(h,{children:[z(h,{width:18,children:z(u,{color:"gray",children:"Sessions"},void 0,!1,void 0,this)},void 0,!1,void 0,this),z(u,{color:"yellow",children:c.sessions.length},void 0,!1,void 0,this)]},void 0,!0,void 0,this),z(h,{children:[z(h,{width:18,children:z(u,{color:"gray",children:"Messages"},void 0,!1,void 0,this)},void 0,!1,void 0,this),z(u,{color:"magenta",children:c.entries.length},void 0,!1,void 0,this)]},void 0,!0,void 0,this),P>0&&z(h,{children:[z(h,{width:18,children:z(u,{color:"gray",children:"Cache Savings"},void 0,!1,void 0,this)},void 0,!1,void 0,this),z(u,{color:"#7BED9F",children:["~",G(P)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this),z(h,{marginTop:1,children:[z(u,{color:"gray",dimColor:!0,children:"Daily trend: "},void 0,!1,void 0,this),z(qo,{data:$,width:18,color:"#70A1FF"},void 0,!1,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this)},void 0,!1,void 0,this)}function Jo({stats:c}){let o=new Date,A=`${o.getFullYear()}-${String(o.getMonth()+1).padStart(2,"0")}-${String(o.getDate()).padStart(2,"0")}`,b=c.daily.find((n)=>n.date===A),F=io(o,{weekStartsOn:0}),P=c.daily.filter((n)=>new Date(n.date)>=F),$=P.reduce((n,Y)=>n+Y.totalCost,0),g=P.reduce((n,Y)=>n+Y.messageCount,0),f=Vo(o),X=c.daily.filter((n)=>new Date(n.date)>=f),H=X.reduce((n,Y)=>n+Y.totalCost,0),r=X.reduce((n,Y)=>n+Y.messageCount,0);return z(h,{flexDirection:"row",gap:2,children:[z(M,{title:"Today",borderColor:"cyan",titleColor:"cyan",children:[z(u,{color:"green",bold:!0,children:G(b?.totalCost||0)},void 0,!1,void 0,this),z(u,{color:"gray",dimColor:!0,children:[" ",b?.messageCount||0," msgs"]},void 0,!0,void 0,this)]},void 0,!0,void 0,this),z(M,{title:"This Week",borderColor:"blue",titleColor:"blue",children:[z(u,{color:"green",bold:!0,children:G($)},void 0,!1,void 0,this),z(u,{color:"gray",dimColor:!0,children:[" ",g," msgs"]},void 0,!0,void 0,this)]},void 0,!0,void 0,this),z(M,{title:"This Month",borderColor:"magenta",titleColor:"magenta",children:[z(u,{color:"green",bold:!0,children:G(H)},void 0,!1,void 0,this),z(u,{color:"gray",dimColor:!0,children:[" ",r," msgs"]},void 0,!0,void 0,this)]},void 0,!0,void 0,this),z(M,{title:"All Time",borderColor:"yellow",titleColor:"yellow",children:[z(u,{color:"green",bold:!0,children:G(c.totalCost)},void 0,!1,void 0,this),z(u,{color:"gray",dimColor:!0,children:[" ",c.entries.length," msgs"]},void 0,!0,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this)}import{Box as e,Text as d}from"ink";E();import{jsxDEV as C}from"react/jsx-dev-runtime";var Eo={"Opus 4.5":"#FF6B6B","Opus 4":"#FF8E53","Opus 3":"#FFBA49","Sonnet 4":"#70A1FF","Sonnet 3.7":"#5352ED","Sonnet 3.5":"#A29BFE","Sonnet 3":"#B8B5FF","Haiku 3.5":"#7BED9F","Haiku 3":"#2ECC71"};function po({stats:c}){let o=Object.entries(c.byModel).sort(([,b],[,F])=>F.cost-b.cost),A=Math.max(...o.map(([,b])=>b.cost),0.01);return C(M,{title:"\uD83D\uDCCA Cost by Model",borderColor:"cyan",titleColor:"cyan",children:C(e,{flexDirection:"column",gap:0,children:o.length===0?C(d,{color:"gray",dimColor:!0,children:"No usage data"},void 0,!1,void 0,this):o.map(([b,F])=>{let P=Eo[F.displayName]||"#888",$=F.tokens.inputTokens+F.tokens.outputTokens+F.tokens.cacheCreationTokens+F.tokens.cacheReadTokens;return C(e,{flexDirection:"column",marginBottom:0,children:C(e,{children:[C(e,{width:12,children:C(d,{color:P,bold:!0,children:F.displayName},void 0,!1,void 0,this)},void 0,!1,void 0,this),C(e,{width:10,children:C(d,{color:"white",bold:!0,children:G(F.cost)},void 0,!1,void 0,this)},void 0,!1,void 0,this),C(fo,{value:F.cost,max:A,width:16,color:P},void 0,!1,void 0,this),C(d,{color:"gray",dimColor:!0,children:[" ",L($)," tok"]},void 0,!0,void 0,this)]},void 0,!0,void 0,this)},b,!1,void 0,this)})},void 0,!1,void 0,this)},void 0,!1,void 0,this)}import{Box as m,Text as N}from"ink";E();import{formatDistanceToNow as jo,format as Do}from"date-fns";import{jsxDEV as J}from"react/jsx-dev-runtime";var y={"Opus 4.5":{symbol:"◆",color:"#FF6B6B"},"Opus 4":{symbol:"◆",color:"#FF8E53"},"Opus 3":{symbol:"◆",color:"#FFBA49"},"Sonnet 4":{symbol:"●",color:"#70A1FF"},"Sonnet 3.7":{symbol:"●",color:"#5352ED"},"Sonnet 3.5":{symbol:"●",color:"#A29BFE"},"Sonnet 3":{symbol:"●",color:"#B8B5FF"},"Haiku 3.5":{symbol:"○",color:"#7BED9F"},"Haiku 3":{symbol:"○",color:"#2ECC71"}};function eo(c){let o=c.toLowerCase();if(o.includes("opus-4-5")||o.includes("opus-4.5"))return y["Opus 4.5"];if(o.includes("opus-4")||o.includes("opus4"))return y["Opus 4"];if(o.includes("sonnet-4")||o.includes("sonnet4"))return y["Sonnet 4"];if(o.includes("3-7-sonnet")||o.includes("3.7"))return y["Sonnet 3.7"];if(o.includes("3-5-sonnet")||o.includes("3.5-sonnet"))return y["Sonnet 3.5"];if(o.includes("3-5-haiku")||o.includes("3.5-haiku"))return y["Haiku 3.5"];if(o.includes("opus"))return y["Opus 3"];if(o.includes("sonnet"))return y["Sonnet 3"];if(o.includes("haiku"))return y["Haiku 3"];return{symbol:"◯",color:"#888"}}function lo({sessions:c,selectedIndex:o,maxVisible:A=8,focused:b=!1}){let F=Math.max(0,Math.min(o-Math.floor(A/2),c.length-A)),P=c.slice(F,F+A),$=F>0,g=F+A<c.length;return J(M,{title:`\uD83D\uDCDD Recent Sessions${b?" (↑↓)":""}`,borderColor:b?"cyan":"yellow",titleColor:b?"cyan":"yellow",children:J(m,{flexDirection:"column",children:[$&&J(m,{justifyContent:"center",children:J(N,{color:"gray",children:["▲ ",F," more"]},void 0,!0,void 0,this)},void 0,!1,void 0,this),P.length===0?J(N,{color:"gray",dimColor:!0,children:"No sessions found"},void 0,!1,void 0,this):P.map((f,X)=>{let r=F+X===o,n=eo(f.model),Y=Ao(f.project),p=jo(f.lastMessage,{addSuffix:!0}),K=f.totalTokens.inputTokens+f.totalTokens.outputTokens+f.totalTokens.cacheCreationTokens+f.totalTokens.cacheReadTokens;return J(m,{flexDirection:"column",paddingX:1,paddingY:0,borderStyle:r?"round":void 0,borderColor:r?"cyan":void 0,children:[J(m,{children:[J(N,{color:n.color,children:[n.symbol," "]},void 0,!0,void 0,this),J(N,{color:r?"cyan":"white",bold:!0,children:Y.slice(0,24).padEnd(24)},void 0,!1,void 0,this),J(N,{color:"green",bold:!0,children:[" ",G(f.totalCost).padStart(8)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this),J(m,{children:[J(N,{color:"gray",children:" "},void 0,!1,void 0,this),J(N,{color:"gray",dimColor:!0,children:p.padEnd(20)},void 0,!1,void 0,this),J(N,{color:"gray",dimColor:!0,children:[L(K)," tok"]},void 0,!0,void 0,this),J(N,{color:"gray",dimColor:!0,children:[" • ",f.messageCount," msgs"]},void 0,!0,void 0,this)]},void 0,!0,void 0,this)]},`${f.sessionId}-${X}`,!0,void 0,this)}),g&&J(m,{justifyContent:"center",children:J(N,{color:"gray",children:["▼ ",c.length-F-A," more"]},void 0,!0,void 0,this)},void 0,!1,void 0,this)]},void 0,!0,void 0,this)},void 0,!1,void 0,this)}function Ko({daily:c,selectedIndex:o,maxVisible:A=8,focused:b=!1}){let F=Math.max(0,Math.min(o-Math.floor(A/2),c.length-A)),P=c.slice(F,F+A),$=Math.max(...c.map((X)=>X.totalCost),0.01),g=F>0,f=F+A<c.length;return J(M,{title:`\uD83D\uDCC5 Daily Costs${b?" (↑↓)":""}`,borderColor:b?"cyan":"green",titleColor:b?"cyan":"green",children:J(m,{flexDirection:"column",children:[g&&J(m,{justifyContent:"center",children:J(N,{color:"gray",children:["▲ ",F," more"]},void 0,!0,void 0,this)},void 0,!1,void 0,this),P.length===0?J(N,{color:"gray",dimColor:!0,children:"No daily data"},void 0,!1,void 0,this):P.map((X,H)=>{let n=F+H===o,Y=X.date===new Date().toISOString().slice(0,10),p=Math.max(1,Math.round(X.totalCost/$*20)),K="█".repeat(p),R=X.totalTokens.inputTokens+X.totalTokens.outputTokens+X.totalTokens.cacheCreationTokens+X.totalTokens.cacheReadTokens;return J(m,{paddingX:1,borderStyle:n?"round":void 0,borderColor:n?"cyan":void 0,children:[J(N,{color:Y?"cyan":"gray",children:Do(new Date(X.date),"MMM dd")},void 0,!1,void 0,this),J(N,{color:"green",bold:!0,children:[" ",G(X.totalCost).padStart(8)," "]},void 0,!0,void 0,this),J(N,{color:"#70A1FF",children:K.padEnd(20)},void 0,!1,void 0,this),J(N,{color:"gray",dimColor:!0,children:[" ",L(R)]},void 0,!0,void 0,this)]},`${X.date}-${H}`,!0,void 0,this)}),f&&J(m,{justifyContent:"center",children:J(N,{color:"gray",children:["▼ ",c.length-F-A," more"]},void 0,!0,void 0,this)},void 0,!1,void 0,this)]},void 0,!0,void 0,this)},void 0,!1,void 0,this)}import{Box as v,Text as Q}from"ink";E();import{format as a,startOfWeek as Wo,eachDayOfInterval as xo,subDays as to}from"date-fns";import{jsxDEV as q}from"react/jsx-dev-runtime";var S=["#161b22","#0e4429","#006d32","#26a641","#39d353"];function s(c,o){if(c===0)return S[0];let A=c/o;if(A<0.25)return S[1];if(A<0.5)return S[2];if(A<0.75)return S[3];return S[4]}function Bo({hourlyData:c}){let o=[];for(let P=0;P<24;P++){let $=c.find((g)=>g.hour===P);o.push($?.cost||0)}let A=Math.max(...o,0.01),b=o.reduce((P,$)=>P+$,0),F=o.indexOf(Math.max(...o));return q(M,{title:"Activity (Today)",borderColor:"gray",titleColor:"gray",children:q(v,{flexDirection:"column",children:[q(v,{flexDirection:"row",gap:0,children:o.map((P,$)=>q(Q,{color:s(P,A),children:"██"},$,!1,void 0,this))},void 0,!1,void 0,this),q(v,{marginTop:0,children:q(Q,{color:"gray",dimColor:!0,children:"0 6 12 18 23"},void 0,!1,void 0,this)},void 0,!1,void 0,this),q(v,{marginTop:0,gap:2,children:[q(Q,{color:"gray",dimColor:!0,children:"Total: "},void 0,!1,void 0,this),q(Q,{color:"green",children:G(b)},void 0,!1,void 0,this),q(Q,{color:"gray",dimColor:!0,children:" Peak hour: "},void 0,!1,void 0,this),q(Q,{color:"cyan",children:[F,":00"]},void 0,!0,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this)},void 0,!1,void 0,this)}function uo({dailyData:c}){let o=new Date,A=Wo(o,{weekStartsOn:0}),F=xo({start:A,end:o}).map((g)=>{let f=a(g,"yyyy-MM-dd"),X=c.find((H)=>H.date===f);return{day:g,cost:X?.cost||0,label:a(g,"EEE")}}),P=Math.max(...F.map((g)=>g.cost),0.01),$=F.reduce((g,f)=>g+f.cost,0);return q(M,{title:"Activity (This Week)",borderColor:"gray",titleColor:"gray",children:q(v,{flexDirection:"column",children:[q(v,{flexDirection:"row",gap:2,children:F.map((g,f)=>q(v,{flexDirection:"column",alignItems:"center",children:[q(Q,{color:s(g.cost,P),children:"██████"},void 0,!1,void 0,this),q(Q,{color:"gray",dimColor:!0,children:g.label},void 0,!1,void 0,this)]},f,!0,void 0,this))},void 0,!1,void 0,this),q(v,{marginTop:1,gap:2,children:[q(Q,{color:"gray",dimColor:!0,children:"Total: "},void 0,!1,void 0,this),q(Q,{color:"green",children:G($)},void 0,!1,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this)},void 0,!1,void 0,this)}function Go({dailyData:c}){let o=new Date,A=o.getFullYear(),b=o.getMonth(),F=new Date(A,b,1),P=new Date(A,b+1,0),$=F.getDay(),g=[];for(let n=0;n<$;n++)g.push({day:null,cost:0});for(let n=1;n<=P.getDate();n++){let Y=`${A}-${String(b+1).padStart(2,"0")}-${String(n).padStart(2,"0")}`,p=c.find((K)=>K.date===Y);g.push({day:n,cost:p?.cost||0})}while(g.length%7!==0)g.push({day:null,cost:0});let f=Math.max(...g.map((n)=>n.cost),0.01),X=g.reduce((n,Y)=>n+Y.cost,0),H=[];for(let n=0;n<g.length;n+=7)H.push(g.slice(n,n+7));let r=["S","M","T","W","T","F","S"];return q(M,{title:`Activity (${a(o,"MMMM yyyy")})`,borderColor:"gray",titleColor:"gray",children:q(v,{flexDirection:"column",children:[q(v,{flexDirection:"row",gap:1,children:r.map((n,Y)=>q(Q,{color:"gray",dimColor:!0,children:[n," "]},Y,!0,void 0,this))},void 0,!1,void 0,this),H.map((n,Y)=>q(v,{flexDirection:"row",gap:1,children:n.map((p,K)=>q(Q,{color:p.day?s(p.cost,f):"#0d1117",children:"██"},K,!1,void 0,this))},Y,!1,void 0,this)),q(v,{marginTop:1,gap:2,children:[q(Q,{color:"gray",dimColor:!0,children:"Total: "},void 0,!1,void 0,this),q(Q,{color:"green",children:G(X)},void 0,!1,void 0,this),q(v,{marginLeft:1,children:[q(Q,{color:S[0],children:"█"},void 0,!1,void 0,this),q(Q,{color:"gray",dimColor:!0,children:" Less "},void 0,!1,void 0,this),q(Q,{color:S[1],children:"█"},void 0,!1,void 0,this),q(Q,{color:S[2],children:"█"},void 0,!1,void 0,this),q(Q,{color:S[3],children:"█"},void 0,!1,void 0,this),q(Q,{color:S[4],children:"█"},void 0,!1,void 0,this),q(Q,{color:"gray",dimColor:!0,children:" More"},void 0,!1,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this)},void 0,!1,void 0,this)}function No({dailyData:c}){let o=new Date,A=Math.min(26,Math.ceil(c.length/7)||12),b=Array.from({length:7},()=>[]);for(let f=A-1;f>=0;f--){let X=Wo(to(o,f*7),{weekStartsOn:0});for(let H=0;H<7;H++){let r=new Date(X);r.setDate(X.getDate()+H);let n=a(r,"yyyy-MM-dd"),Y=c.find((p)=>p.date===n);b[H].push(Y?.cost||0)}}let F=b.flat(),P=Math.max(...F,0.01),$=F.reduce((f,X)=>f+X,0),g=["S","M","T","W","T","F","S"];return q(M,{title:"Activity (All Time)",borderColor:"gray",titleColor:"gray",children:q(v,{flexDirection:"column",children:[b.map((f,X)=>q(v,{flexDirection:"row",children:[q(Q,{color:"gray",dimColor:!0,children:[g[X]," "]},void 0,!0,void 0,this),f.map((H,r)=>q(Q,{color:s(H,P),children:"██"},r,!1,void 0,this))]},X,!0,void 0,this)),q(v,{marginTop:1,gap:2,children:[q(Q,{color:"gray",dimColor:!0,children:"Total: "},void 0,!1,void 0,this),q(Q,{color:"green",children:G($)},void 0,!1,void 0,this),q(Q,{color:"gray",dimColor:!0,children:[" (",c.length," days)"]},void 0,!0,void 0,this),q(v,{marginLeft:1,children:[q(Q,{color:S[0],children:"█"},void 0,!1,void 0,this),q(Q,{color:"gray",dimColor:!0,children:" Less "},void 0,!1,void 0,this),q(Q,{color:S[1],children:"█"},void 0,!1,void 0,this),q(Q,{color:S[2],children:"█"},void 0,!1,void 0,this),q(Q,{color:S[3],children:"█"},void 0,!1,void 0,this),q(Q,{color:S[4],children:"█"},void 0,!1,void 0,this),q(Q,{color:"gray",dimColor:!0,children:" More"},void 0,!1,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this)},void 0,!1,void 0,this)}E();import{startOfWeek as oc,startOfMonth as cc,endOfMonth as rc,format as nc}from"date-fns";import{jsxDEV as Z}from"react/jsx-dev-runtime";function Mo(){let{exit:c}=ao(),[o,A]=w(null),[b,F]=w(null),[P,$]=w(!0),[g,f]=w(null),[X,H]=w("sessions"),[r,n]=w("today"),[Y,p]=w(0),[K,R]=w(0),[B,T]=w(new Date),[co,Po]=w(5),$c=5,ro=()=>{$(!0),f(null);try{let U,I,i=new Date;switch(r){case"today":U=new Date(i),U.setHours(0,0,0,0);break;case"week":U=oc(i,{weekStartsOn:0});break;case"month":U=cc(i),I=rc(i);break;case"all":default:U=void 0}let So=t(U,I);A(So);let _o=t();F(_o),T(new Date)}catch(U){f(U instanceof Error?U.message:"Unknown error")}finally{$(!1)}};if(vo(()=>{ro()},[r]),vo(()=>{let U=setInterval(()=>{Po((I)=>{if(I<=1)return ro(),5;return I-1})},1000);return()=>clearInterval(U)},[r]),so((U,I)=>{if(U==="q"||I.ctrl&&U==="c"){c();return}if(U==="r"){ro(),Po(5);return}if(I.tab||U==="\t"){H(X==="sessions"?"daily":"sessions");return}if(U==="1")n("today");if(U==="2")n("week");if(U==="3")n("month");if(U==="4")n("all");if(I.upArrow)if(X==="sessions")p(Math.max(0,Y-1));else R(Math.max(0,K-1));if(I.downArrow)if(X==="sessions"){let i=(o?.sessions.length||1)-1;p(Math.min(i,Y+1))}else{let i=(o?.daily.length||1)-1;R(Math.min(i,K+1))}}),P&&!o)return Z(_,{flexDirection:"column",alignItems:"center",padding:2,children:[Z(j,{},void 0,!1,void 0,this),Z(k,{color:"cyan",children:"Loading usage data..."},void 0,!1,void 0,this)]},void 0,!0,void 0,this);if(g)return Z(_,{flexDirection:"column",alignItems:"center",padding:2,children:[Z(j,{},void 0,!1,void 0,this),Z(k,{color:"red",children:["Error: ",g]},void 0,!0,void 0,this),Z(k,{color:"gray",children:"Press r to retry"},void 0,!1,void 0,this)]},void 0,!0,void 0,this);if(!o)return Z(_,{flexDirection:"column",alignItems:"center",padding:2,children:[Z(j,{},void 0,!1,void 0,this),Z(k,{color:"yellow",children:"No usage data found"},void 0,!1,void 0,this)]},void 0,!0,void 0,this);let To={today:"Today",week:"This Week",month:nc(new Date,"MMMM yyyy"),all:"All Time"}[r];return Z(_,{flexDirection:"column",padding:1,children:[Z(j,{},void 0,!1,void 0,this),Z(_,{marginBottom:1,gap:1,children:[Z(k,{color:"gray",children:"Time: "},void 0,!1,void 0,this),["today","week","month","all"].map((U,I)=>Z(_,{children:Z(k,{color:r===U?"cyan":"gray",bold:r===U,inverse:r===U,children:` ${I+1}:${U.charAt(0).toUpperCase()+U.slice(1)} `},void 0,!1,void 0,this)},U,!1,void 0,this)),Z(k,{color:"gray",children:" │ Focus: "},void 0,!1,void 0,this),["sessions","daily"].map((U)=>Z(k,{color:X===U?"yellow":"gray",bold:X===U,children:[X===U?`[${U}]`:U," "]},U,!0,void 0,this)),Z(k,{color:"gray",dimColor:!0,children:[" ","│ ",B.toLocaleTimeString()]},void 0,!0,void 0,this)]},void 0,!0,void 0,this),Z(Jo,{stats:b||o},void 0,!1,void 0,this),Z(_,{flexDirection:"column",marginTop:1,gap:1,children:[Z(_,{flexDirection:"row",gap:1,children:[Z(_,{flexDirection:"column",gap:1,width:"50%",children:[Z(Qo,{stats:o,periodLabel:To},void 0,!1,void 0,this),Z(po,{stats:o},void 0,!1,void 0,this)]},void 0,!0,void 0,this),Z(_,{flexDirection:"column",gap:1,width:"50%",children:Z(lo,{sessions:o.sessions,selectedIndex:X==="sessions"?Y:-1,maxVisible:8,focused:X==="sessions"},void 0,!1,void 0,this)},void 0,!1,void 0,this)]},void 0,!0,void 0,this),Z(_,{flexDirection:"row",gap:1,children:[Z(_,{width:"50%",children:[r==="today"&&Z(Bo,{hourlyData:o.hourly.map((U)=>({hour:U.hour,cost:U.cost}))},void 0,!1,void 0,this),r==="week"&&Z(uo,{dailyData:o.daily.map((U)=>({date:U.date,cost:U.totalCost}))},void 0,!1,void 0,this),r==="month"&&Z(Go,{dailyData:o.daily.map((U)=>({date:U.date,cost:U.totalCost}))},void 0,!1,void 0,this),r==="all"&&Z(No,{dailyData:(b||o).daily.map((U)=>({date:U.date,cost:U.totalCost}))},void 0,!1,void 0,this)]},void 0,!0,void 0,this),Z(_,{width:"50%",children:Z(Ko,{daily:o.daily,selectedIndex:X==="daily"?K:-1,maxVisible:8,focused:X==="daily"},void 0,!1,void 0,this)},void 0,!1,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this),Z(_,{marginTop:1,justifyContent:"center",children:[Z(k,{color:"gray",dimColor:!0,children:[o.entries.length," messages from ",o.sessions.length," sessions"]},void 0,!0,void 0,this),Z(k,{color:"gray",children:" • "},void 0,!1,void 0,this),P?Z(k,{color:"cyan",children:"↻ Refreshing..."},void 0,!1,void 0,this):Z(k,{color:"gray",dimColor:!0,children:["Next refresh in ",co,"s"]},void 0,!0,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this)}import{jsxDEV as Pc}from"react/jsx-dev-runtime";var oo=process.argv.slice(2),bc=oo.includes("--json")||oo.includes("-j"),gc=oo.includes("--help")||oo.includes("-h");if(gc)console.log(`
|
|
2
|
+
var Co=Object.defineProperty;var ho=(c,o)=>{for(var g in o)Co(c,g,{get:o[g],enumerable:!0,configurable:!0,set:(n)=>o[g]=()=>n})};var Yo=(c,o)=>()=>(c&&(o=c(c=0)),o);function wo(c){if(R[c])return R[c];let o=c.toLowerCase();for(let[g,n]of Object.entries(R))if(o.includes(g.toLowerCase())||g.toLowerCase().includes(o))return n;if(o.includes("opus-4-5")||o.includes("opus-4.5")||o.includes("opus4.5"))return R["claude-opus-4-5-20251101"];if(o.includes("sonnet-4-5")||o.includes("sonnet-4.5")||o.includes("sonnet4.5"))return R["claude-sonnet-4-5-20241022"];if(o.includes("haiku-4-5")||o.includes("haiku-4.5")||o.includes("haiku4.5"))return R["claude-3-5-haiku-20241022"];if(o.includes("opus-4")||o.includes("opus4"))return R["claude-opus-4-20250514"];if(o.includes("sonnet-4")||o.includes("sonnet4"))return R["claude-sonnet-4-20250514"];if(o.includes("3-5-haiku")||o.includes("3.5-haiku"))return R["claude-3-5-haiku-20241022"];if(o.includes("haiku"))return R["claude-3-haiku-20240307"];if(o.includes("opus"))return R["claude-3-opus-20240229"];if(o.includes("sonnet"))return R["claude-3-5-sonnet-20241022"];return Lo}function Qo(c,o,g,n=0,b=0){let X=wo(c),Y=o/1e6*X.input,Z=g/1e6*X.output,$=n/1e6*X.cacheWrite,A=b/1e6*X.cacheRead;return Y+Z+$+A}function Ho(c){let o=c.toLowerCase();if(o.includes("opus-4-5")||o.includes("opus-4.5"))return"Opus 4.5";if(o.includes("sonnet-4-5")||o.includes("sonnet-4.5"))return"Sonnet 4.5";if(o.includes("haiku-4-5")||o.includes("haiku-4.5"))return"Haiku 4.5";if(o.includes("opus-4")||o.includes("opus4"))return"Opus 4";if(o.includes("sonnet-4")||o.includes("sonnet4"))return"Sonnet 4";if(o.includes("3-7-sonnet")||o.includes("3.7"))return"Sonnet 3.7";if(o.includes("3-5-sonnet")||o.includes("3.5-sonnet"))return"Sonnet 3.5";if(o.includes("3-5-haiku")||o.includes("3.5-haiku"))return"Haiku 3.5";if(o.includes("opus"))return"Opus 3";if(o.includes("sonnet"))return"Sonnet 3";if(o.includes("haiku"))return"Haiku 3";return c.slice(0,20)}var R,Lo;var Po=Yo(()=>{R={"claude-opus-4-5-20251101":{input:5,output:25,cacheWrite:6.25,cacheRead:0.5},"claude-sonnet-4-5-20250929":{input:3,output:15,cacheWrite:3.75,cacheRead:0.3},"claude-haiku-4-5-20251001":{input:0.8,output:4,cacheWrite:1,cacheRead:0.08},"claude-opus-4-20250514":{input:15,output:75,cacheWrite:18.75,cacheRead:1.5},"claude-sonnet-4-5-20241022":{input:3,output:15,cacheWrite:3.75,cacheRead:0.3},"claude-sonnet-4-20250514":{input:3,output:15,cacheWrite:3.75,cacheRead:0.3},"claude-3-7-sonnet-20250219":{input:3,output:15,cacheWrite:3.75,cacheRead:0.3},"claude-3-5-sonnet-20241022":{input:3,output:15,cacheWrite:3.75,cacheRead:0.3},"claude-3-5-sonnet-20240620":{input:3,output:15,cacheWrite:3.75,cacheRead:0.3},"claude-3-5-haiku-20241022":{input:0.8,output:4,cacheWrite:1,cacheRead:0.08},"claude-3-opus-20240229":{input:15,output:75,cacheWrite:18.75,cacheRead:1.5},"claude-3-sonnet-20240229":{input:3,output:15,cacheWrite:3.75,cacheRead:0.3},"claude-3-haiku-20240307":{input:0.25,output:1.25,cacheWrite:0.3,cacheRead:0.03}},Lo={input:3,output:15,cacheWrite:3.75,cacheRead:0.3}});var Bo={};ho(Bo,{parseAllUsage:()=>t,getProjectName:()=>Xo,getAllJsonlFiles:()=>Wo,formatTokens:()=>m,formatCost:()=>N});import{homedir as mo}from"os";import{join as d}from"path";import{readdirSync as Jo,existsSync as yo,readFileSync as io,statSync as po}from"fs";function jo(c){try{let g=po(c).mtimeMs,n=go.get(c);if(n&&n.mtime===g)return n.entries;let b=[],Y=io(c,"utf-8").split(`
|
|
3
|
+
`).filter(Boolean);for(let Z of Y)try{let $=JSON.parse(Z);if($.type!=="assistant")continue;let A=$.message;if(!A?.usage||!A?.model)continue;let H=A.usage,F=H.input_tokens||0,r=H.output_tokens||0,q=H.cache_creation_input_tokens||0,p=H.cache_read_input_tokens||0;if(F===0&&r===0&&q===0&&p===0)continue;let B=Qo(A.model,F,r,q,p);b.push({timestamp:new Date($.timestamp),model:A.model,usage:{inputTokens:F,outputTokens:r,cacheCreationTokens:q,cacheReadTokens:p},cost:B,sessionId:$.sessionId||"unknown",project:$.cwd||"unknown",messageId:A.id||$.uuid||"unknown"})}catch{}return go.set(c,{mtime:g,entries:b}),b}catch{return go.delete(c),[]}}function Wo(){let c=[];if(!yo(qo))return c;try{let o=Jo(qo,{withFileTypes:!0});for(let g of o){if(!g.isDirectory())continue;let n=d(qo,g.name),b=Jo(n).filter((X)=>X.endsWith(".jsonl"));for(let X of b)c.push(d(n,X))}}catch{}return c}function Do(c){let o=0;for(let g of c)try{let n=po(g);if(n.mtimeMs>o)o=n.mtimeMs}catch{}return o}function t(c,o){let g=Date.now(),n=`${c?.getTime()??"all"}-${o?.getTime()??"all"}`,b=$o.get(n);if(b&&g-b.timestamp<Vo)return b.stats;let X=Wo(),Y=Do(X);if(b&&Ao&&Ao.mtime>=Y)return $o.set(n,{timestamp:g,stats:b.stats}),b.stats;let Z=[];for(let r of X){let q=jo(r);Z.push(...q)}Ao={mtime:Y,entries:Z};let $=Z;if(c)$=$.filter((r)=>r.timestamp>=c);if(o)$=$.filter((r)=>r.timestamp<=o);let A=new Set,H=[];$.sort((r,q)=>q.timestamp.getTime()-r.timestamp.getTime());for(let r of $){let q=`${r.sessionId}-${r.messageId}`;if(!A.has(q))A.add(q),H.push(r)}H.sort((r,q)=>r.timestamp.getTime()-q.timestamp.getTime());let F=xo(H);return $o.set(n,{timestamp:g,stats:F}),F}function xo(c){let o={inputTokens:0,outputTokens:0,cacheCreationTokens:0,cacheReadTokens:0},g=0,n={},b=new Map,X=new Map,Y=new Map,Z=new Date;Z.setHours(0,0,0,0);for(let F of c){if(g+=F.cost,o.inputTokens+=F.usage.inputTokens,o.outputTokens+=F.usage.outputTokens,o.cacheCreationTokens+=F.usage.cacheCreationTokens,o.cacheReadTokens+=F.usage.cacheReadTokens,!n[F.model])n[F.model]={cost:0,tokens:{inputTokens:0,outputTokens:0,cacheCreationTokens:0,cacheReadTokens:0},displayName:Ho(F.model)};let r=n[F.model];if(r.cost+=F.cost,r.tokens.inputTokens+=F.usage.inputTokens,r.tokens.outputTokens+=F.usage.outputTokens,r.tokens.cacheCreationTokens+=F.usage.cacheCreationTokens,r.tokens.cacheReadTokens+=F.usage.cacheReadTokens,!b.has(F.sessionId))b.set(F.sessionId,[]);b.get(F.sessionId).push(F);let q=`${F.timestamp.getFullYear()}-${String(F.timestamp.getMonth()+1).padStart(2,"0")}-${String(F.timestamp.getDate()).padStart(2,"0")}`;if(!X.has(q))X.set(q,[]);if(X.get(q).push(F),F.timestamp>=Z){let p=F.timestamp.getHours();if(!Y.has(p))Y.set(p,{cost:0,tokens:0,messageCount:0});let B=Y.get(p);B.cost+=F.cost,B.tokens+=F.usage.inputTokens+F.usage.outputTokens+F.usage.cacheCreationTokens+F.usage.cacheReadTokens,B.messageCount+=1}}let $=[];for(let[F,r]of b){let q=r.sort((M,co)=>M.timestamp.getTime()-co.timestamp.getTime()),p={inputTokens:0,outputTokens:0,cacheCreationTokens:0,cacheReadTokens:0},B=0;for(let M of q)B+=M.cost,p.inputTokens+=M.usage.inputTokens,p.outputTokens+=M.usage.outputTokens,p.cacheCreationTokens+=M.usage.cacheCreationTokens,p.cacheReadTokens+=M.usage.cacheReadTokens;let h=q[0],u=q[q.length-1];$.push({sessionId:F,project:h.project,firstMessage:h.timestamp,lastMessage:u.timestamp,totalCost:B,totalTokens:p,messageCount:q.length,model:u.model})}$.sort((F,r)=>r.lastMessage.getTime()-F.lastMessage.getTime());let A=[];for(let[F,r]of X){let q={inputTokens:0,outputTokens:0,cacheCreationTokens:0,cacheReadTokens:0},p=0,B={},h=new Set;for(let u of r){if(p+=u.cost,q.inputTokens+=u.usage.inputTokens,q.outputTokens+=u.usage.outputTokens,q.cacheCreationTokens+=u.usage.cacheCreationTokens,q.cacheReadTokens+=u.usage.cacheReadTokens,h.add(u.sessionId),!B[u.model])B[u.model]={cost:0,tokens:{inputTokens:0,outputTokens:0,cacheCreationTokens:0,cacheReadTokens:0}};let M=B[u.model];M.cost+=u.cost,M.tokens.inputTokens+=u.usage.inputTokens,M.tokens.outputTokens+=u.usage.outputTokens,M.tokens.cacheCreationTokens+=u.usage.cacheCreationTokens,M.tokens.cacheReadTokens+=u.usage.cacheReadTokens}A.push({date:F,totalCost:p,totalTokens:q,sessionCount:h.size,messageCount:r.length,byModel:B})}A.sort((F,r)=>r.date.localeCompare(F.date));let H=[];for(let[F,r]of Y)H.push({hour:F,cost:r.cost,tokens:r.tokens,messageCount:r.messageCount});return H.sort((F,r)=>F.hour-r.hour),{messageCount:c.length,sessions:$,daily:A,hourly:H,totalCost:g,totalTokens:o,byModel:n}}function N(c){if(c>=1000)return`$${(c/1000).toFixed(2)}K`;if(c>=1)return`$${c.toFixed(2)}`;if(c>=0.01)return`$${c.toFixed(2)}`;return`${(c*100).toFixed(2)}¢`}function m(c){if(c>=1e6)return`${(c/1e6).toFixed(2)}M`;if(c>=1000)return`${(c/1000).toFixed(1)}K`;return c.toString()}function Xo(c){let o=c.split("/");return o[o.length-1]||c}var go,Ao=null,$o,Vo=4000,Eo,qo;var E=Yo(()=>{Po();go=new Map,$o=new Map,Eo=d(mo(),".claude"),qo=d(Eo,"projects")});import{render as Xc}from"ink";import{useState as w,useEffect as _o}from"react";import{Box as _,Text as I,useApp as nc,useInput as bc}from"ink";import{Box as Fo,Text as f}from"ink";import{jsxDEV as K}from"react/jsx-dev-runtime";function j(){return K(Fo,{flexDirection:"column",alignItems:"center",marginBottom:1,children:[K(Fo,{children:[K(f,{color:"#FF6B6B",bold:!0,children:"C"},void 0,!1,void 0,this),K(f,{color:"#FF8E53",bold:!0,children:"L"},void 0,!1,void 0,this),K(f,{color:"#FFBA49",bold:!0,children:"A"},void 0,!1,void 0,this),K(f,{color:"#7BED9F",bold:!0,children:"U"},void 0,!1,void 0,this),K(f,{color:"#70A1FF",bold:!0,children:"D"},void 0,!1,void 0,this),K(f,{color:"#5352ED",bold:!0,children:"E"},void 0,!1,void 0,this),K(f,{color:"white",children:" "},void 0,!1,void 0,this),K(f,{color:"#A29BFE",bold:!0,children:"C"},void 0,!1,void 0,this),K(f,{color:"#FD79A8",bold:!0,children:"O"},void 0,!1,void 0,this),K(f,{color:"#FF6B6B",bold:!0,children:"S"},void 0,!1,void 0,this),K(f,{color:"#FF8E53",bold:!0,children:"T"},void 0,!1,void 0,this),K(f,{color:"gray",dimColor:!0,children:" │ Usage Analytics Dashboard"},void 0,!1,void 0,this)]},void 0,!0,void 0,this),K(Fo,{children:[K(f,{color:"gray",children:"Press "},void 0,!1,void 0,this),K(f,{color:"yellow",children:"↑↓"},void 0,!1,void 0,this),K(f,{color:"gray",children:" scroll • "},void 0,!1,void 0,this),K(f,{color:"yellow",children:"tab"},void 0,!1,void 0,this),K(f,{color:"gray",children:" switch view • "},void 0,!1,void 0,this),K(f,{color:"yellow",children:"r"},void 0,!1,void 0,this),K(f,{color:"gray",children:" refresh • "},void 0,!1,void 0,this),K(f,{color:"yellow",children:"q"},void 0,!1,void 0,this),K(f,{color:"gray",children:" quit"},void 0,!1,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this)}import{Box as k,Text as G}from"ink";import{Box as bo,Text as D}from"ink";import{jsxDEV as V}from"react/jsx-dev-runtime";function S({title:c,children:o,width:g,borderColor:n="gray",titleColor:b="white"}){return V(bo,{flexDirection:"column",borderStyle:"round",borderColor:n,paddingX:1,width:g,children:[c&&V(bo,{marginBottom:0,children:V(D,{color:b,bold:!0,children:c},void 0,!1,void 0,this)},void 0,!1,void 0,this),o]},void 0,!0,void 0,this)}function Zo({value:c,max:o,width:g=20,color:n="green",showPercent:b=!1}){let X=o>0?Math.min(c/o,1):0,Y=Math.round(X*g),Z=g-Y,$="█".repeat(Y)+"░".repeat(Z);return V(bo,{children:[V(D,{color:n,children:$},void 0,!1,void 0,this),b&&V(D,{color:"gray",children:[" ",(X*100).toFixed(0),"%"]},void 0,!0,void 0,this)]},void 0,!0,void 0,this)}var no=["▁","▂","▃","▄","▅","▆","▇","█"];function zo({data:c,width:o=20,color:g="cyan"}){if(c.length===0)return V(D,{color:"gray",children:"─".repeat(o)},void 0,!1,void 0,this);let n=[],b=Math.max(1,Math.floor(c.length/o));for(let H=0;H<c.length;H+=b){let F=c.slice(H,Math.min(H+b,c.length));n.push(F.reduce((r,q)=>r+q,0)/F.length)}let X=Math.max(...n,0.001),Y=Math.min(...n,0),Z=X-Y||1,A=n.slice(-o).map((H)=>{let F=(H-Y)/Z,r=Math.min(Math.floor(F*no.length),no.length-1);return no[r]}).join("").padStart(o," ");return V(D,{color:g,children:A},void 0,!1,void 0,this)}E();import{startOfWeek as to,startOfMonth as eo}from"date-fns";import{jsxDEV as P}from"react/jsx-dev-runtime";function Ko({stats:c,periodLabel:o}){let g=c.totalTokens.inputTokens+c.totalTokens.outputTokens+c.totalTokens.cacheCreationTokens+c.totalTokens.cacheReadTokens,n=c.totalTokens.cacheReadTokens/1e6*3,b=c.totalTokens.cacheReadTokens/1e6*0.3,X=Math.max(0,n-b),Y=c.daily.slice().reverse().map((Z)=>Z.totalCost);return P(S,{title:`\uD83D\uDCB0 ${o} Summary`,borderColor:"green",titleColor:"green",children:P(k,{flexDirection:"column",gap:0,children:[P(k,{children:[P(k,{width:18,children:P(G,{color:"gray",children:"Total Cost"},void 0,!1,void 0,this)},void 0,!1,void 0,this),P(G,{color:"green",bold:!0,children:N(c.totalCost)},void 0,!1,void 0,this)]},void 0,!0,void 0,this),P(k,{children:[P(k,{width:18,children:P(G,{color:"gray",children:"Total Tokens"},void 0,!1,void 0,this)},void 0,!1,void 0,this),P(G,{color:"cyan",children:m(g)},void 0,!1,void 0,this)]},void 0,!0,void 0,this),P(k,{children:[P(k,{width:18,children:P(G,{color:"gray",children:"Sessions"},void 0,!1,void 0,this)},void 0,!1,void 0,this),P(G,{color:"yellow",children:c.sessions.length},void 0,!1,void 0,this)]},void 0,!0,void 0,this),P(k,{children:[P(k,{width:18,children:P(G,{color:"gray",children:"Messages"},void 0,!1,void 0,this)},void 0,!1,void 0,this),P(G,{color:"magenta",children:c.messageCount},void 0,!1,void 0,this)]},void 0,!0,void 0,this),X>0&&P(k,{children:[P(k,{width:18,children:P(G,{color:"gray",children:"Cache Savings"},void 0,!1,void 0,this)},void 0,!1,void 0,this),P(G,{color:"#7BED9F",children:["~",N(X)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this),P(k,{marginTop:1,children:[P(G,{color:"gray",dimColor:!0,children:"Daily trend: "},void 0,!1,void 0,this),P(zo,{data:Y,width:18,color:"#70A1FF"},void 0,!1,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this)},void 0,!1,void 0,this)}function fo({stats:c}){let o=new Date,g=`${o.getFullYear()}-${String(o.getMonth()+1).padStart(2,"0")}-${String(o.getDate()).padStart(2,"0")}`,n=c.daily.find((r)=>r.date===g),b=to(o,{weekStartsOn:0}),X=c.daily.filter((r)=>new Date(r.date)>=b),Y=X.reduce((r,q)=>r+q.totalCost,0),Z=X.reduce((r,q)=>r+q.messageCount,0),$=eo(o),A=c.daily.filter((r)=>new Date(r.date)>=$),H=A.reduce((r,q)=>r+q.totalCost,0),F=A.reduce((r,q)=>r+q.messageCount,0);return P(k,{flexDirection:"row",gap:2,children:[P(S,{title:"Today",borderColor:"cyan",titleColor:"cyan",children:[P(G,{color:"green",bold:!0,children:N(n?.totalCost||0)},void 0,!1,void 0,this),P(G,{color:"gray",dimColor:!0,children:[" ",n?.messageCount||0," msgs"]},void 0,!0,void 0,this)]},void 0,!0,void 0,this),P(S,{title:"This Week",borderColor:"blue",titleColor:"blue",children:[P(G,{color:"green",bold:!0,children:N(Y)},void 0,!1,void 0,this),P(G,{color:"gray",dimColor:!0,children:[" ",Z," msgs"]},void 0,!0,void 0,this)]},void 0,!0,void 0,this),P(S,{title:"This Month",borderColor:"magenta",titleColor:"magenta",children:[P(G,{color:"green",bold:!0,children:N(H)},void 0,!1,void 0,this),P(G,{color:"gray",dimColor:!0,children:[" ",F," msgs"]},void 0,!0,void 0,this)]},void 0,!0,void 0,this),P(S,{title:"All Time",borderColor:"yellow",titleColor:"yellow",children:[P(G,{color:"green",bold:!0,children:N(c.totalCost)},void 0,!1,void 0,this),P(G,{color:"gray",dimColor:!0,children:[" ",c.messageCount," msgs"]},void 0,!0,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this)}import{Box as x,Text as e}from"ink";E();import{jsxDEV as C}from"react/jsx-dev-runtime";var ao={"Opus 4.5":"#FF6B6B","Opus 4":"#FF8E53","Opus 3":"#FFBA49","Sonnet 4":"#70A1FF","Sonnet 3.7":"#5352ED","Sonnet 3.5":"#A29BFE","Sonnet 3":"#B8B5FF","Haiku 3.5":"#7BED9F","Haiku 3":"#2ECC71"};function uo({stats:c}){let o=Object.entries(c.byModel).sort(([,n],[,b])=>b.cost-n.cost),g=Math.max(...o.map(([,n])=>n.cost),0.01);return C(S,{title:"\uD83D\uDCCA Cost by Model",borderColor:"cyan",titleColor:"cyan",children:C(x,{flexDirection:"column",gap:0,children:o.length===0?C(e,{color:"gray",dimColor:!0,children:"No usage data"},void 0,!1,void 0,this):o.map(([n,b])=>{let X=ao[b.displayName]||"#888",Y=b.tokens.inputTokens+b.tokens.outputTokens+b.tokens.cacheCreationTokens+b.tokens.cacheReadTokens;return C(x,{flexDirection:"column",marginBottom:0,children:C(x,{children:[C(x,{width:12,children:C(e,{color:X,bold:!0,children:b.displayName},void 0,!1,void 0,this)},void 0,!1,void 0,this),C(x,{width:10,children:C(e,{color:"white",bold:!0,children:N(b.cost)},void 0,!1,void 0,this)},void 0,!1,void 0,this),C(Zo,{value:b.cost,max:g,width:16,color:X},void 0,!1,void 0,this),C(e,{color:"gray",dimColor:!0,children:[" ",m(Y)," tok"]},void 0,!0,void 0,this)]},void 0,!0,void 0,this)},n,!1,void 0,this)})},void 0,!1,void 0,this)},void 0,!1,void 0,this)}import{Box as L,Text as v}from"ink";E();import{formatDistanceToNow as so,format as oc}from"date-fns";import{jsxDEV as W}from"react/jsx-dev-runtime";var y={"Opus 4.5":{symbol:"◆",color:"#FF6B6B"},"Opus 4":{symbol:"◆",color:"#FF8E53"},"Opus 3":{symbol:"◆",color:"#FFBA49"},"Sonnet 4":{symbol:"●",color:"#70A1FF"},"Sonnet 3.7":{symbol:"●",color:"#5352ED"},"Sonnet 3.5":{symbol:"●",color:"#A29BFE"},"Sonnet 3":{symbol:"●",color:"#B8B5FF"},"Haiku 3.5":{symbol:"○",color:"#7BED9F"},"Haiku 3":{symbol:"○",color:"#2ECC71"}};function cc(c){let o=c.toLowerCase();if(o.includes("opus-4-5")||o.includes("opus-4.5"))return y["Opus 4.5"];if(o.includes("opus-4")||o.includes("opus4"))return y["Opus 4"];if(o.includes("sonnet-4")||o.includes("sonnet4"))return y["Sonnet 4"];if(o.includes("3-7-sonnet")||o.includes("3.7"))return y["Sonnet 3.7"];if(o.includes("3-5-sonnet")||o.includes("3.5-sonnet"))return y["Sonnet 3.5"];if(o.includes("3-5-haiku")||o.includes("3.5-haiku"))return y["Haiku 3.5"];if(o.includes("opus"))return y["Opus 3"];if(o.includes("sonnet"))return y["Sonnet 3"];if(o.includes("haiku"))return y["Haiku 3"];return{symbol:"◯",color:"#888"}}function Go({sessions:c,selectedIndex:o,maxVisible:g=8,focused:n=!1}){let b=Math.max(0,Math.min(o-Math.floor(g/2),c.length-g)),X=c.slice(b,b+g),Y=b>0,Z=b+g<c.length;return W(S,{title:`\uD83D\uDCDD Recent Sessions${n?" (↑↓)":""}`,borderColor:n?"cyan":"yellow",titleColor:n?"cyan":"yellow",children:W(L,{flexDirection:"column",children:[Y&&W(L,{justifyContent:"center",children:W(v,{color:"gray",children:["▲ ",b," more"]},void 0,!0,void 0,this)},void 0,!1,void 0,this),X.length===0?W(v,{color:"gray",dimColor:!0,children:"No sessions found"},void 0,!1,void 0,this):X.map(($,A)=>{let F=b+A===o,r=cc($.model),q=Xo($.project),p=so($.lastMessage,{addSuffix:!0}),B=$.totalTokens.inputTokens+$.totalTokens.outputTokens+$.totalTokens.cacheCreationTokens+$.totalTokens.cacheReadTokens;return W(L,{flexDirection:"column",paddingX:1,paddingY:0,borderStyle:F?"round":void 0,borderColor:F?"cyan":void 0,children:[W(L,{children:[W(v,{color:r.color,children:[r.symbol," "]},void 0,!0,void 0,this),W(v,{color:F?"cyan":"white",bold:!0,children:q.slice(0,24).padEnd(24)},void 0,!1,void 0,this),W(v,{color:"green",bold:!0,children:[" ",N($.totalCost).padStart(8)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this),W(L,{children:[W(v,{color:"gray",children:" "},void 0,!1,void 0,this),W(v,{color:"gray",dimColor:!0,children:p.padEnd(20)},void 0,!1,void 0,this),W(v,{color:"gray",dimColor:!0,children:[m(B)," tok"]},void 0,!0,void 0,this),W(v,{color:"gray",dimColor:!0,children:[" • ",$.messageCount," msgs"]},void 0,!0,void 0,this)]},void 0,!0,void 0,this)]},`${$.sessionId}-${A}`,!0,void 0,this)}),Z&&W(L,{justifyContent:"center",children:W(v,{color:"gray",children:["▼ ",c.length-b-g," more"]},void 0,!0,void 0,this)},void 0,!1,void 0,this)]},void 0,!0,void 0,this)},void 0,!1,void 0,this)}function No({daily:c,selectedIndex:o,maxVisible:g=8,focused:n=!1}){let b=Math.max(0,Math.min(o-Math.floor(g/2),c.length-g)),X=c.slice(b,b+g),Y=Math.max(...c.map((A)=>A.totalCost),0.01),Z=b>0,$=b+g<c.length;return W(S,{title:`\uD83D\uDCC5 Daily Costs${n?" (↑↓)":""}`,borderColor:n?"cyan":"green",titleColor:n?"cyan":"green",children:W(L,{flexDirection:"column",children:[Z&&W(L,{justifyContent:"center",children:W(v,{color:"gray",children:["▲ ",b," more"]},void 0,!0,void 0,this)},void 0,!1,void 0,this),X.length===0?W(v,{color:"gray",dimColor:!0,children:"No daily data"},void 0,!1,void 0,this):X.map((A,H)=>{let r=b+H===o,q=A.date===new Date().toISOString().slice(0,10),p=Math.max(1,Math.round(A.totalCost/Y*20)),B="█".repeat(p),h=A.totalTokens.inputTokens+A.totalTokens.outputTokens+A.totalTokens.cacheCreationTokens+A.totalTokens.cacheReadTokens;return W(L,{paddingX:1,borderStyle:r?"round":void 0,borderColor:r?"cyan":void 0,children:[W(v,{color:q?"cyan":"gray",children:oc(new Date(A.date),"MMM dd")},void 0,!1,void 0,this),W(v,{color:"green",bold:!0,children:[" ",N(A.totalCost).padStart(8)," "]},void 0,!0,void 0,this),W(v,{color:"#70A1FF",children:B.padEnd(20)},void 0,!1,void 0,this),W(v,{color:"gray",dimColor:!0,children:[" ",m(h)]},void 0,!0,void 0,this)]},`${A.date}-${H}`,!0,void 0,this)}),$&&W(L,{justifyContent:"center",children:W(v,{color:"gray",children:["▼ ",c.length-b-g," more"]},void 0,!0,void 0,this)},void 0,!1,void 0,this)]},void 0,!0,void 0,this)},void 0,!1,void 0,this)}import{Box as T,Text as J}from"ink";E();import{format as a,startOfWeek as vo,eachDayOfInterval as rc,subDays as Fc}from"date-fns";import{jsxDEV as U}from"react/jsx-dev-runtime";var l=["#161b22","#0e4429","#006d32","#26a641","#39d353"];function s(c,o){if(c===0)return l[0];let g=c/o;if(g<0.25)return l[1];if(g<0.5)return l[2];if(g<0.75)return l[3];return l[4]}function To({hourlyData:c}){let o=[];for(let X=0;X<24;X++){let Y=c.find((Z)=>Z.hour===X);o.push(Y?.cost||0)}let g=Math.max(...o,0.01),n=o.reduce((X,Y)=>X+Y,0),b=o.indexOf(Math.max(...o));return U(S,{title:"Activity (Today)",borderColor:"gray",titleColor:"gray",children:U(T,{flexDirection:"column",children:[U(T,{flexDirection:"row",gap:0,children:o.map((X,Y)=>U(J,{color:s(X,g),children:"██"},Y,!1,void 0,this))},void 0,!1,void 0,this),U(T,{marginTop:0,children:U(J,{color:"gray",dimColor:!0,children:"0 6 12 18 23"},void 0,!1,void 0,this)},void 0,!1,void 0,this),U(T,{marginTop:0,gap:2,children:[U(J,{color:"gray",dimColor:!0,children:"Total: "},void 0,!1,void 0,this),U(J,{color:"green",children:N(n)},void 0,!1,void 0,this),U(J,{color:"gray",dimColor:!0,children:" Peak hour: "},void 0,!1,void 0,this),U(J,{color:"cyan",children:[b,":00"]},void 0,!0,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this)},void 0,!1,void 0,this)}function So({dailyData:c}){let o=new Date,g=vo(o,{weekStartsOn:0}),b=rc({start:g,end:o}).map((Z)=>{let $=a(Z,"yyyy-MM-dd"),A=c.find((H)=>H.date===$);return{day:Z,cost:A?.cost||0,label:a(Z,"EEE")}}),X=Math.max(...b.map((Z)=>Z.cost),0.01),Y=b.reduce((Z,$)=>Z+$.cost,0);return U(S,{title:"Activity (This Week)",borderColor:"gray",titleColor:"gray",children:U(T,{flexDirection:"column",children:[U(T,{flexDirection:"row",gap:2,children:b.map((Z,$)=>U(T,{flexDirection:"column",alignItems:"center",children:[U(J,{color:s(Z.cost,X),children:"██████"},void 0,!1,void 0,this),U(J,{color:"gray",dimColor:!0,children:Z.label},void 0,!1,void 0,this)]},$,!0,void 0,this))},void 0,!1,void 0,this),U(T,{marginTop:1,gap:2,children:[U(J,{color:"gray",dimColor:!0,children:"Total: "},void 0,!1,void 0,this),U(J,{color:"green",children:N(Y)},void 0,!1,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this)},void 0,!1,void 0,this)}function Mo({dailyData:c}){let o=new Date,g=o.getFullYear(),n=o.getMonth(),b=new Date(g,n,1),X=new Date(g,n+1,0),Y=b.getDay(),Z=[];for(let r=0;r<Y;r++)Z.push({day:null,cost:0});for(let r=1;r<=X.getDate();r++){let q=`${g}-${String(n+1).padStart(2,"0")}-${String(r).padStart(2,"0")}`,p=c.find((B)=>B.date===q);Z.push({day:r,cost:p?.cost||0})}while(Z.length%7!==0)Z.push({day:null,cost:0});let $=Math.max(...Z.map((r)=>r.cost),0.01),A=Z.reduce((r,q)=>r+q.cost,0),H=[];for(let r=0;r<Z.length;r+=7)H.push(Z.slice(r,r+7));let F=["S","M","T","W","T","F","S"];return U(S,{title:`Activity (${a(o,"MMMM yyyy")})`,borderColor:"gray",titleColor:"gray",children:U(T,{flexDirection:"column",children:[U(T,{flexDirection:"row",gap:1,children:F.map((r,q)=>U(J,{color:"gray",dimColor:!0,children:[r," "]},q,!0,void 0,this))},void 0,!1,void 0,this),H.map((r,q)=>U(T,{flexDirection:"row",gap:1,children:r.map((p,B)=>U(J,{color:p.day?s(p.cost,$):"#0d1117",children:"██"},B,!1,void 0,this))},q,!1,void 0,this)),U(T,{marginTop:1,gap:2,children:[U(J,{color:"gray",dimColor:!0,children:"Total: "},void 0,!1,void 0,this),U(J,{color:"green",children:N(A)},void 0,!1,void 0,this),U(T,{marginLeft:1,children:[U(J,{color:l[0],children:"█"},void 0,!1,void 0,this),U(J,{color:"gray",dimColor:!0,children:" Less "},void 0,!1,void 0,this),U(J,{color:l[1],children:"█"},void 0,!1,void 0,this),U(J,{color:l[2],children:"█"},void 0,!1,void 0,this),U(J,{color:l[3],children:"█"},void 0,!1,void 0,this),U(J,{color:l[4],children:"█"},void 0,!1,void 0,this),U(J,{color:"gray",dimColor:!0,children:" More"},void 0,!1,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this)},void 0,!1,void 0,this)}function lo({dailyData:c}){let o=new Date,g=Math.min(26,Math.ceil(c.length/7)||12),n=Array.from({length:7},()=>[]);for(let $=g-1;$>=0;$--){let A=vo(Fc(o,$*7),{weekStartsOn:0});for(let H=0;H<7;H++){let F=new Date(A);F.setDate(A.getDate()+H);let r=a(F,"yyyy-MM-dd"),q=c.find((p)=>p.date===r);n[H].push(q?.cost||0)}}let b=n.flat(),X=Math.max(...b,0.01),Y=b.reduce(($,A)=>$+A,0),Z=["S","M","T","W","T","F","S"];return U(S,{title:"Activity (All Time)",borderColor:"gray",titleColor:"gray",children:U(T,{flexDirection:"column",children:[n.map(($,A)=>U(T,{flexDirection:"row",children:[U(J,{color:"gray",dimColor:!0,children:[Z[A]," "]},void 0,!0,void 0,this),$.map((H,F)=>U(J,{color:s(H,X),children:"██"},F,!1,void 0,this))]},A,!0,void 0,this)),U(T,{marginTop:1,gap:2,children:[U(J,{color:"gray",dimColor:!0,children:"Total: "},void 0,!1,void 0,this),U(J,{color:"green",children:N(Y)},void 0,!1,void 0,this),U(J,{color:"gray",dimColor:!0,children:[" (",c.length," days)"]},void 0,!0,void 0,this),U(T,{marginLeft:1,children:[U(J,{color:l[0],children:"█"},void 0,!1,void 0,this),U(J,{color:"gray",dimColor:!0,children:" Less "},void 0,!1,void 0,this),U(J,{color:l[1],children:"█"},void 0,!1,void 0,this),U(J,{color:l[2],children:"█"},void 0,!1,void 0,this),U(J,{color:l[3],children:"█"},void 0,!1,void 0,this),U(J,{color:l[4],children:"█"},void 0,!1,void 0,this),U(J,{color:"gray",dimColor:!0,children:" More"},void 0,!1,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this)},void 0,!1,void 0,this)}E();import{startOfWeek as gc,startOfMonth as Ac,endOfMonth as $c,format as qc}from"date-fns";import{jsxDEV as Q}from"react/jsx-dev-runtime";function ko(){let{exit:c}=nc(),[o,g]=w(null),[n,b]=w(null),[X,Y]=w(!0),[Z,$]=w(null),[A,H]=w("sessions"),[F,r]=w("today"),[q,p]=w(0),[B,h]=w(0),[u,M]=w(new Date),[co,Uo]=w(5),Qc=5,ro=()=>{Y(!0),$(null);try{let z,O,i=new Date;switch(F){case"today":z=new Date(i),z.setHours(0,0,0,0);break;case"week":z=gc(i,{weekStartsOn:0});break;case"month":z=Ac(i),O=$c(i);break;case"all":default:z=void 0}let Oo=t(z,O);g(Oo);let Ro=t();b(Ro),M(new Date)}catch(z){$(z instanceof Error?z.message:"Unknown error")}finally{Y(!1)}};if(_o(()=>{ro()},[F]),_o(()=>{let z=setInterval(()=>{Uo((O)=>{if(O<=1)return ro(),5;return O-1})},1000);return()=>clearInterval(z)},[F]),bc((z,O)=>{if(z==="q"||O.ctrl&&z==="c"){c();return}if(z==="r"){ro(),Uo(5);return}if(O.tab||z==="\t"){H(A==="sessions"?"daily":"sessions");return}if(z==="1")r("today");if(z==="2")r("week");if(z==="3")r("month");if(z==="4")r("all");if(O.upArrow)if(A==="sessions")p(Math.max(0,q-1));else h(Math.max(0,B-1));if(O.downArrow)if(A==="sessions"){let i=(o?.sessions.length||1)-1;p(Math.min(i,q+1))}else{let i=(o?.daily.length||1)-1;h(Math.min(i,B+1))}}),X&&!o)return Q(_,{flexDirection:"column",alignItems:"center",padding:2,children:[Q(j,{},void 0,!1,void 0,this),Q(I,{color:"cyan",children:"Loading usage data..."},void 0,!1,void 0,this)]},void 0,!0,void 0,this);if(Z)return Q(_,{flexDirection:"column",alignItems:"center",padding:2,children:[Q(j,{},void 0,!1,void 0,this),Q(I,{color:"red",children:["Error: ",Z]},void 0,!0,void 0,this),Q(I,{color:"gray",children:"Press r to retry"},void 0,!1,void 0,this)]},void 0,!0,void 0,this);if(!o)return Q(_,{flexDirection:"column",alignItems:"center",padding:2,children:[Q(j,{},void 0,!1,void 0,this),Q(I,{color:"yellow",children:"No usage data found"},void 0,!1,void 0,this)]},void 0,!0,void 0,this);let Io={today:"Today",week:"This Week",month:qc(new Date,"MMMM yyyy"),all:"All Time"}[F];return Q(_,{flexDirection:"column",padding:1,children:[Q(j,{},void 0,!1,void 0,this),Q(_,{marginBottom:1,gap:1,children:[Q(I,{color:"gray",children:"Time: "},void 0,!1,void 0,this),["today","week","month","all"].map((z,O)=>Q(_,{children:Q(I,{color:F===z?"cyan":"gray",bold:F===z,inverse:F===z,children:` ${O+1}:${z.charAt(0).toUpperCase()+z.slice(1)} `},void 0,!1,void 0,this)},z,!1,void 0,this)),Q(I,{color:"gray",children:" │ Focus: "},void 0,!1,void 0,this),["sessions","daily"].map((z)=>Q(I,{color:A===z?"yellow":"gray",bold:A===z,children:[A===z?`[${z}]`:z," "]},z,!0,void 0,this)),Q(I,{color:"gray",dimColor:!0,children:[" ","│ ",u.toLocaleTimeString()]},void 0,!0,void 0,this)]},void 0,!0,void 0,this),Q(fo,{stats:n||o},void 0,!1,void 0,this),Q(_,{flexDirection:"column",marginTop:1,gap:1,children:[Q(_,{flexDirection:"row",gap:1,children:[Q(_,{flexDirection:"column",gap:1,width:"50%",children:[Q(Ko,{stats:o,periodLabel:Io},void 0,!1,void 0,this),Q(uo,{stats:o},void 0,!1,void 0,this)]},void 0,!0,void 0,this),Q(_,{flexDirection:"column",gap:1,width:"50%",children:Q(Go,{sessions:o.sessions,selectedIndex:A==="sessions"?q:-1,maxVisible:8,focused:A==="sessions"},void 0,!1,void 0,this)},void 0,!1,void 0,this)]},void 0,!0,void 0,this),Q(_,{flexDirection:"row",gap:1,children:[Q(_,{width:"50%",children:[F==="today"&&Q(To,{hourlyData:o.hourly.map((z)=>({hour:z.hour,cost:z.cost}))},void 0,!1,void 0,this),F==="week"&&Q(So,{dailyData:o.daily.map((z)=>({date:z.date,cost:z.totalCost}))},void 0,!1,void 0,this),F==="month"&&Q(Mo,{dailyData:o.daily.map((z)=>({date:z.date,cost:z.totalCost}))},void 0,!1,void 0,this),F==="all"&&Q(lo,{dailyData:(n||o).daily.map((z)=>({date:z.date,cost:z.totalCost}))},void 0,!1,void 0,this)]},void 0,!0,void 0,this),Q(_,{width:"50%",children:Q(No,{daily:o.daily,selectedIndex:A==="daily"?B:-1,maxVisible:8,focused:A==="daily"},void 0,!1,void 0,this)},void 0,!1,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this),Q(_,{marginTop:1,justifyContent:"center",children:[Q(I,{color:"gray",dimColor:!0,children:[o.messageCount," messages from ",o.sessions.length," sessions"]},void 0,!0,void 0,this),Q(I,{color:"gray",children:" • "},void 0,!1,void 0,this),X?Q(I,{color:"cyan",children:"↻ Refreshing..."},void 0,!1,void 0,this):Q(I,{color:"gray",dimColor:!0,children:["Next refresh in ",co,"s"]},void 0,!0,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this)}import{jsxDEV as zc}from"react/jsx-dev-runtime";var oo=process.argv.slice(2),Uc=oo.includes("--json")||oo.includes("-j"),Yc=oo.includes("--help")||oo.includes("-h");if(Yc)console.log(`
|
|
4
4
|
\x1B[1m\x1B[36mCLAUDE COST\x1B[0m - Beautiful Claude Code Usage Analytics
|
|
5
5
|
|
|
6
6
|
\x1B[33mUsage:\x1B[0m
|
|
@@ -19,4 +19,4 @@ var ho=Object.defineProperty;var ko=(c,o)=>{for(var A in o)ho(c,A,{get:o[A],enum
|
|
|
19
19
|
Reads from ~/.claude/projects/*/*.jsonl
|
|
20
20
|
|
|
21
21
|
\x1B[90mPricing based on LiteLLM model costs\x1B[0m
|
|
22
|
-
`),process.exit(0);var
|
|
22
|
+
`),process.exit(0);var Zc=process.stdin.isTTY&&process.stdout.isTTY;if(!Zc||Uc){let{parseAllUsage:c,formatCost:o,formatTokens:g}=await Promise.resolve().then(() => (E(),Bo)),n=c(),b={totalCost:o(n.totalCost),totalTokens:g(n.totalTokens.inputTokens+n.totalTokens.outputTokens+n.totalTokens.cacheCreationTokens+n.totalTokens.cacheReadTokens),sessions:n.sessions.length,messages:n.messageCount,breakdown:Object.fromEntries(Object.entries(n.byModel).map(([X,Y])=>[Y.displayName,{cost:o(Y.cost),tokens:g(Y.tokens.inputTokens+Y.tokens.outputTokens+Y.tokens.cacheCreationTokens+Y.tokens.cacheReadTokens)}]))};console.log(JSON.stringify(b,null,2)),process.exit(0)}console.clear();Xc(zc(ko,{},void 0,!1,void 0,this));
|