# AI Usage CLI `usagestat` is a scriptable command line interface for discovering provider plugins, probing live usage, checking provider status pages, exporting usage snapshots, and managing backend config/cache state. This reference describes the current source checkout. See the [installation guide](installation.md) for published packages and setup. The CLI is intended to grow into a superset of CodexBar's CLI capabilities. `usage`, `status`, `cost`, `config`, and `cache` mirror CodexBar's command families where the backend already has equivalent data. Use `usagestat capabilities --json` to discover implemented platform features, or `usagestat doctor --json` to diagnose configuration, resources, helper discovery and native service health without probing credentials or changing settings. See the [capabilities and diagnostics contract](capabilities.md). Future provider UX work should consider standardizing common usage-window labels and ordering across plugins. CodexBar tracks this as a low-priority polish item so providers with comparable limits are easier to scan side by side, while still allowing provider-specific labels for balances, credits, and model-specific quota pools. ## Running The CLI For packaged installs, bundled provider resources, upgrades, and removal, start with the [installation guide](installation.md). The commands below are useful when developing from a checkout. From a checkout, run the binary through Cargo: ```bash cargo run -p usagestat-cli -- list ``` For repeated use, build or install the CLI and then run `usagestat` directly: ```bash cargo build -p usagestat-cli ./target/debug/usagestat list ``` ```bash cargo install --path crates/ai-usage-cli usagestat list ``` That `cargo install` command installs only the CLI. Use the [complete source installation](installation.md#from-source) or a dev installer to install the daemon and plugins as well. When running through Cargo, everything after `--` is passed to `usagestat`. ## Optional background daemon On Linux with a systemd user session, install or build both binaries to enable automatic startup at login: ```bash cargo build -p usagestat-cli -p usagestat-daemon ./target/debug/usagestat daemon enable ./target/debug/usagestat daemon status ./target/debug/usagestat daemon disable ``` `enable` starts the daemon now and registers the native per-user login service: systemd on Linux, a LaunchAgent on macOS, or an interactive-user scheduled task on Windows. Native desktop session qualification remains pending. The dashboard at `http://127.0.0.1:6736/dashboard` and native API serve all enabled providers. Startup checks the daemon's `/health` endpoint. Repeating `enable` restarts with the selected settings and remembers the last T3 mode. `disable` stops the daemon and turns autostart off, preserving that mode and its key. `status` supports `--json`. Regular CLI usage does not enable or start the service. `daemon unregister` stops and removes only the managed login registration. It retains the saved owner/binary/key paths, T3 mode, config, history and credentials for recovery or reinstallation. It does not remove the executable package or kill an independently started foreground daemon. Unmanaged service files/tasks are rejected before removal. Repeating it is safe after successful removal. Installers can discover this command through the `daemon.unregister` capability. `daemon stop` pauses an already registered daemon; `daemon start` starts it again. Both preserve login startup. `daemon autostart on|off` changes login startup while preserving whether the daemon is running. These commands require an existing managed registration and retain T3 mode, key paths, ownership and provider settings. Installers can discover this support through `daemon.independentControls` and restore `running` and `autostart` from `daemon status --json` independently after an upgrade or rollback. `enable` and `disable` retain their combined behavior. `daemon relocate [--binary PATH]` updates a registered installation when a package manager moves it to another retained version under the same owner. It replaces recognized bundled resource paths and preserves custom paths, provider environment, config/key locations, T3 mode and both running/login preferences. The new CLI and daemon versions must match. Keep the previous package until this command succeeds. The operation records a private recovery journal before changing service state; a failed launch restores the previous registration/settings and verifies its old backend version. `daemon recover` resumes recovery after interruption. Other daemon mutations refuse a pending relocation; status remains available. A changed external owner/settings record is preserved for manual recovery. Repeating a completed relocation is safe. This command relocates saved paths; the owning installer must handle executable replacement in place. See the [Homebrew upgrade procedure](macos-distribution.md). T3 compatibility is a separate opt-in: ```bash usagestat daemon t3 auto usagestat daemon enable usagestat daemon key usagestat daemon t3 off ``` `t3 auto` exposes the compatibility endpoint whenever the daemon runs and generates a private management key if missing. `t3 off` keeps the bridge disabled. `key` prints the key for T3 Code's Add hub dialog. These modes do not detect T3 or start the daemon themselves. They preserve the service's bind address, binary, config, plugin paths, and autostart setting. A running daemon restarts to apply a mode change; a stopped daemon stays stopped. Plain `enable` uses the last T3 mode, including after a full `disable`. The preference is stored in `daemon.json` in the [native config directory](platform-support.md#filesystem-and-profiles) (respecting overrides and the dev profile). You can set it before first enabling the daemon. T3 starts off by default; a retained key alone does not enable it. When T3 is off, startup neither creates nor reads that key. Managed services ignore `USAGESTAT_MANAGEMENT_KEY` in their environment so the saved mode controls the bridge. Older saved boolean settings migrate to `auto` or `off`. `daemon status` distinguishes the saved mode from local connection availability: ```text T3: auto · available T3: auto · unavailable (daemon stopped) T3: auto · unavailable (bridge not responding) T3: off ``` Availability requires an authenticated response from the local quota endpoint. JSON output exposes `t3Mode` (`auto` or `off`) and `t3Available` separately. The earlier shortcuts remain: `enable --t3` starts the daemon with mode `auto`, `disable --t3` selects `off`, and `toggle --t3` switches between the two modes. The daemon defaults to `127.0.0.1:6736`. Set `daemon enable --bind ADDRESS:PORT` or `--binary /path/to/usagestatd` when needed. Global `--config` and `--plugin-dir` options apply to the installed service, with their paths resolved at setup time. The dev installers include both binaries; use `usagestat-dev daemon enable` for the separate `usagestat-dev.service` and dev profile. See [T3 Code setup](t3-code.md) for connection details and current T3 limitations. ## Open the dashboard ```bash usagestat dashboard usagestat dashboard --url usagestat dashboard --json ``` `dashboard` opens the native usage dashboard in your default browser after checking that the daemon responds. It uses the managed service's bind address, or `127.0.0.1:6736` when no managed service is configured. Wildcard bind addresses resolve to loopback. Use `--bind ADDRESS:PORT` for a manually started daemon at another address. If the daemon is stopped, the command prints startup guidance. It does not enable autostart or change T3's mode. `--url` prints only the link, including while the daemon is stopped; `--json` emits `{"dashboardUrl":"..."}`. Both skip the browser and health check, so they work over SSH. The dev CLI resolves its own service settings with `usagestat-dev dashboard`. The source dashboard's **Settings** tab controls provider visibility, order, display names, summary quotas and appearance independently of UsageStat Bar. See [dashboard settings](dashboard-settings.md) for persistence and import/export. The existing published v2.0.0 archive predates this settings page. The dashboard's **History** tab shows saved daily token and cost trends across providers, including providers that are no longer enabled. Filter by provider, choose 7, 30, 90, or 365 days, month-to-date, all saved history, or custom dates, and group the chart by day, Monday-based week, or month. **Export selected CSV** downloads the daily rows for that provider and date range, regardless of chart grouping. Totals are compared with the immediately preceding period of the same length. Ranges use UTC calendar dates, include both endpoints, and include today's partial activity. Recorded-day counts show coverage; missing records are gaps, not recorded zero usage. A comparison is unavailable if either period has no records. An increase from zero is labeled without inventing a percentage. Daily reports are saved in `~/.local/share/usagestat/usage_daily.json` (or the equivalent XDG data directory) when supported providers read local usage logs. Run `usagestat usage` or keep the daemon running to collect available reports. Only providers with daily reports contribute to spend and token totals. Costs may be API-equivalent estimates, not subscription charges. `costKnown` and `tokensKnown` distinguish complete values from partial/unavailable readings. The dashboard shows `Unpriced`, `Unknown`, or a `+` suffix rather than treating unavailable pricing as a known zero; older reports without these flags keep their original interpretation. Quota-only providers retain their snapshot charts in the provider tab. Repeated polling snapshots are never added together to calculate daily spend or token totals. History stays on the daemon's machine; this view does not combine records from other servers. The Used/Remaining selector applies to quota meters, not token or spend history. History day breakdowns initially show 30 rows and can expand to the full selected period. Display preferences can be exported/imported as bounded JSON; credentials, API endpoints, and provider configuration are not exported. Additional read-only daemon endpoints: ```text GET /v1/history/daily// GET /v1/icons/ GET /metrics ``` History periods accept `month`, `all`, or a day count from 1 to 36600. Icons use resolved provider metadata (including custom overrides). Prometheus output includes provider health, quota ratios, and fetch/reset timestamps, without account names, credentials, or diagnostic messages in metric labels. ## Quick Start List discovered providers: ```bash usagestat list ``` List enabled/disabled state for specific providers: ```bash usagestat list claude codex ``` Check live status pages for specific providers: ```bash usagestat status claude codex ``` Probe every enabled provider: ```bash usagestat usage ``` Probe one provider: ```bash usagestat usage claude usagestat usage --provider claude ``` Claude's automatic source can also use fresh, account-verified Claude Code quota observations and a standalone no-prompt CLI fallback. See [Claude quota sources](claude-usage.md) for freshness, cooldown, and platform limitations. No T3 or status-line integration is required. Probe multiple providers: ```bash usagestat usage claude codex gemini ``` Emit JSON for scripts: ```bash usagestat --json usage claude ``` Save a history record while probing: ```bash usagestat usage claude --save ``` Export current live data as CSV: ```bash usagestat export --format csv ``` Export saved history: ```bash usagestat export --from-file ~/.local/share/usagestat/history.jsonl --format csv ``` Validate or dump config: ```bash usagestat config validate usagestat config dump ``` Import ChatGPT/OpenAI browser cookies for Codex web usage: ```bash usagestat auth import-cookies --provider codex --format json ``` ## Global Options Global options can be placed before or after the subcommand. ```text --json Print JSON when the command supports it. --json-only CodexBar-compatible alias for --json. --pretty Accepted; JSON is currently pretty-printed by default. --json-output Accepted CodexBar-compatible structured log flag. --log-level Accepted CodexBar-compatible log-level flag. -v, --verbose Accepted CodexBar-compatible verbose flag. --no-color Disable ANSI colors in text output. --plain Use plain text instead of tables. --config Read config from a custom TOML file. --plugin-dir Add a plugin discovery directory. May be repeated. --all Include disabled providers. -h, --help Show help. -V, --version Show version. ``` Examples: ```bash usagestat --config ./config.toml list usagestat --plugin-dir ./plugins --plugin-dir ~/usagestat-plugins list usagestat --all probe openrouter ``` ## Commands ### `usage` Runs provider plugins and prints live usage snapshots. ```bash usagestat usage [PROVIDER_IDS]... ``` If no provider IDs are supplied, `usage` runs every enabled provider. Each provider has its own timeout. The default timeout is 120 seconds. ```bash USAGESTAT_PROBE_TIMEOUT_SEC=30 usagestat usage claude ``` Options: ```text --save Append results to ~/.local/share/usagestat/history.jsonl. --status Fetch provider status-page state and include it with output. --provider Provider to query. Also accepts all enabled providers, or both. --format text|json Output format. --source Compatibility option: auto|web|cli|oauth|api|local. --web Alias for --source web. --account