Skip to content

feat: add Claude plan usage stat card to Command Center#19

Open
sj-unit72 wants to merge 1 commit intoMeisnerDan:mainfrom
sj-unit72:feat/claude-plan-usage-card
Open

feat: add Claude plan usage stat card to Command Center#19
sj-unit72 wants to merge 1 commit intoMeisnerDan:mainfrom
sj-unit72:feat/claude-plan-usage-card

Conversation

@sj-unit72
Copy link
Contributor

Summary

Adds a Claude Plan Usage card to the Command Center stats bar, showing your 5-hour session and 7-day window utilization directly on the dashboard — no external app needed.

  • Uses Anthropic's OAuth PKCE flow (client_id: 9d1c250a-e61b-44d9-88ed-5944d1962f5e) to authenticate
  • Fetches live usage from https://api.anthropic.com/api/oauth/usage with anthropic-beta: oauth-2025-04-20
  • Progress bars turn orange above 80% utilization
  • Reset timers show when each limit resets
  • 30-minute sessionStorage cache prevents rate limiting on page navigation
  • 429 responses show "Rate limited · resets in Xm" instead of an error
  • Sign-in flow is built into the card — click to connect, paste the OAuth code, done

New files

  • src/app/api/claude-auth/route.ts — OAuth PKCE (start / exchange / signout)
  • src/app/api/claude-usage/route.ts — proxies the Anthropic usage endpoint
  • src/lib/claude-token.ts — shared file-based token loader

Changes

  • src/app/page.tsx — 5th stat card, grid updated to lg:grid-cols-5, brain dump card gets h-full

Test plan

  • Visit Command Center — 5th card shows "Click to connect"
  • Click card → opens Claude.ai OAuth in new tab
  • Paste the code#state string → card shows usage bars
  • Navigate away and back → cached data loads instantly (no new API call)
  • Click refresh icon → forces fresh fetch
  • Click sign-out icon → card resets to "Click to connect"
  • Let usage exceed 80% → bars turn orange

🤖 Generated with Claude Code

Shows 5-hour session and 7-day window utilization directly in the
dashboard stats bar, with OAuth PKCE sign-in built into the card.

- New `src/app/api/claude-auth/route.ts` — OAuth PKCE flow (start /
  exchange / signout), stores token in data/claude-oauth-token
- New `src/app/api/claude-usage/route.ts` — fetches from
  https://api.anthropic.com/api/oauth/usage with anthropic-beta header
- New `src/lib/claude-token.ts` — shared token loader used by both routes
- Command Center stats bar: 5th card shows progress bars for 5h session
  and 7d window usage; turns orange above 80%; click to connect when
  unauthenticated; inline code-paste flow for OAuth exchange
- 30-minute sessionStorage cache to avoid rate limiting (429 handled
  gracefully with backoff message instead of error)
- Brain dump card gets h-full so it stretches correctly alongside the
  taller Claude plan card

Co-Authored-By: Serge Jespers <serge@unit72.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant