Skip to content

About

Small Waybar-friendly CLI for showing GitHub Copilot quota at a glance.

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Latest commit

 

History

2 Commits

Folders and files

Repository files navigation

waybar-copilot-usage

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
image

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/restore helper

Requirements

  • Python 3.10+
  • for personal Copilot quota:
    • OpenCode or another setup that stores a Copilot OAuth token in OpenCode runtime auth.json
  • for managed Copilot quota:
    • optional copilot-quota-token.json
  • optional: gh installed and authenticated if you want CLI billing fallback mode

Path discovery

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_HOME
  • XDG_CONFIG_HOME
  • XDG_CACHE_HOME
  • XDG_STATE_HOME
  • OPENCODE_CONFIG_DIR
  • COPILOT_QUOTA_TOKEN_PATH

Quick Start

python3 copilot_usage.py
python3 copilot_usage.py --waybar
python3 copilot_usage.py --diagnostics

Default mode is --source auto, which tries:

  1. copilot-quota-token.json if present
  2. OpenCode Copilot OAuth plus /copilot_internal/user
  3. 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

Diagnostics

python3 copilot_usage.py --diagnostics

Diagnostics 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

Managed config

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:

  • token
  • tier
  • organization
  • enterprise
  • username
  • product
  • model

Billing CLI fallback

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-username

Caching and history

The script writes a small local cache file after successful fetches.

  • default cache TTL: 300 seconds
  • default stale-cache fallback window: 86400 seconds
  • default history depth: 24 snapshots

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-cache

The history note stays intentionally lightweight:

  • Stable since 5m ago
  • Trend: 3 pts, 7 req down since 1h ago
  • Overage: 60 over included quota

Waybar helper

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-snippets

Defaults:

  • config: ~/.config/waybar/config.jsonc
  • style: ~/.config/waybar/style.css
  • signal: 12

The inserted module uses:

  • exec-if so the widget only appears when OpenCode auth or managed config is present
  • on-click with a dedicated Waybar realtime signal
  • --clear-cache before refresh, so click means a real live Copilot refresh

Example Waybar module

"custom/copilot-usage": {
  "exec-if": "/usr/bin/sh -lc 'test -f \\\"$HOME/.local/share/opencode/auth.json\\\" || test -f \\\"$HOME/.config/opencode/copilot-quota-token.json\\\"'",
  "exec": "/usr/bin/python3 \"$HOME/dev/git/waybar-copilot-usage/copilot_usage.py\" --waybar --format '{icon_styled} {percent_used}% {time_icon} {days_left}d'",
  "return-type": "json",
  "interval": 300,
  "on-click": "/usr/bin/python3 \"$HOME/dev/git/waybar-copilot-usage/copilot_usage.py\" --clear-cache && /usr/bin/pkill -RTMIN+12 waybar",
  "signal": 12
}

That refresh pattern works like this:

  • Waybar reruns a custom module when it receives SIGRTMIN+N
  • "signal": 12 means this module listens for SIGRTMIN+12
  • clicking runs pkill -RTMIN+12 waybar, so only the Copilot module refreshes

Custom formatting

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}

Notes

  • The tool remains intentionally small and Waybar-first.
  • Multi-account discovery is intentionally out of scope for now.
  • If GitHub changes either /copilot_internal/user or billing endpoints again, diagnostics should make the breakage much easier to see.

Sources:

About

Small Waybar-friendly CLI for showing GitHub Copilot quota at a glance.

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages