Skip to content

Instantly share code, notes, and snippets.

@khun84
khun84 / fetch-usage.sh
Created March 1, 2026 07:18
Claude Code usage statusline — 5h/7d rate-limit stats, reset countdowns, context window (macOS Keychain fix for Claude Code v2.1+)
#!/bin/sh
# Fetches Claude API usage stats and writes them to /tmp/.claude_usage_cache.
# Line 1: five_hour.utilization (integer %)
# Line 2: seven_day.utilization (integer %)
# Line 3: five_hour.resets_at (raw ISO string, e.g. 2026-02-26T12:59:59.997656+00:00)
# Line 4: seven_day.resets_at (raw ISO string)
# All output is suppressed; meant to be run in background.
CACHE_FILE="/tmp/.claude_usage_cache"
TOKEN_CACHE="/tmp/.claude_token_cache"