Display your Claude AI usage statistics directly in your Claude Code statusline. Monitor your API usage in real-time without leaving your terminal.
- Real-time Usage Tracking - See your current Claude usage percentage
- Visual Progress Bar - 10-block progress indicator with color gradient
- 10-Level Color Gradient - Dark green to deep red based on usage
- Reset Timer - Know exactly when your usage quota resets
- Fast & Lightweight - Uses native Swift for optimal performance
- Secure - No third-party services, all data stays local
- Auto-refresh - Updates automatically with your statusline
directory │ ⎇ branch │ Usage: XX% ▓▓▓░░░░░░░ → Reset: HH:MM AM/PM
Example:
my-project │ ⎇ main │ Usage: 29% ▓▓▓░░░░░░░ → Reset: 12:00 AM
Color Gradient: The entire usage section changes color based on usage level:
- 0-10%: Dark green
- 11-20%: Soft green
- 21-30%: Medium green
- 31-40%: Green-yellowish
- 41-50%: Olive/yellow-green
- 51-60%: Muted yellow
- 61-70%: Muted yellow-orange
- 71-80%: Darker orange
- 81-90%: Dark red
- 91-100%: Deep red
- macOS 11.0 or later
- Claude Code installed
- Swift (comes pre-installed with macOS)
jqcommand-line JSON processor
brew install jq- Open your browser and navigate to claude.ai
- Open Developer Tools (Cmd+Option+I)
- Go to the Application tab
- In the left sidebar, expand Cookies → https://claude.ai
- Find the
sessionKeycookie (starts withsk-ant-sid01-) - Copy the entire value
cd ~/Desktop/claude-code-statusline
./install.shThe installer will:
- Prompt you to paste your session key
- Install the Swift usage fetcher script
- Install the statusline command script
- Configure your Claude Code settings
- Set proper file permissions
Close and reopen Claude Code to see your usage stats in the statusline!
If you prefer to install manually:
# Create the session key file
echo "sk-ant-sid01-YOUR_SESSION_KEY_HERE" > ~/.claude-session-key
chmod 600 ~/.claude-session-key# Copy the Swift script
cp scripts/fetch-claude-usage.swift ~/.claude/fetch-claude-usage.swift
chmod +x ~/.claude/fetch-claude-usage.swift# Copy the statusline command script
cp scripts/statusline-command.sh ~/.claude/statusline-command.sh
chmod +x ~/.claude/statusline-command.shAdd this to your ~/.claude/settings.json:
{
"statusLine": {
"type": "command",
"command": "bash /Users/YOUR_USERNAME/.claude/statusline-command.sh"
}
}Replace YOUR_USERNAME with your actual username, or use $HOME:
{
"statusLine": {
"type": "command",
"command": "bash $HOME/.claude/statusline-command.sh"
}
}-
Swift Fetcher (
fetch-claude-usage.swift):- Reads your session key from
~/.claude-session-key - Fetches your organization ID from Claude's API
- Retrieves current usage statistics
- Returns:
UTILIZATION|RESETS_AT
- Reads your session key from
-
Statusline Script (
statusline-command.sh):- Calls the Swift fetcher
- Parses the output
- Selects color based on usage level (10-level gradient system)
- Builds visual progress bar with filled and empty blocks
- Formats the display with directory, branch, usage info, and reset time
- Outputs to Claude Code's statusline with proper color codes
-
Why Swift?
- Native macOS URLSession has browser-like TLS fingerprinting
- Bypasses Cloudflare bot detection (unlike curl)
- Fast and reliable
- No external dependencies
Causes:
- Session key is missing or invalid
- Session key has expired
- Swift script has errors
Solutions:
-
Verify session key exists:
cat ~/.claude-session-key -
Test the Swift script directly:
swift ~/.claude/fetch-claude-usage.swiftShould output:
29|2025-11-28T04:00:00.424405+00:00 -
Check for errors:
swift ~/.claude/fetch-claude-usage.swift 2>&1
-
Refresh your session key:
- Session keys expire periodically
- Follow step 2 in Quick Start to get a new key
- Update
~/.claude-session-keywith the new key
The Swift script typically runs in 1-2 seconds. If it's slower:
- Check your internet connection
- Verify Claude API is accessible:
curl -I https://claude.ai
chmod 600 ~/.claude-session-key
chmod +x ~/.claude/fetch-claude-usage.swift
chmod +x ~/.claude/statusline-command.shEdit ~/.claude/statusline-command.sh and modify the date format on line 87:
# 12-hour format (default)
reset_time=$(date -r "$epoch" "+%I:%M %p" 2>/dev/null)
# 24-hour format
reset_time=$(date -r "$epoch" "+%H:%M" 2>/dev/null)
# Full date and time
reset_time=$(date -r "$epoch" "+%b %d %I:%M %p" 2>/dev/null)- Your session key is stored locally at
~/.claude-session-keywith600permissions (owner read/write only) - No data is sent to third-party services
- All API calls go directly to Claude.ai
- Session keys should be treated like passwords - never commit them to git
rm ~/.claude-session-key
rm ~/.claude/fetch-claude-usage.swift
rm ~/.claude/statusline-command.shThen remove the statusLine configuration from ~/.claude/settings.json.
Contributions are welcome! Please feel free to submit a Pull Request.
MIT License - see LICENSE for details.
- Claude Usage Tracker (macOS App) - Menu bar app for usage tracking
If you encounter any issues:
- Check the Troubleshooting section
- Open an issue on GitHub
- Ensure you're using the latest version
Note: This is an unofficial tool and is not affiliated with or endorsed by Anthropic.