--- summary: "CodexBar CLI for fetching usage from the command line." read_when: - "You want to call CodexBar data from scripts or a terminal." - "Adding or modifying Commander-based CLI commands." - "Aligning menubar and CLI output/behavior." --- # CodexBar CLI A lightweight Commander-based CLI that mirrors the menu bar app’s provider fetchers and config file. Use it when you need usage numbers in scripts, CI, or dashboards without UI. ## Install - In the app: **Preferences → Advanced → Install CLI**. This symlinks `CodexBarCLI` to `/usr/local/bin/codexbar` and `/opt/homebrew/bin/codexbar`. - From the repo, after installing `CodexBar.app` in `/Applications`: `./bin/install-codexbar-cli.sh` (same symlink targets). - Manual: `ln -sf "/Applications/CodexBar.app/Contents/Helpers/CodexBarCLI" /usr/local/bin/codexbar`. ### Release tarball install (macOS/Linux) - Homebrew formula (Linux today): `brew install steipete/tap/codexbar`. - Download release tarballs from GitHub Releases: - macOS: `CodexBarCLI-v-macos-arm64.tar.gz`, `CodexBarCLI-v-macos-x86_64.tar.gz` - Linux (glibc): `CodexBarCLI-v-linux-aarch64.tar.gz`, `CodexBarCLI-v-linux-x86_64.tar.gz` - Linux (static musl): `CodexBarCLI-v-linux-musl-aarch64.tar.gz`, `CodexBarCLI-v-linux-musl-x86_64.tar.gz` - Extract and run `./codexbar` (symlink) or `./CodexBarCLI`. ``` tar -xzf CodexBarCLI-v0.17.0-macos-x86_64.tar.gz ./codexbar --version ./codexbar usage --format json --pretty ``` ## Build - `./Scripts/package_app.sh` (or `./Scripts/compile_and_run.sh`) bundles `CodexBarCLI` into `CodexBar.app/Contents/Helpers/CodexBarCLI`. - Standalone: `swift build -c release --product CodexBarCLI` (binary at `./.build/release/CodexBarCLI`). - Dependencies: Swift 6.2+, Commander package (`https://github.com/steipete/Commander`). ## Configuration CodexBar reads the resolved config file for provider settings, secrets, and ordering. New installs use `~/.config/codexbar/config.json`; absolute `XDG_CONFIG_HOME` paths and `CODEXBAR_CONFIG` are supported, and existing `~/.codexbar/config.json` installs keep using the legacy file when no XDG config exists. See `docs/configuration.md` for the schema. ## Command - `codexbar` defaults to the `usage` command. - `--format text|json` (default: text). - `codexbar cost` prints local token cost usage for Claude + Codex without web/CLI access. - `--format text|json` (default: text). - `--refresh` ignores cached scans. - `codexbar cards` prints a one-shot usage snapshot as a responsive terminal card grid. - Reuses the same provider, source, account, credits, and status flags as `codexbar usage`. - Account lines and plan badges are included in the card grid by default. - `--brief` renders a compact table (Provider / Usage / Reset) instead of the card grid. - Stdout is always rendered text; `--json-output` only affects stderr logs (no JSON card payload). - Failed providers are summarized in a footer (not rendered as error cards). - Honors `$COLUMNS` for layout; falls back to 80 columns. Use `--no-color` for plain output. - Kitty, Ghostty, WezTerm, and other truecolor terminals auto-enable enhanced gradients/outlines. - Force enhanced mode elsewhere with `CODEXBAR_CARDS_ENHANCED=1`. - Exit code is non-zero when any provider fetch fails. - `codexbar serve` starts a foreground localhost-only HTTP server for usage and cost JSON. - `--port ` defaults to `8080`. - `--refresh-interval ` defaults to `60` and controls the in-memory response cache TTL. - `--request-timeout ` defaults to `30` and bounds each request before returning `504 Gateway Timeout`; use `0` to keep waiting indefinitely. - Provider config is reloaded for each usage/cost request; cache entries are keyed by the loaded config so provider toggles and source changes do not require restarting `serve`. - Transient refresh failures fall back to the last good response for up to ten refresh intervals (minimum five minutes) so polling clients do not flicker between data and errors; disabled when `--refresh-interval 0`. - v1 binds to `127.0.0.1` only and rejects non-loopback `Host` headers. It does not expose remote bind, auth, CORS, TLS, or daemon mode. - Endpoints: `GET /health`, `GET /usage`, `GET /usage?provider=`, `GET /cost`, `GET /cost?provider=`. - `GET /health` returns `{"status":"ok"}` plus a `version` field with the running build (e.g. `"0.37.2"`) when resolvable; clients can compare it against `codexbar --version` to detect a `serve` process still running an older binary after an update. - Codex usage responses include every visible Codex account, matching the menu bar switcher. - `codexbar cache clear` clears local CodexBar caches. - `--cookies` removes cached browser-cookie headers from the CodexBar Keychain cache. - `--cookies --provider ` removes browser-cookie cache entries for that provider, including managed Codex account scopes. - `--cost` removes local cost-usage scan caches. - `--all` clears both cookies and cost caches. `--provider` is cookie-only and cannot be combined with `--cost` or `--all`. - `--provider ` (default: enabled providers in config; falls back to defaults when missing). - Provider IDs live in the config file (see `docs/configuration.md`). - With three or more providers enabled, the default stays scoped to enabled providers; use `--provider all` to query every registered provider. - `--account