Skip to content

Instantly share code, notes, and snippets.

@panicoenlaxbox
Last active May 19, 2026 12:16
Show Gist options
  • Select an option

  • Save panicoenlaxbox/826f0c5af67ebd06771afbbc9fad4733 to your computer and use it in GitHub Desktop.

Select an option

Save panicoenlaxbox/826f0c5af67ebd06771afbbc9fad4733 to your computer and use it in GitHub Desktop.
Claude statusline
import json, sys
from datetime import datetime, timezone
data = json.loads(sys.stdin.read())
model = data.get("model", {}).get("display_name", "Unknown")
context_window_size = data.get("context_window", {}).get("context_window_size", 0)
used_percentage = data.get("context_window", {}).get("used_percentage")
current_usage = data.get("context_window", {}).get("current_usage", {})
total_tokens = (
current_usage.get("input_tokens", 0)
+ current_usage.get("cache_creation_input_tokens", 0)
+ current_usage.get("cache_read_input_tokens", 0)
)
total_cost_usd = data.get("cost", {}).get("total_cost_usd")
rate_limits = data.get("rate_limits", {})
five_hour = rate_limits.get("five_hour", {})
seven_day = rate_limits.get("seven_day", {})
if context_window_size >= 1_000_000:
context_window_label = f"{context_window_size // 1_000_000}M context"
elif context_window_size >= 1_000:
context_window_label = f"{context_window_size // 1_000}K context"
else:
context_window_label = f"{context_window_size} context"
status_line = f"{model} ({context_window_label})"
if used_percentage is not None:
status_line += f" | {round(used_percentage)}% used"
if total_tokens:
if total_tokens >= 1_000:
status_line += f" | {total_tokens / 1_000:.1f}k tokens"
else:
status_line += f" | {total_tokens} tokens"
if total_cost_usd is not None:
status_line += f" | ${total_cost_usd:.2f} cost"
if five_hour:
pct = five_hour.get("used_percentage", 0)
resets_at = five_hour.get("resets_at")
if resets_at:
resets_dt = datetime.fromtimestamp(resets_at, tz=timezone.utc).astimezone()
now = datetime.now(tz=timezone.utc).astimezone()
diff_minutes = int((resets_dt - now).total_seconds() / 60)
if diff_minutes >= 60:
resets_label = f"{diff_minutes // 60}h{diff_minutes % 60:02d}m"
else:
resets_label = f"{diff_minutes}m"
status_line += f" | 5h: {round(pct)}% (reset in {resets_label})"
else:
status_line += f" | 5h: {round(pct)}%"
if seven_day:
pct = seven_day.get("used_percentage", 0)
status_line += f" | 7d: {round(pct)}%"
print(status_line)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment