11import { DEFAULT_CLIENT_VERSIONS } from "../clientVersions" ;
2- import { normalizePercent , toEpochMs } from "../formatters" ;
2+ import { toEpochMs } from "../formatters" ;
33import type { CollectOptions , HostPort } from "../host" ;
44import type { UsageSnapshot , UsageWindow , UsageWindowId } from "../types" ;
55
@@ -52,9 +52,8 @@ function windowFrom(
5252 id : UsageWindowId ,
5353 label : string ,
5454 raw : ClaudeWindowRaw | undefined ,
55- normalize : ( value : number | undefined ) => number | undefined = normalizePercent ,
5655) : UsageWindow | undefined {
57- const usedPercent = normalize ( raw ?. utilization ) ;
56+ const usedPercent = normalizeClaudePercent ( raw ?. utilization ) ;
5857 if ( usedPercent === undefined ) return undefined ;
5958 const resetsAt = toEpochMs ( raw ?. resets_at ) ;
6059 return {
@@ -66,7 +65,13 @@ function windowFrom(
6665 } ;
6766}
6867
69- function normalizeClaudeSessionPercent ( value : number | undefined ) : number | undefined {
68+ /**
69+ * The Claude `/api/oauth/usage` endpoint reports `utilization` already in
70+ * percent (0-100) for every window — session, weekly, and overage alike. Clamp
71+ * to 0-100 and round to one decimal; never rescale (a value of 1 means 1%, not
72+ * the fraction 1.0 → 100%).
73+ */
74+ function normalizeClaudePercent ( value : number | undefined ) : number | undefined {
7075 if ( value === undefined || ! Number . isFinite ( value ) || value < 0 ) return undefined ;
7176 return Math . min ( 100 , Math . max ( 0 , Math . round ( value * 10 ) / 10 ) ) ;
7277}
@@ -80,7 +85,7 @@ export function parseClaudeUsage(
8085 const data = ( body ?? { } ) as ClaudeUsageResponse ;
8186 const windows : UsageWindow [ ] = [ ] ;
8287 for ( const w of [
83- windowFrom ( "session-5h" , "Session (5h)" , data . five_hour , normalizeClaudeSessionPercent ) ,
88+ windowFrom ( "session-5h" , "Session (5h)" , data . five_hour ) ,
8489 windowFrom ( "weekly" , "Weekly" , data . seven_day ) ,
8590 windowFrom ( "weekly-opus" , "Weekly (Opus)" , data . seven_day_opus ) ,
8691 windowFrom ( "weekly-sonnet" , "Weekly (Sonnet)" , data . seven_day_sonnet ) ,
@@ -95,7 +100,7 @@ export function parseClaudeUsage(
95100 const usedCents = data . extra_usage . used_credits ;
96101 const limitCents = data . extra_usage . monthly_limit ;
97102 const pct =
98- normalizePercent ( data . extra_usage . utilization ) ??
103+ normalizeClaudePercent ( data . extra_usage . utilization ) ??
99104 ( usedCents !== undefined && limitCents ? Math . min ( 100 , ( usedCents / limitCents ) * 100 ) : 0 ) ;
100105 windows . push ( {
101106 id : "extra-usage" ,
0 commit comments