Skip to content

fix: stop rescaling Claude utilization below 1% to 100% - #274

Open
yozu wants to merge 1 commit into
nesszer:mainfrom
yozu:fix/claude-utilization-percent-unit
Open

fix: stop rescaling Claude utilization below 1% to 100%#274
yozu wants to merge 1 commit into
nesszer:mainfrom
yozu:fix/claude-utilization-percent-unit

Conversation

@yozu

@yozu yozu commented Aug 10, 2026

Copy link
Copy Markdown

Problem

A Claude session at 1% is displayed as 100% used, with the red "used up" state, while the Claude settings page reports 1% for the same window.

normalize_utilization (duplicated in the OAuth and web API fetchers) treats any utilization value in (0, 1] as a fraction and multiplies it by 100:

fn normalize_utilization(utilization: f64) -> f64 {
    if utilization > 0.0 && utilization <= 1.0 {
        utilization * 100.0
    } else {
        utilization
    }
}

The API already reports these values in percent units, so every window at or below 1% is inflated by 100x. Values above 1 are unaffected, which is why the bug only shows up on freshly reset windows.

Why percent is the right unit

  • scoped_weekly::weekly_all_window already consumes the sibling limits[].percent field as-is, without rescaling.
  • The payload captured in the existing weekly_all_limit_wins_over_stale_seven_day_utilization test carries "seven_day": {"utilization": 1.0} next to "kind": "weekly_all", "percent": 1.0 — the same window, the same value, in both fields.
  • That test already asserts the weekly window must be 1%, not 100%. The limits[] path satisfied it; to_rate_window did not.

Change

Remove normalize_utilization from both fetchers and use utilization directly. This covers the five-hour session, seven-day, model-scoped (Opus/Sonnet), OAuth apps and Daily Routines windows.

Tests

  • Renamed converts_fractional_utilization_to_percent to keeps_sub_one_utilization_in_percent_units in both modules and flipped the expectation (0.23 stays 0.23).
  • Added one_percent_session_is_not_reported_as_full_quota covering the reported symptom directly.
  • Updated parses_current_snake_case_oauth_usage_response, which encoded the old behaviour (1.0 -> 100.0, 0.14 -> 14.0).
  • cargo test: 1207 passed, 0 failed. cargo clippy --all-targets: no new warnings.

View with [code]smith Autofix with [code]smith
Need help on this PR? Tag @codesmith-bot with what you need. Autofix is disabled.

`normalize_utilization` treated any `utilization` value in (0, 1] as a
fraction and multiplied it by 100. The Claude usage API already reports
these values in percent units, so a session at 1% was rendered as a fully
consumed quota with a red "used up" state, while the Claude settings page
showed 1%.

The sibling `limits[].percent` field has always been consumed as-is by
`scoped_weekly::weekly_all_window`, and issue payloads carry the same
value in both fields (`seven_day.utilization: 1.0` alongside
`weekly_all.percent: 1.0`), confirming the unit.

Drop the rescaling in both the OAuth and web API fetchers so five-hour,
seven-day, model-scoped and routines windows all report percent directly.
@Finesssee

Copy link
Copy Markdown
Collaborator

Thanks for the PR, I will review this ASAP.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants