Small Waybar-friendly CLI for showing GitHub Copilot quota at a glance.
It stays dependency-free and prefers the same working personal Copilot source that OpenCode uses:
- OpenCode runtime
auth.json GET /copilot_internal/user
It also supports:
- optional managed-sidecar config for business or enterprise billing
- local cache with stale fallback
- diagnostics output
- lightweight recent-trend or overage note
- a small Waybar
setup/cleanup/restorehelper
- Python 3.10+
- for personal Copilot quota:
- OpenCode or another setup that stores a Copilot OAuth token in OpenCode runtime
auth.json
- OpenCode or another setup that stores a Copilot OAuth token in OpenCode runtime
- for managed Copilot quota:
- optional
copilot-quota-token.json
- optional
- optional:
ghinstalled and authenticated if you want CLI billing fallback mode
The script follows XDG directories and OpenCode-style runtime locations.
Default Linux paths:
- auth:
~/.local/share/opencode/auth.json - managed config:
~/.config/opencode/copilot-quota-token.json - cache:
~/.cache/waybar-copilot-usage/cache.json
Relevant overrides:
XDG_DATA_HOMEXDG_CONFIG_HOMEXDG_CACHE_HOMEXDG_STATE_HOMEOPENCODE_CONFIG_DIRCOPILOT_QUOTA_TOKEN_PATH
python3 copilot_usage.py
python3 copilot_usage.py --waybar
python3 copilot_usage.py --diagnosticsDefault mode is --source auto, which tries:
copilot-quota-token.jsonif present- OpenCode Copilot OAuth plus
/copilot_internal/user - GitHub billing APIs via
gh
If a managed config file is present, it takes precedence and does not silently fall back to another source on failure.
On a machine with working OpenCode Copilot auth, the default output looks like:
42% 15d
python3 copilot_usage.py --diagnosticsDiagnostics output includes:
- discovered auth/config/cache paths
- whether managed config was found
- cache age and history depth
- which source was attempted
- the last successful summary or current error
Create copilot-quota-token.json in your OpenCode config directory when you want managed billing mode.
Business example:
{
"token": "github_pat_...",
"tier": "business",
"organization": "acme-corp",
"username": "alice"
}Enterprise example:
{
"token": "github_pat_...",
"tier": "enterprise",
"enterprise": "acme-enterprise",
"organization": "acme-corp",
"username": "alice"
}Supported keys:
tokentierorganizationenterpriseusernameproductmodel
python3 copilot_usage.py --source billing --scope user
python3 copilot_usage.py --source billing --scope org --org my-org
python3 copilot_usage.py --source billing --scope enterprise --enterprise my-enterprise --org my-org --user my-usernameThe script writes a small local cache file after successful fetches.
- default cache TTL:
300seconds - default stale-cache fallback window:
86400seconds - default history depth:
24snapshots
Useful flags:
python3 copilot_usage.py --cache-ttl 120
python3 copilot_usage.py --stale-cache-max-age 3600
python3 copilot_usage.py --no-cache
python3 copilot_usage.py --clear-cacheThe history note stays intentionally lightweight:
Stable since 5m agoTrend: 3 pts, 7 req down since 1h agoOverage: 60 over included quota
waybar_helper.py is a small marker-based helper that can add, remove, or restore the Copilot Waybar snippet and companion CSS block.
python3 waybar_helper.py setup
python3 waybar_helper.py cleanup
python3 waybar_helper.py restore
python3 waybar_helper.py print-snippetsDefaults:
- config:
~/.config/waybar/config.jsonc - style:
~/.config/waybar/style.css - signal:
12
The inserted module uses:
exec-ifso the widget only appears when OpenCode auth or managed config is presenton-clickwith a dedicated Waybar realtime signal--clear-cachebefore refresh, so click means a real live Copilot refresh
That refresh pattern works like this:
- Waybar reruns a custom module when it receives
SIGRTMIN+N "signal": 12means this module listens forSIGRTMIN+12- clicking runs
pkill -RTMIN+12 waybar, so only the Copilot module refreshes
python3 copilot_usage.py --format "{icon_styled} {percent_used}% {time_icon} {days_left}d"
python3 copilot_usage.py --tooltip-format "Plan: {plan}\nSource: {source_label}\n{history_note}"Available format keys:
{icon}{icon_plain}{icon_styled}{source}{source_label}{auth_source}{plan}{percent_left}{percent_used}{remaining}{entitlement}{used}{days_left}{reset}{scope_note}{history_note}{cache_note}{overage}{time_icon}{time_icon_plain}{time_icon_styled}
- The tool remains intentionally small and Waybar-first.
- Multi-account discovery is intentionally out of scope for now.
- If GitHub changes either
/copilot_internal/useror billing endpoints again, diagnostics should make the breakage much easier to see.
Sources: