Skip to content

feat(devtools/claude-usage): Anthropic OAuth usage API client + mapping #202

Description

@jaeyeom

Parent

Part of #199 — port claude-usage into devtools/.

Depends on credential resolution (#199 child: OAuth credentials issue).

Problem

Need a small client for Anthropic’s OAuth usage endpoint that powers the 5-hour and 7-day windows, without importing claude-hud’s Node module.

API notes (as used by claude-hud)

  • Endpoint: GET https://api.anthropic.com/api/oauth/usage (confirm path/headers against current Claude Code behavior while implementing)
  • Auth: OAuth bearer token from Claude Code credentials
  • User-Agent used by claude-hud: claude-code/2.1 (match or document divergence)
  • Response includes roughly:
    • five_hour.utilization, five_hour.resets_at
    • seven_day.utilization, seven_day.resets_at
  • Map utilization → percent fields fiveHour / sevenDay
  • Plan name from subscription type / fallback (claude-hud has getUsagePlanNameFallback)

Scope

  • internal/usage HTTP client with injectable transport for tests
  • Map API response → stable output struct used by the CLI
  • Sensible timeouts (claude-hud default ~15s)
  • Optional short-lived cache (nice-to-have; claude-hud uses ~5 min file cache for HUD — CLI may skip or use a simpler in-process/optional cache)
  • Handle 401/403/429 and network errors with clear messages
  • Respect “custom base URL ⇒ usage N/A” behavior if applicable

Acceptance criteria

  • Successful call produces data matching the CLI JSON contract
  • Table tests with recorded/fake HTTP responses (no network in unit tests)
  • Error paths covered (unauthorized, rate limit, timeout, empty body)
  • No dependency on ~/.claude/plugins/cache/**/claude-hud/**

Out of scope

  • HUD rendering / statusline integration
  • Mutating credentials or performing OAuth login

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions