Skip to content

Instantly share code, notes, and snippets.

@esamattis
Last active June 2, 2026 12:37
Show Gist options
  • Select an option

  • Save esamattis/65c0c283f89e21e4407f2b43f4d94dfd to your computer and use it in GitHub Desktop.

Select an option

Save esamattis/65c0c283f89e21e4407f2b43f4d94dfd to your computer and use it in GitHub Desktop.

SketchyBar widget for Github Copilot AI credits budget usage. Requires uses level budget to be set.

image
#!/bin/bash
# items/copilot_usage.sh
copilot_usage_top=(
label.font="$FONT:Semibold:7"
label="copilot usage"
icon.drawing=off
width=0
padding_right=15
y_offset=6
)
copilot_usage=(
icon.drawing=off
label.font="$FONT:Heavy:12"
label="--/--"
y_offset=-4
padding_right=15
update_freq=900
script="$PLUGIN_DIR/copilot_usage.sh"
)
sketchybar --add item copilot_usage.top right \
--set copilot_usage.top "${copilot_usage_top[@]}" \
\
--add item copilot_usage right \
--set copilot_usage "${copilot_usage[@]}"
#!/bin/bash
# plugins/copilot_usage.sh
USER_NAME="$(gh api user --jq '.login' 2>/dev/null)"
if [ -z "$USER_NAME" ]; then
sketchybar --set "$NAME" label="--/--"
exit 0
fi
USAGE=""
# Copilot budgets are scoped to an org, so check each active org membership
# until one exposes a user-level AI credits budget for the authenticated user.
while IFS= read -r ORG_NAME; do
[ -z "$ORG_NAME" ] && continue
USAGE="$(
gh api \
-H "Accept: application/vnd.github+json" \
-H "X-GitHub-Api-Version: 2026-03-10" \
"/organizations/$ORG_NAME/settings/billing/budgets" 2>/dev/null \
| jq -r --arg user "$USER_NAME" '
.budgets[]
| select(.budget_product_sku == "ai_credits" and .budget_scope == "user" and .user == $user)
| "$\((.consumed_amount * 100 | round) / 100)/$\(.budget_amount)"
' 2>/dev/null
)"
[ -n "$USAGE" ] && break
done < <(gh api --paginate user/memberships/orgs --jq '.[] | select(.state == "active") | .organization.login' 2>/dev/null)
if [ -z "$USAGE" ]; then
USAGE="\$--/\$--"
fi
sketchybar --set "$NAME" label="${USAGE}"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment