Feature Request: Expose subscription usage data via local file or API
Summary
Provide a way for users and tools to programmatically access Claude Code Pro/Max subscription usage data (session and weekly quota percentages, reset times).
Problem
Currently, the only way to check subscription usage is via the /usage command, which:
- Displays data in the terminal but doesn't expose it programmatically
- Fetches from Anthropic's servers but doesn't cache locally
- Cannot be invoked by external tools or scripts
This makes it impossible to build companion tools that help users:
- Monitor usage in real-time
- Get alerts before hitting limits
- Track usage patterns over time
- Plan sessions efficiently
Proposed Solution
One or more of the following:
Option A: Local cache file
Write usage data to a local file (e.g., ~/.claude/usage-cache.json) after each /usage call or periodically:
{
"session": {
"percentUsed": 59,
"resetIn": "2h 47m",
"resetAt": "2026-01-30T15:30:00Z"
},
"weekly": {
"percentUsed": 29,
"resetDay": "Wednesday",
"resetAt": "2026-02-05T11:29:00Z"
},
"updatedAt": "2026-01-30T12:43:00Z"
}
Option B: Machine-readable /usage output
Add a flag like /usage --json that outputs structured data instead of formatted text.
Option C: Include in stats-cache.json
Extend the existing ~/.claude/stats-cache.json to include current quota status.
Use Cases
- CLI companion tools - Build dashboards showing real-time usage
- Alerts - Get notified before hitting session/weekly limits
- Planning - Tools that help distribute usage across the week
- Automation - Scripts that pause work when approaching limits
Current Workaround
Users must manually read /usage output and input numbers into external tools - this is error-prone and tedious.
Additional Context
The API already returns rate limit headers (anthropic-ratelimit-*) for per-minute limits. Extending this pattern to subscription quotas would be consistent and helpful.
Related: The existing stats-cache.json already tracks token usage but lacks quota context.
11 Comments
Found 3 possible duplicate issues:
This issue will be automatically closed as a duplicate in 3 days.
🤖 Generated with Claude Code
Strong +1 for this feature request.
I maintain CodexBar, a macOS menu bar app that displays Claude Code usage. Currently, we face a significant UX problem that this feature would solve.
The Problem
On macOS, Claude Code stores OAuth credentials in the Keychain. Third-party apps like CodexBar need these credentials to fetch usage data from the API. However:
~/.claude/.credentials.json(only Linux does)See related issue #19456 which documents the keychain ACL problem.
Why Usage Cache Solves This
If Claude Code wrote usage data to a cache file:
This is the cleanest architectural solution because:
Proposed Cache Location
Minimal Viable Schema
Implementation Suggestion
Write/update the cache file whenever:
/usagecommandEven just option 1 would be valuable - users could run
/usageoccasionally and third-party tools would read the cached data.Affected Third-Party Tools
Would love to see this prioritized given the current keychain UX issues on macOS.
+1 — this shouldn't have been marked as a duplicate. The core ask (expose subscription usage programmatically) is distinct from generic "analytics" requests. The data is already fetched for
/usage— caching it locally or piping it into the statusline hook would be a small implementation with huge user impact. 8+ open issues requesting the same thing speaks for itself.+1 for this one. Or add ability to fetch that data via API
+1 - would also love to see this available to the data provided to the statusline tool - would love to track my session usage in my status line.
this script works as a status line which includes quota data: https://github.com/slopware/claude-quota
thanks - I actually stole that logic and am using it right now - this will do for now until anthropic implements an official solution.
<img width="552" height="165" alt="Image" src="https://github.com/user-attachments/assets/3240f460-2fa6-4fbf-bd86-093bb36eb43e" />
+1 — closed my duplicate #33215 in favor of this one.
Adding two desktop app / Cowork-specific angles not yet covered here:
1. Always-visible usage indicator in the menu bar icon
The Claude menu bar icon could visually represent usage as a fill level (like the macOS battery icon) — empty at 0%, full at 100%, with color shift (green → yellow → red). Tooltip on hover: "Session: 72% | Weekly: 45%". This gives at-a-glance awareness without opening the app.
2. MCP tool access for Cowork mode
In Cowork mode, Claude runs with MCP tools (Desktop Commander, Chrome, Gmail, GCal, scheduled tasks). Claude itself has zero visibility into its own token consumption or quota. Exposing usage via an internal MCP tool or query would let Claude:
Until native usage data is exposed, a PostToolUse hook can track session-level usage and write it to a local file:
This creates a local JSONL log at
~/.claude/usage.jsonlthat you can query withjq,grep, or any script. Session summaries are saved to~/.claude/usage-reports/. Not actual subscription usage, but gives you complete visibility into tool-level activity.this is the gap between local-log tooling and server-truth quota, and it's been bugging me for months. ccusage and the monitor projects parse ~/.claude/projects/*.jsonl, which gives you token counts but not the rolling 5h or weekly window Anthropic actually enforces. /usage hits an internal endpoint (the same one claude.ai/settings/usage renders) and that's the only number that matches what gets you rate-limited. option B (--json) is the cleanest fix because the data already exists server-side, the CLI just needs to stop pretty-printing and start emitting structured output. without it everyone ends up scraping the terminal.
Here's yet another workaround to this https://github.com/hiinaspace/claude-quota . it runs an empty claude code session in screen, types in
/usage, scrolls down and parses the bars into JSON on stdout. takes a bit to run since claude code startup is slow (~5 seconds) and is fragile to changes, but works in a pinch.