Created
April 22, 2026 14:20
-
-
Save mzur/c43b7fc9e6a72d5cb27ef86a04ac408b to your computer and use it in GitHub Desktop.
A statusline script for Claude Code showing the current context size and remaining quota
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/usr/bin/env python3 | |
| """Pattern 1: Minimal dots - colored circles with numbers only""" | |
| """Source: https://nyosegawa.com/posts/claude-code-statusline-rate-limits/ """ | |
| import json, math, sys | |
| from datetime import datetime, timezone | |
| data = json.load(sys.stdin) | |
| R = '\033[0m' | |
| DIM = '\033[2m' | |
| BOLD = '\033[1m' | |
| def gradient(pct): | |
| if pct < 50: | |
| r = int(pct * 5.1) | |
| return f'\033[38;2;{r};200;80m' | |
| else: | |
| g = int(200 - (pct - 50) * 4) | |
| return f'\033[38;2;255;{max(g, 0)};60m' | |
| def time_left(resets_at): | |
| if not resets_at: | |
| return None | |
| try: | |
| reset = datetime.fromtimestamp(float(resets_at), tz=timezone.utc) | |
| secs = (reset - datetime.now(timezone.utc)).total_seconds() | |
| if secs <= 0: | |
| return '0m' | |
| h = secs / 3600 | |
| if h >= 24: | |
| return f'{math.ceil(h / 24)}d' | |
| if h >= 1: | |
| return f'{math.ceil(h)}h' | |
| return f'{math.ceil(secs / 60)}m' | |
| except Exception: | |
| return None | |
| def dot(pct): | |
| p = round(pct) | |
| return f'{gradient(pct)}●{R} {BOLD}{p}%{R}' | |
| model = data.get('model', {}).get('display_name', 'Claude') | |
| parts = [f'{BOLD}{model}{R}'] | |
| ctx = data.get('context_window', {}).get('used_percentage') | |
| if ctx is not None: | |
| parts.append(f'ctx {dot(ctx)}') | |
| five = data.get('rate_limits', {}).get('five_hour', {}).get('used_percentage') | |
| reset_five = data.get('rate_limits', {}).get('five_hour', {}).get('resets_at') | |
| if five is not None: | |
| label = time_left(reset_five) or '5h' | |
| parts.append(f'{label} {dot(five)}') | |
| week = data.get('rate_limits', {}).get('seven_day', {}).get('used_percentage') | |
| reset_seven = data.get('rate_limits', {}).get('seven_day', {}).get('resets_at') | |
| if week is not None: | |
| label = time_left(reset_seven) or '7d' | |
| parts.append(f'{label} {dot(week)}') | |
| print(f' {DIM}·{R} '.join(parts), end='') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment