claude-code - 💡(How to fix) Fix Expose usage/quota data via CLI and hooks [1 comments, 2 participants]

Official PRs (…)
ON THIS PAGE

Recommended Tools

×6

Utilities matched from this issue’s tags and category — try them while you read without losing context.

GitHub issue graph ai analysis

Paste a GitHub issue URL. We fetch that issue, discover linked issues from bodies/comments/timeline, collect linked pull requests, and produce a structured English report.

The report is written in English Markdown for sharing and archival.

Helpful · Quick feedback

Loading…
GitHub stats
anthropics/claude-code#48660Fetched 2026-04-16 06:54:25
View on GitHub
Comments
1
Participants
2
Timeline
6
Reactions
0
Author
Timeline (top)
labeled ×5commented ×1

There's no way to programmatically access usage quota data (daily/weekly/plan limits and current consumption) from outside the interactive Claude Code session. This makes it impossible to build status lines, hooks, or monitoring that shows usage percentages.

Root Cause

There's no way to programmatically access usage quota data (daily/weekly/plan limits and current consumption) from outside the interactive Claude Code session. This makes it impossible to build status lines, hooks, or monitoring that shows usage percentages.

RAW_BUFFERClick to expand / collapse

Summary

There's no way to programmatically access usage quota data (daily/weekly/plan limits and current consumption) from outside the interactive Claude Code session. This makes it impossible to build status lines, hooks, or monitoring that shows usage percentages.

What I tried

  • Status line (statusLine in settings.json) — runs a shell command, but there's no CLI flag or local file with quota data to read
  • Stop hook with curl — the OAuth token from keychain (claude-code-oauth) gets blocked by Cloudflare's challenge page on claude.ai/api/organizations/{org}/usage
  • Local files~/.claude/stats-cache.json has historical token counts but no quota limits or current consumption percentages

What would be useful

Any of these would unblock it:

  1. claude usage --json — CLI command that outputs current quota state as JSON (daily/weekly/plan usage and limits, percentages)
  2. Environment variable — e.g. $CLAUDE_USAGE_JSON injected into hook contexts
  3. Local file — Claude Code writes ~/.claude/usage.json with current quota state, updated after each API call
  4. Response headers — If x-ratelimit-* headers are available, expose them to hooks via stdin JSON

Use case

As a Max plan user, I want an unobtrusive status line showing percentage usage against daily, weekly, and plan caps — updated after each query. This would help me pace usage and avoid surprises. A Stop hook that reads a local file or calls claude usage --json would be ~100ms overhead per query.

Environment

  • Claude Code on macOS
  • Max plan (claude.ai billing, not Console)
  • OAuth authentication via keychain

extent analysis

TL;DR

Implementing a claude usage --json CLI command or exposing quota data through a local file like ~/.claude/usage.json would provide a straightforward way to access usage quota data programmatically.

Guidance

  • Investigate the feasibility of adding a --json flag to the claude usage command to output quota data in a machine-readable format.
  • Consider modifying the Claude Code application to write the current quota state to a local file, such as ~/.claude/usage.json, after each API call, allowing for easy access to this data.
  • Evaluate the possibility of exposing quota data through environment variables, such as $CLAUDE_USAGE_JSON, that can be injected into hook contexts.
  • Look into whether the x-ratelimit-* headers are available and can be exposed to hooks via stdin JSON for an alternative solution.

Example

No specific code example is provided due to the lack of explicit API or function details in the issue.

Notes

The solution requires modifications to the Claude Code application or its API to provide programmatic access to usage quota data. The exact implementation details may vary based on the application's internal architecture and existing APIs.

Recommendation

Apply a workaround by implementing a claude usage --json CLI command or exposing quota data through a local file, as these approaches seem to be the most direct and least invasive solutions to access usage quota data programmatically.

Vote matrix · Quick signals

Works
Did the solution work? Tap to confirm.
Easy Fix
Was it a quick fix?
Time Saver
Did it save you time?
Blocking
Was it severely blocking?
Common Issue
Are others likely hitting this too?
Flaky / Intermittent
Is it intermittent?
Verified / Reproducible
Can you reproduce it reliably?
Loading…

Still need to ship something?

×6

Another batch ranked right after the header list — different links, same matching logic.

Back to top recommendations

TRENDING