feat: add API usage widgets (session, weekly, reset, context bar)#168
feat: add API usage widgets (session, weekly, reset, context bar)#168pcvelz wants to merge 1 commit intosirmalloc:mainfrom
Conversation
|
@pcvelz Thanks, I'll review this soon, travelling at the moment. How does this handle Windows and WSL? If they are unsupported, I'd like to still merge it, but with a system to gate it properly and have it only appear on supported OS's. |
|
@sirmalloc can this be merged? |
… reset, context bar) Resolved conflicts: keep both fork widgets (session-name, free-memory) and PR widgets (session-usage, weekly-usage, reset-timer, context-bar). Made-with: Cursor
|
Hi, this is quite a handy feature for Subscription users. Since the PR is still pending merge, would you mind adding a small custom feature that allows users to choose whether to hide or unhide the progress bar? For example, I like to keep the status line compact and only show the used percentage. |
e643ee6 to
b7dae7c
Compare
|
@sirmalloc I've updated this PR with Windows support, based on @zac15987's working Windows snippet on issue #94. I don't have access to a Windows machine myself, so I can't verify this with absolute certainty. That said, I'm fairly confident it works — I analyzed the differences between zac15987's working Windows script and our widget code, and the only deviation was The rest of the code was already platform-agnostic:
On Windows, credentials are read from The fix is also published as v2.1.8 in the fork. |
Add four new widgets that display Claude Code API usage data: - session-usage: 5-hour session utilization with progress bar - weekly-usage: 7-day utilization with progress bar - reset-timer: countdown to session reset - context-bar: context window usage with progress bar Fetches data from /api/oauth/usage using existing OAuth credentials (macOS Keychain + Linux file fallback). Includes 180s cache with 30s rate limiting to minimize API calls. Also enhances ContextPercentage widget to use context_window data from Claude Code's stdin JSON when available. Closes sirmalloc#94
b7dae7c to
07dd5d8
Compare
|
@pcvelz I've got a Windows machine I can test on. I'll dig into reviewing this today. |
Summary
Adds four new widgets that display Claude Code API usage data, closing #94:
context_windowdata from Claude Code stdin JSON)Also enhances the existing
ContextPercentagewidget to usecontext_windowdata when transcript-based token metrics aren't available.How it works
GET /api/oauth/usageusing existing OAuth credentials (macOS Keychain + Linux~/.claude/.credentials.jsonfallback)Files changed
src/widgets/ApiUsage.tsxsrc/widgets/index.tssrc/utils/widgets.tssrc/types/StatusJSON.tscontext_windowschema for Claude Code's context datasrc/widgets/ContextPercentage.tscontext_windowfrom stdin when availableContext
This was originally prototyped as a bash script and then implemented as native TypeScript widgets in a fork. This PR extracts just the widget code with no other changes.
Uses the same API approach as claude-pulse — same endpoint, same auth headers.
Test plan
bun run buildsucceedsbun testpasses[No credentials]gracefully when OAuth token is unavailable~/.cache/ccstatusline-api.jsonafter first API call~/.claude/.credentials.json