Skip to content

normalizePercent misreads API utilization value of 1.0 as 100% instead of 1% #11

Description

@taemire

Bug Description

claude-nonstop status incorrectly displays 7-day utilization as 100% when actual usage is 1%.

Root Cause

In lib/usage.js, normalizePercent uses value <= 1.0 to detect fraction format:

// Current (buggy)
export function normalizePercent(value) {
  if (typeof value !== 'number' || isNaN(value)) return 0;
  if (value >= 0 && value <= 1.0) {
    return Math.round(value * 100);  // ← fires when value = 1.0
  }
  return Math.round(value);
}

The Anthropic OAuth usage API returns percentage scale (0–100), not fractions. When the API returns { "seven_day": { "utilization": 1.0 } } (meaning 1%), the condition 1.0 <= 1.0 fires and multiplies by 100, yielding 100% instead of 1%.

Verified Raw API Response

{
  "five_hour":  { "utilization": 8.0 },
  "seven_day":  { "utilization": 1.0 }
}
  • five_hour: 8.0 → correctly bypasses <= 1.0 branch → renders 8%
  • seven_day: 1.0 → incorrectly hits the branch → renders 100%

Fix

export function normalizePercent(value) {
  if (typeof value !== 'number' || isNaN(value)) return 0;
  return Math.min(100, Math.round(value));
}

The comment at the top of usage.js already states "Returns five_hour and seven_day utilization percentages (0-100)" — the fraction-detection branch contradicts this contract.

Environment

  • claude-nonstop v0.2.0
  • macOS 15.4, Node.js v25.8.2
  • Reproduces on any account where 7-day utilization is exactly 1.0

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions