Skip to content

Commit 5cb56ea

Browse files
committed
fix(claude): correct utilization inversion and propagate remainingPercentage
- Fix createQuotaObject: utilization is percentage USED, not remaining - Add optional chaining to window access in createQuotaObject - Use typeof object guards for five_hour/seven_day instead of !== undefined - Use nullish coalescing for extra_usage - Propagate remainingPercentage in parseQuotaData claude case
1 parent f88f968 commit 5cb56ea

File tree

2 files changed

+10
-7
lines changed
  • open-sse/services
  • src/app/(dashboard)/dashboard/usage/components/ProviderLimits

2 files changed

+10
-7
lines changed

open-sse/services/usage.ts

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -443,23 +443,25 @@ async function getClaudeUsage(accessToken) {
443443
const data = await oauthResponse.json();
444444
const quotas: Record<string, any> = {};
445445

446-
// utilization = percentage remaining, not used
446+
// utilization = percentage USED (e.g., 22 means 22% used, 78% remaining)
447447
const createQuotaObject = (window: any) => {
448-
const remaining = window.utilization ?? 0;
448+
const used = window?.utilization ?? 0;
449+
const remaining = 100 - used;
449450
return {
450-
used: 100 - remaining,
451+
used,
451452
total: 100,
452-
resetAt: parseResetTime(window.resets_at) || null,
453+
remaining,
454+
resetAt: parseResetTime(window?.resets_at),
453455
remainingPercentage: remaining,
454456
unlimited: false,
455457
};
456458
};
457459

458-
if (data.five_hour !== undefined) {
460+
if (data.five_hour && typeof data.five_hour === "object") {
459461
quotas["session (5h)"] = createQuotaObject(data.five_hour);
460462
}
461463

462-
if (data.seven_day !== undefined) {
464+
if (data.seven_day && typeof data.seven_day === "object") {
463465
quotas["weekly (7d)"] = createQuotaObject(data.seven_day);
464466
}
465467

@@ -479,7 +481,7 @@ async function getClaudeUsage(accessToken) {
479481
return {
480482
plan: "Claude Code",
481483
quotas,
482-
extraUsage: data.extra_usage || null,
484+
extraUsage: data.extra_usage ?? null,
483485
};
484486
}
485487

src/app/(dashboard)/dashboard/usage/components/ProviderLimits/utils.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,7 @@ export function parseQuotaData(provider, data) {
159159
used: quota.used || 0,
160160
total: quota.total || 0,
161161
resetAt: quota.resetAt || null,
162+
remainingPercentage: quota.remainingPercentage,
162163
});
163164
});
164165
}

0 commit comments

Comments
 (0)