Feature request: `claude usage --json` for programmatic access to rate limit data

Resolved 💬 3 comments Opened Mar 30, 2026 by SaberMage Closed Apr 2, 2026

Feature Request

Expose the data shown by the /usage TUI dialog as a CLI command with machine-readable output.

Proposed Command

claude usage --json

Example Output

{
  "current_session": {
    "used_percent": 93,
    "resets_at": "2026-03-29T21:59:00-07:00"
  },
  "current_week_all_models": {
    "used_percent": 72,
    "resets_at": "2026-03-31T23:00:00-07:00"
  },
  "current_week_sonnet": {
    "used_percent": 14,
    "resets_at": "2026-04-03T01:00:00-07:00"
  },
  "extra_usage": {
    "used_percent": 87,
    "spent_usd": 26.16,
    "limit_usd": 30.00,
    "resets_at": "2026-04-01T00:00:00-07:00"
  }
}

Motivation

The /usage dialog shows valuable rate limit and billing data, but it's only available as an interactive TUI component. This makes it impossible for:

  • Agents/subagents to monitor usage and make cost-aware decisions (e.g., switching to Haiku when session limit is high, pausing non-critical work near limits)
  • Statusline hooks to display usage alongside context window data
  • CI/automation to gate expensive operations based on remaining budget
  • Users scripting workflows across multiple sessions

Currently there's no programmatic way to access this data — no CLI flag, no API endpoint, and the TUI output can't be captured from a piped/non-interactive session.

Alternatives Considered

  • Piping /usage via stdin: Doesn't work — /usage is a built-in TUI command that only renders interactively
  • Debug mode: --debug doesn't capture the usage API calls
  • Spawning a child claude process: Would require parsing ANSI escape codes from TUI output — extremely fragile
  • Screenshot + OCR: Works but is absurd for structured data that already exists internally

Suggested Implementation

Add usage as a CLI subcommand (alongside auth, doctor, mcp, etc.) that calls the same internal API endpoint the /usage dialog uses, and outputs JSON to stdout.

View original on GitHub ↗

This issue has 3 comments on GitHub. Read the full discussion on GitHub ↗