fix: correct toPercent units and de-duplicate worker.ts/parsing.ts - #53
Merged
lacymorrow merged 1 commit intoAug 11, 2026
Merged
Conversation
toPercent() multiplied utilization by 100, assuming the Anthropic OAuth usage API returns a 0..1 fraction. It actually returns a whole percentage already (confirmed against the same response's own limits[].percent field), so any real usage >=1% was clamping straight to 100%. While fixing this, discovered worker.ts carries a full second copy of every parsing/formatting helper in parsing.ts (toPercent included) that it never imports, so parsing.ts's test coverage exercised dead code and the bug lived undetected in the copy actually running in production. Consolidated worker.ts onto parsing.ts's exports.
lacymorrow
approved these changes
Aug 11, 2026
lacymorrow
left a comment
Owner
There was a problem hiding this comment.
Verified the core claim against the live API before reading further. GET /api/oauth/usage on a real Max account just returned five_hour.utilization: 29.0 alongside limits[0].percent: 29, and seven_day.utilization: 5.0 next to percent: 5. So utilization is already a whole percentage and the old *100 was clamping any real usage to 100. Your read is right, and the regression note explaining how this reverses LAC-2004 is appreciated.
The worker.ts dedup is also correct: the removed local copies were drifting from parsing.ts already (the local toPercent had the same *100 bug baked in twice).
Approved the held CI run. Will merge once it goes green.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
toPercent()reports the wrong usage percentage against the real Anthropic OAuth usage API (GET /api/oauth/usage).It multiplies
utilizationby 100, assuming a0..1fraction — but the live API returnsutilizationas a whole percentage already (e.g.1.0means 1% used,31.0means 31% used). This was confirmed against the same response's ownlimits[].percentfield, which reports the identical value under an unambiguous name. With the* 100in place, any real, non-zero usage clamps straight to 100% — the dashboard, usage page, andget-usage/get-usage-summaryagent tools all report "100% used" for accounts that have barely touched their quota.This reverses
toPercent's previous fix (theLAC-2004regression tests it added), which was chasing the opposite problem — reportedutilization: 1.0displaying as 1% instead of 100% — under the wrong assumption about the API's units. Both bugs are real; the API's units just aren't what either fix assumed. The new regression test asserts against the values actually observed from a live low-usage account (1% / 31%), not synthetic 0..1 fractions.While tracking this down, found the actual root cause of why the bug shipped silently:
worker.tscarries a full second copy of every helper inparsing.ts—toPercent,parseAnthropicResponse,extractAccountEmail, the whole CLI-output parsing pipeline (stripAnsi,cleanTerminalText,parseClaudeCliUsageText, etc.) — and never imports fromparsing.ts(onlyfriendlyErrorMessagewas actually wired up).parsing.ts's own comment says these were "extracted from worker.ts so they can be unit-tested," but the extraction never got finished — the copy left behind inworker.tsis the one that actually runs, whileparsing.test.tsexercises the untouched copy inparsing.ts. Any future fix to aparsing.tsfunction (like this one) silently does nothing to production behavior unless the same edit is manually mirrored intoworker.ts.This PR fixes
toPercent()and removes the duplication soparsing.tsis the single source of truthworker.tsactually runs.How to test
npm install npm run typecheck npm run build npm testOr manually: connect a low-usage Claude account and check the dashboard widget / usage page report percentages that match
claude /usagein the CLI, not 100%.Checklist
npm run typecheckpassesnpm run buildproducesdist/manifest.js+dist/worker.js