Skip to content

Instantly share code, notes, and snippets.

@norm
Created February 3, 2026 08:04
Show Gist options
  • Select an option

  • Save norm/c9e9bb0ded99b95d51bf3eaed595360e to your computer and use it in GitHub Desktop.

Select an option

Save norm/c9e9bb0ded99b95d51bf3eaed595360e to your computer and use it in GitHub Desktop.
#!/usr/bin/env python
import os
import requests
from datetime import datetime, timezone
ORG_ID = os.environ["CLAUDE_ORG"]
COOKIE = os.environ["CLAUDE_COOKIE"]
HEADERS = {
"Content-Type": "application/json",
"Cookie": COOKIE,
"User-Agent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) "
"AppleWebKit/605.1.15 (KHTML, like Gecko) Version/18.5 Safari/605.1.15",
}
def format_reset_time(iso_string, short=True):
if not iso_string:
return None
reset = datetime.fromisoformat(iso_string)
now = datetime.now(timezone.utc)
delta = reset - now
if delta.total_seconds() < 0:
return "now"
hours, remainder = divmod(int(delta.total_seconds()), 3600)
minutes = remainder // 60
if hours >= 24:
days = hours // 24
if short:
return f"{days}d"
return f"{days} day" + ("s" if days != 1 else "")
if short:
return f"{hours}h {minutes:02d}"
hour_str = f"{hours} hour" + ("s" if hours != 1 else "")
minute_str = f"{minutes} minute" + ("s" if minutes != 1 else "")
return f"{hour_str}, {minute_str}"
def main():
url = f"https://claude.ai/api/organizations/{ORG_ID}/usage"
response = requests.get(url, headers=HEADERS)
response.raise_for_status()
data = response.json()
term_width = os.get_terminal_size(0).columns if os.isatty(0) else 80
short = term_width <= 80
time_width = 7 if short else 24
rows = []
for key, value in data.items():
if value is None:
continue
reset_str = format_reset_time(value.get("resets_at"), short=short)
if reset_str is None:
continue
utilisation = int(value.get("utilization", 0))
rows.append((key, utilisation, reset_str))
if not rows:
return
label_width = max(len(row[0]) for row in rows) + 4
bar_width = term_width - label_width - time_width - 7
print()
for key, utilisation, reset_str in rows:
filled = utilisation * bar_width // 100
bar = "#" * filled + "-" * (bar_width - filled)
print(f"{key:{label_width}}[{bar}] {reset_str}")
if __name__ == "__main__":
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment