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 two binaries (ai-usagebar and ai-usagebar-tui) 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.
- 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.
- config
- Config file at
~/.config/ai-usagebar/config.toml. - context
- Best-effort, local-only Claude Code context-window discovery.
- 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. - deepseek
- 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. - 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
- 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. - novita
- Novita AI vendor — account credit balance from
/openapi/v1/billing/balance/detailover an API key. - 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. - openrouter
- OpenRouter vendor —
/api/v1/creditsand/api/v1/keyover an API key. - 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.
- 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). - theme
- Color palette resolution.
- tooltip
- Pango-bordered tooltip primitives shared by every vendor renderer.
- tui
- TUI binary support — ratatui app with one tab per enabled vendor.
- 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.