Expand description
ai-usagebar library — shared core for the Waybar widget and TUI binaries.
The crate is organized by concern, not by binary:
- low-level primitives (
cache,countdown,pacing,pango,theme) - the vendor abstraction (
vendor,vendors::*,usage) - bin-specific composition (
widget,tui) which lives next to its binary
The binaries (ai-usagebar, ai-usagebar-tui, and on Windows
ai-usagebar-tray) are thin: they parse CLI args, instantiate vendors,
and hand off to a renderer in this crate.
Re-exports§
Modules§
- account
- Administrative commands for named Claude accounts.
- active
- Active-vendor state file. Set by
--cycle-next/--cycle-prev(which Waybar’son-scroll-up/on-scroll-downinvoke), read by the widget on every tick. The TUI does NOT consult this — it has its own tab state. - anthropic
- Anthropic vendor — OAuth-based plan usage via the undocumented
https://api.anthropic.com/api/oauth/usageendpoint. - anthropic_
api - Anthropic Admin API vendor — month-to-date spend from
/v1/organizations/cost_reportover a Console Admin key (distinct from the inference key and from the Claude Code OAuth login). The remaining prepaid credit balance is Console-only (no API), so this reports spend. - antigravity
- Google Antigravity vendor — quota tracking via the local language server.
- cache
- Per-vendor on-disk cache with atomic writes, TTL checks, and inter-process locking.
- catalog
- The one answer to “which providers exist, how does each authenticate, and is this one switched on and credentialed on this machine”.
- claude_
desktop - Switching which Claude account the Claude Desktop app is signed in as, carrying local history along so the account you land on shows the union of everything rather than only its own conversations.
- commandcode
- Command Code (commandcode.ai) subscription usage integration.
- config
- Config file at
~/.config/ai-usagebar/config.toml. - context
- Best-effort, local-only Claude Code context-window discovery.
- copilot
- GitHub Copilot quota via the private endpoint used by VS Code.
- countdown
- Human-readable countdown between two instants.
- cursor
- Cursor — premium-request quota read from the local Cursor IDE session
token (
state.vscdb) against the undocumentedcursor.com/api/usageendpoint the Cursor dashboard itself calls. Seedb.rsfor the token source andfetch.rs/types.rsfor the wire call and schema. - custom
- User-defined HTTP providers: a URL, a static token, and JSON pointers.
- deepseek
- detect
- Local credential detection — the seed for auto-enabling vendors.
- display
- Sanitization for text that crosses an untrusted data boundary into a UI.
- error
- Shared error type. Vendors and renderers convert their failures into
AppErrorso the widget shell can decide whether to retry, fall back to cache, show ⚠, or show “Loading…”. - format
{placeholder}substitution for--formatand--tooltip-format.- grok
- xAI (Grok) vendor — prepaid credit balance from the Management API
(
management-api.x.ai) over a management key (distinct from the inference key), optionally auto-resolving the team id. - grokbot
- Grok Bot — the Grok Bot desktop app’s weekly included-usage pool, reported
by
aiserver.v1.DashboardService/GetSandUsageStatusover Connect-RPC. Separate from[grok](Management API prepaid dollars) and[supergrok](the Grok Build subscription). - jwt
- Read the claims out of a JWT without verifying it.
- kilo
- Kilo Code vendor — credit balance from
/api/profile/balanceover an API key (an undocumented endpoint used by the Kilo Code extension; seetypes.rs). - kimi
- Kimi — weekly subscription quota + 5h rolling window from
/coding/v1/usages. - kiro
- Kiro CLI — credit-based quota read from kiro-cli’s own cached AWS SSO OIDC
session (
db.rs) againstAmazonCodeWhispererService.GetUsageLimits, the same call kiro-cli’s own/usageslash command makes. Seeoauth.rsfor the (documented) token-refresh flow andfetch.rs/types.rsfor the wire call and schema. - minimax
- MiniMax Token Plan vendor — subscription quota from
/v1/token_plan/remainsover an API key. The key is instance-scoped:api.minimax.io(global) andapi.minimaxi.com(CN) reject each other’s keys, so the region is configured rather than probed. - moonshot
- Moonshot / Kimi vendor — account balance from
/v1/users/me/balanceover an API key. USD onapi.moonshot.ai, CNY onapi.moonshot.cn. - nous
- Nous Research OAuth and subscription usage integration.
- novita
- Novita AI vendor — account credit balance from
/openapi/v1/billing/balance/detailover an API key. - ollama
- Ollama Cloud (
ollama.com) — the cloud quota service behind the “Cloud usage” section ofollama.com/settingsand the session/weekly limits enforced by remote models (*-cloudtags) in the official CLI. - openai
- OpenAI vendor — Codex OAuth via
~/.codex/auth.json+ the undocumentedchatgpt.com/backend-api/wham/usageendpoint. Reference:~/Projects/codexbar/codexbarby the same author as claudebar. - opencode_
go - OpenCode Go subscription quota integration.
- openrouter
- OpenRouter vendor —
/api/v1/creditsand/api/v1/keyover an API key. - outcome
- What a vendor fetch produced: a snapshot, plus how much to trust it.
- pacing
- Pacing math — encodes claudebar’s
calc_pacing(claudebar:279-321) andpace_color_for(claudebar:212-219) as pure functions. - pango
- Pango-markup rendering helpers shared by the widget bar text and tooltip.
- process
- Child-process conventions shared by every vendor that shells out.
- report
ai-usagebar usage— quota and time-to-reset for everything in the config, in one pass.- safe_
storage - Electron/Chromium safeStorage on macOS — the encryption Claude Desktop
uses for the OAuth token blobs in its
config.json(oauth:tokenCacheV2). - serde_
helpers - Deserializers shared by the OAuth credential readers.
- supergrok
- SuperGrok (xAI subscription OAuth) usage through the official Grok Build CLI’s billing surface.
- theme
- Color palette resolution.
- tooltip
- Pango-bordered tooltip primitives shared by every vendor renderer.
- tray
- Windows system-tray popover over
usage --json. - tui
- TUI binary support — ratatui app with one tab per enabled vendor.
- update
- Self-update support for the Windows tray: release discovery, asset selection, checksum verification, and the in-place binary swap.
- usage
- Canonical in-memory representation of “how much have I used my plan”.
- vendor
- Shared vendor IDs and renderer/fetcher structs used by the widget and TUI.
- waybar
- Waybar JSON output:
{text, tooltip, class}. - widget
- Widget binary support: CLI parsing, per-vendor rendering, the always-exit-0
wrapper, and the local-testing renderers (
--pretty,--watch,--json). - zai
- Z.AI / BigModel vendor — undocumented
/api/monitor/usage/quota/limit. Auth header isAuthorization: <KEY>with NOBearerprefix.