Skip to content

Commit 9eb0ebd

Browse files
committed
chore: bump VERSION to 5.1.0
1 parent 710fb0b commit 9eb0ebd

2 files changed

Lines changed: 47 additions & 7 deletions

File tree

CLAUDE.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ Key sections in `claude-code-status-line.py` (~2,200 lines):
4141
- **Lines ~170-355**: Theme system — `THEMES` dict (dark/light, Nord-inspired), `_load_custom_theme()` loads optional `~/.claude/claude-code-theme.toml` via `tomllib`
4242
- **Lines ~468**: `get_git_branch()` — subprocess call to `git branch --show-current`, strips ESC characters from output
4343
- **Lines ~497**: `get_git_status()` — collects working directory state (staged/modified/deleted/renamed/untracked/conflicted), stash count, and ahead/behind status via `git status --porcelain=v1`, `git stash list`, and `git rev-list`
44-
- **Lines ~571**: `fetch_usage_data()` — OAuth API call via `curl` subprocess, cached atomically to `~/.claude/.usage_cache.json` for `USAGE_CACHE_DURATION` seconds
44+
- **Lines ~571**: `_normalize_usage_data()` — converts CC 2.1.80+ `rate_limits` stdin JSON (unix timestamps, float percentages) to internal format (ISO 8601, utilization). `fetch_usage_data()` (deprecated) — OAuth API fallback for older CC versions, cached atomically to `~/.claude/.usage_cache.json`
4545
- **Lines ~639-746**: Update checker — `get_installed_version()` runs `claude --version`, `fetch_latest_version()` queries npm registry with caching to `~/.claude/.update_cache.json`, `check_for_update()` compares versions via `parse_semver()`
4646
- **Lines ~749-870**: Usage gauge rendering — vertical (block chars ▁▂▃▄▅▆▇█) and horizontal blocks styles with forward-looking ratio logic
4747
- **Lines ~872**: `format_usage_indicators()` — returns dict with per-window usage strings
@@ -70,7 +70,8 @@ Key sections in `claude-code-status-line.py` (~2,200 lines):
7070
- **Custom themes**: loaded via `tomllib` from a TOML file (Python 3.11+, `tomli` fallback), only the defined keys override the base theme. Silently skipped if no TOML parser available.
7171
- **Progress bar precision**: Unicode fractional blocks (▏▎▍▌▋▊▉█) for sub-character precision with gradient color interpolation across 10 thresholds.
7272
- **Input validation**: OAuth token characters allowlisted before HTTP use. Git branch names stripped of ESC chars. Segment widths capped at 128. Hex colors length-checked. Usage ratio guarded against near-zero divisor.
73-
- **Credential sources**: macOS Keychain (`security` command) → `~/.claude/.credentials.json` fallback.
73+
- **Usage data source**: CC 2.1.80+ sends `rate_limits` in stdin JSON (preferred). Falls back to deprecated OAuth API (`fetch_usage_data()`) for older CC versions. OAuth path (`get_oauth_token()`, `USAGE_CACHE_PATH`, `SL_USAGE_CACHE_DURATION`) will be removed in a future version.
74+
- **Credential sources**: macOS Keychain (`security` command) → `~/.claude/.credentials.json` fallback (deprecated, only used by OAuth fallback).
7475
- **Cache writes**: atomic via `tempfile.mkstemp()` + `os.replace()` with temp file cleanup on failure.
7576
- **No type hints** per project convention — uses f-strings throughout.
7677
- **Effort level limitations**: The statusline JSON from Claude Code does NOT include effort level. The `model:effort` option reads from settings files as a workaround. Known gaps:

claude-code-status-line.py

Lines changed: 44 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@
3535
import tty
3636
from datetime import datetime, timezone
3737

38-
VERSION = "5.0.0"
38+
VERSION = "5.1.0"
3939

4040
# =============================================================================
4141
# CONFIGURATION — override any setting via environment variables (SL_ prefix)
@@ -55,6 +55,7 @@ def _env_int(key, default):
5555

5656

5757
THEME = _env_str("THEME", "dark")
58+
# Deprecated: only used by fetch_usage_data() fallback. Will be removed in a future version.
5859
USAGE_CACHE_DURATION = _env_int("USAGE_CACHE_DURATION", 300)
5960
UPDATE_CACHE_DURATION = _env_int("UPDATE_CACHE_DURATION", 3600) # 1 hour on success
6061
UPDATE_RETRY_DURATION = _env_int("UPDATE_RETRY_DURATION", 600) # 10 min retry on failure
@@ -623,8 +624,37 @@ def get_git_status(cwd):
623624
CREDENTIALS_PATH = os.path.expanduser("~/.claude/.credentials.json")
624625

625626

627+
def _normalize_usage_data(rate_limits):
628+
"""Convert rate_limits from CC stdin JSON to internal usage format.
629+
630+
CC 2.1.80+ sends: {used_percentage: float, resets_at: unix_timestamp}
631+
Internal format: {utilization: int, resets_at: ISO8601_string}
632+
"""
633+
if not rate_limits:
634+
return None
635+
result = {}
636+
for key in ("five_hour", "seven_day"):
637+
window = rate_limits.get(key)
638+
if not window:
639+
continue
640+
used_pct = window.get("used_percentage")
641+
resets_at = window.get("resets_at")
642+
if used_pct is None or resets_at is None:
643+
continue
644+
reset_dt = datetime.fromtimestamp(resets_at, tz=timezone.utc)
645+
result[key] = {
646+
"utilization": used_pct,
647+
"resets_at": reset_dt.isoformat(),
648+
}
649+
return result if result else None
650+
651+
626652
def get_oauth_token():
627-
"""Get OAuth access token from macOS Keychain or credentials file."""
653+
"""Get OAuth access token from macOS Keychain or credentials file.
654+
655+
Deprecated: Only used by fetch_usage_data() which is itself deprecated.
656+
Will be removed in a future version.
657+
"""
628658
# On macOS, try Keychain first
629659
if sys.platform == "darwin":
630660
try:
@@ -656,7 +686,12 @@ def get_oauth_token():
656686

657687

658688
def fetch_usage_data():
659-
"""Fetch usage data from Anthropic OAuth API, with caching."""
689+
"""Fetch usage data from Anthropic OAuth API, with caching.
690+
691+
Deprecated: CC 2.1.80+ provides rate_limits in stdin JSON. This function
692+
is kept as a fallback for older CC versions and will be removed in a
693+
future version along with get_oauth_token() and USAGE_CACHE_PATH.
694+
"""
660695
# Check cache first
661696
try:
662697
if os.path.exists(USAGE_CACHE_PATH):
@@ -2199,8 +2234,12 @@ def main():
21992234
return
22002235
pct = int(used_percentage)
22012236

2202-
# Get usage limits indicators
2203-
usage_data = fetch_usage_data()
2237+
# Get usage limits indicators (prefer stdin from CC 2.1.80+, fallback to OAuth API)
2238+
rate_limits = data.get("rate_limits")
2239+
if rate_limits:
2240+
usage_data = _normalize_usage_data(rate_limits)
2241+
else:
2242+
usage_data = fetch_usage_data() # Deprecated: will be removed in a future version
22042243
usage_parts = format_usage_indicators(usage_data)
22052244

22062245
# Check for updates

0 commit comments

Comments
 (0)