Skip to content

Instantly share code, notes, and snippets.

@robinebers
Last active May 11, 2026 07:48
Show Gist options
  • Select an option

  • Save robinebers/275c3fd29b14447e3656cf9573863607 to your computer and use it in GitHub Desktop.

Select an option

Save robinebers/275c3fd29b14447e3656cf9573863607 to your computer and use it in GitHub Desktop.
Claude Code Statusline for OpenUsage - Display Claude usage (Session, Weekly, Today) in Claude Code's status bar using the OpenUsage local API. Requires OpenUsage app running.
{
"statusLine": {
"type": "command",
"command": "~/.claude/statusline.sh",
"padding": 1
}
}
#!/usr/bin/env bash
# Claude Code statusline using OpenUsage API
# 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 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 ))
[[ $cache_age -ge $CACHE_AGE_MAX ]] && curl -s --max-time 2 "$API_URL" > "$CACHE_FILE" 2>/dev/null || true
else
curl -s --max-time 2 "$API_URL" > "$CACHE_FILE" 2>/dev/null || true
fi
data=$(cat "$CACHE_FILE" 2>/dev/null) || data=""
[[ -z "$data" ]] && { echo "Claude: --"; exit 0; }
# Extract with sed
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')
printf "Claude %s | Session: %s%% | Week: %s%% | Today: %s\n" \
"${plan:---}" "${session%.*}" "${weekly%.*}" "${today:---}"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment