Last active
January 15, 2026 20:14
-
-
Save shayelkin/eb2449354a70ac792e9aa726a454f849 to your computer and use it in GitHub Desktop.
Status line hook for Claude Code that shows remaining plan usage
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
| #!/bin/bash | |
| # Read JSON input from stdin | |
| input=$(cat) | |
| # Uncomment to debug what fields are available: | |
| #echo "$input" | jq '.' > /tmp/statusline-debug.json | |
| # Initialize status parts array | |
| status_parts=("$(echo "$input" | jq -r '.model.display_name')") | |
| # Context Window Usage | |
| usage=$(echo "$input" | jq -r ' | |
| if .context_window.current_usage then | |
| (.context_window.current_usage.input_tokens + | |
| .context_window.current_usage.cache_creation_input_tokens + | |
| .context_window.current_usage.cache_read_input_tokens) as $current | | |
| .context_window.context_window_size as $size | | |
| ($current * 100 / $size) | "\(.)%" | |
| else | |
| "ready" | |
| end | |
| ') | |
| status_parts+=("Context: ${usage}") | |
| # Plan Usage | |
| version=$(echo "$input" | jq -r '.version') | |
| token=$(security find-generic-password -s "Claude Code-credentials" -w 2>/dev/null | jq -r '.claudeAiOauth.accessToken') | |
| if [ -n "$token" ]; then | |
| usage=$(curl -s -H "Accept: application/json, text/plain, */*" \ | |
| -H "Content-Type: application/json" \ | |
| -H "User-Agent: claude-code/$version" \ | |
| -H "Authorization: Bearer $token" \ | |
| -H "anthropic-beta: oauth-2025-04-20" \ | |
| "https://api.anthropic.com/api/oauth/usage" 2>/dev/null) | |
| if [ $? -eq 0 ] && [ -n "$usage" ]; then | |
| five_hour=$(echo "$usage" | jq -r '.five_hour.utilization // ""') | |
| [ -n "$five_hour" ] && status_parts+=("5h: ${five_hour}%") | |
| seven_day=$(echo "$usage" | jq -r '.seven_day.utilization // ""') | |
| [ -n "$seven_day" ] && status_parts+=("7d: ${seven_day}%") | |
| fi | |
| fi | |
| # Join all parts with " | " | |
| first=true | |
| for part in "${status_parts[@]}"; do | |
| if [ "$first" = true ]; then | |
| printf "%s" "$part" | |
| first=false | |
| else | |
| printf " | %s" "$part" | |
| fi | |
| done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment