Created
March 30, 2026 23:10
-
-
Save robinebers/dc3ca148cf432499f011e99fbd065214 to your computer and use it in GitHub Desktop.
Claude Code Statusline for OpenUsage Display your Claude usage (Session, Weekly, Today) in Claude Code's status bar using the OpenUsage local API. ## Quick Install ```bash
curl -o ~/.claude/claude-usage-statusline.sh \ https://gist.githubusercontent.com/YOUR_GIST_ID/raw/statusline.sh
chmod +x ~/.claude/claude-usage-statusline.sh
``` ## Configure…
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 bash | |
| # Minimal Claude Code statusline - no colors, no dependencies | |
| # Format: "Claude Team 5x | Session: 4% | Week: 11% | Today: $0.47 · 1.1M tokens" | |
| API_URL="http://localhost:6736/v1/usage/claude" | |
| CACHE_FILE="${TMPDIR:-/tmp}/claude-statusline-cc.json" | |
| CACHE_AGE_MAX=300 # 5 minutes | |
| # Fetch with simple caching | |
| if [[ -f "$CACHE_FILE" ]]; then | |
| cache_mtime=$(stat -f%m "$CACHE_FILE" 2>/dev/null || stat -c%Y "$CACHE_FILE" 2>/dev/null || echo 0) | |
| cache_age=$(( $(date +%s) - cache_mtime )) | |
| if [[ $cache_age -ge $CACHE_AGE_MAX ]]; then | |
| curl -s --max-time 2 "$API_URL" > "$CACHE_FILE" 2>/dev/null || true | |
| fi | |
| else | |
| curl -s --max-time 2 "$API_URL" > "$CACHE_FILE" 2>/dev/null || true | |
| fi | |
| # Read the cached JSON | |
| data=$(cat "$CACHE_FILE" 2>/dev/null) || data="" | |
| if [[ -z "$data" ]]; then | |
| echo "Claude: --" | |
| exit 0 | |
| fi | |
| # Extract values using sed (handles minified JSON) | |
| plan=$(echo "$data" | sed -n 's/.*"plan":"\([^"]*\)".*/\1/p') | |
| session=$(echo "$data" | sed -n 's/.*"label":"Session"[^}]*"used":\([0-9.]*\).*/\1/p') | |
| weekly=$(echo "$data" | sed -n 's/.*"label":"Weekly"[^}]*"used":\([0-9.]*\).*/\1/p') | |
| today=$(echo "$data" | sed -n 's/.*"label":"Today"[^}]*"value":"\([^"]*\)".*/\1/p') | |
| # Format values | |
| plan="${plan:---}" | |
| session="${session:-0}" | |
| weekly="${weekly:-0}" | |
| today="${today:---}" | |
| # Truncate decimals | |
| session_int="${session%.*}" | |
| weekly_int="${weekly%.*}" | |
| # Output | |
| printf "Claude %s | Session: %s%% | Week: %s%% | Today: %s\n" "$plan" "$session_int" "$weekly_int" "$today" |
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
| { | |
| "statusLine": { | |
| "type": "command", | |
| "command": "~/.claude/claude-usage-statusline.sh", | |
| "padding": 1 | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment