Skip to main content

Desktop widget and CLI that shows real-time Claude Code usage limits and cost.

Project description

Claude Usage Widget

A desktop widget that displays your Claude Code usage limits in real time. Shows session and weekly utilization percentages fetched from the Anthropic API, with an always-on-top OSD overlay and a system tray / menu bar icon.

Platform Python License

Features

  • Real API data -- fetches rate-limit utilization from anthropic-ratelimit-unified-* response headers
  • OSD overlay -- transparent, borderless widget in the corner of your screen showing session and weekly usage bars with reset countdowns
  • System tray / menu bar -- quick-glance usage info and a detailed popup window
  • Cross-platform -- native GTK3 on Linux, native AppKit/rumps on macOS
  • Auto-refresh -- updates every 30 seconds (configurable)
  • Resizable -- scroll wheel to scale the OSD up or down (0.6x--2.0x)
  • Opacity control -- adjustable OSD transparency via the tray / menu bar
  • Draggable -- left-click and drag to reposition the OSD
  • Minimizable -- right-click the OSD to collapse it to a thin progress bar
  • Active sessions -- shows running Claude Code sessions with project paths and durations
  • Cost estimation -- widget shows estimated $ spent today and cache savings using model pricing
  • Usage forecasting -- burn rate calculation shows "at this rate you'll hit the limit in Xh Ym"
  • Per-project breakdown -- top 5 projects by token usage today
  • Themes -- 5 built-in themes (default, catppuccin-mocha, dracula, nord, gruvbox-dark), set via "theme": "dracula" in config.json

Requirements

  • Python 3.10+
  • Claude Code CLI installed and authenticated (OAuth)

Linux

  • GTK3, python3-gi, python3-gi-cairo, python3-cairo
  • gir1.2-ayatanaappindicator3-0.1 (system tray)

macOS

  • rumps and pyobjc-framework-Cocoa (installed automatically via requirements-macos.txt)

Installation

Linux

# 1. Install system dependencies (Ubuntu/Debian)
sudo apt install python3-gi python3-gi-cairo python3-cairo gir1.2-ayatanaappindicator3-0.1

# Fedora
sudo dnf install python3-gobject python3-gobject-cairo python3-cairo gtk3

# Arch
sudo pacman -S python-gobject python-cairo gtk3 libappindicator-gtk3

# 2. Clone and run
git clone https://github.com/bozdemir/claude-usage-widget.git
cd claude-usage-widget
python3 main.py &

# 3. Autostart on login (optional)
./install.sh

macOS

# 1. Clone
git clone https://github.com/bozdemir/claude-usage-widget.git
cd claude-usage-widget

# 2. Install Python dependencies
pip3 install -r requirements-macos.txt

# 3. Run
python3 main.py

# 4. Autostart on login (optional) -- installs a Launch Agent
./install-macos.sh

Usage

OSD Overlay Controls

Action Effect
Scroll up / down Resize (0.6x--2.0x)
Left-click drag Move the OSD
Right-click Minimize / restore

System Tray / Menu Bar

  • Session / Weekly -- current usage percentages
  • Details... -- opens a detailed popup with usage bars and active sessions
  • Refresh -- force an immediate data refresh
  • OSD Overlay -- toggle the OSD on or off
  • OSD Opacity -- set OSD transparency (100% / 75% / 50% / 25%)
  • Quit -- exit the widget

Configuration

All settings are optional. Copy config.json.example to config.json and edit the values you want to change:

cp config.json.example config.json
{
    "daily_message_limit": 200,
    "weekly_message_limit": 1000,
    "daily_token_limit": 5000000,
    "weekly_token_limit": 25000000,
    "refresh_seconds": 30,
    "osd_opacity": 0.75,
    "osd_scale": 1.0
}
Setting Default Description
refresh_seconds 30 How often to fetch new data from the API (seconds)
osd_opacity 0.75 OSD background opacity (0.15--1.0)
osd_scale 1.0 OSD scale factor (0.6--2.0)
daily_message_limit 200 Daily message limit for local tracking in the popup
weekly_message_limit 1000 Weekly message limit for local tracking in the popup
daily_token_limit 5000000 Daily token limit for local tracking
weekly_token_limit 25000000 Weekly token limit for local tracking
claude_dir ~/.claude Path to the Claude Code data directory
theme default Color theme for the OSD and popup. One of default, catppuccin-mocha, dracula, nord, gruvbox-dark

Keys omitted from config.json fall back to built-in defaults. claude_dir is not included in the example file because the default is correct for most setups.

Themes

The widget ships with 5 built-in color themes. Select one by adding "theme": "<name>" to your config.json:

{
    "theme": "dracula"
}

Available themes:

  • default -- the original widget palette (screenshots welcome)
  • catppuccin-mocha -- soft pastel dark theme (screenshots welcome)
  • dracula -- classic purple-and-pink dark theme (screenshots welcome)
  • nord -- cool arctic blue palette (screenshots welcome)
  • gruvbox-dark -- warm retro-style dark theme (screenshots welcome)

How It Works

The widget reads your Claude Code OAuth credentials from ~/.claude/.credentials.json (Linux) or the macOS Keychain and makes a minimal API call (max_tokens=1 to claude-haiku-4-5-20251001) to read the rate-limit response headers:

anthropic-ratelimit-unified-5h-utilization: 0.58
anthropic-ratelimit-unified-5h-reset: 1776186000
anthropic-ratelimit-unified-7d-utilization: 0.10
anthropic-ratelimit-unified-7d-reset: 1776690000

These are the same values shown on the claude.ai usage page. The widget also reads local data from ~/.claude/ for message counts, token usage per model, and active session tracking.

How the OSD Works

The OSD is a transparent, borderless window rendered entirely via 2D drawing primitives:

  • Linux -- a Gtk.Window with the NOTIFICATION type hint uses Cairo to draw rounded rectangles, progress bars, and text onto an RGBA surface. The compositor handles transparency; set_accept_focus(False) prevents the overlay from stealing keyboard focus.
  • macOS -- an NSWindow at NSFloatingWindowLevel with NSWindowStyleMaskBorderless and a transparent NSView subclass does the equivalent drawing via AppKit (NSBezierPath, NSColor, NSAttributedString).

Scale and opacity -- Both platforms store a float scale (0.6--2.0, default 1.0) and opacity (0.15--1.0, default 0.75) that are applied at draw time. Scale multiplies every pixel dimension (padding, font size, bar height, window size) before drawing, so the entire widget resizes proportionally without re-layout. Opacity is used as the alpha channel of the background fill; bar and text elements are drawn at full alpha on top so they remain legible at low opacity.

Refresh cycle -- A background thread wakes every refresh_seconds (default 30), makes an API call, and posts the result back to the main thread via GLib.idle_add (Linux) or a rumps.Timer-drained queue (macOS). The main thread then invalidates the OSD window, triggering a synchronous redraw. User interactions (scroll to resize, drag to move, right-click to minimize) update scale and position in place and queue an immediate redraw without waiting for the next refresh tick.

Troubleshooting

Linux: OSD not visible

  • Ensure XWayland is available. The widget forces GDK_BACKEND=x11 for reliable borderless windows.
  • Check if the process is running: ps aux | grep main.py

Linux: no system tray icon

Linux: Cairo errors (Couldn't find foreign struct converter)

  • Install python3-gi-cairo: sudo apt install python3-gi-cairo

macOS: no menu bar icon

  • Make sure rumps is installed: pip3 install rumps
  • If using a virtualenv, ensure pyobjc-framework-Cocoa is also installed.

API authentication fails

  • Make sure the Claude Code CLI is installed and you are logged in (the claude command should work).
  • Linux: the OAuth token is read from ~/.claude/.credentials.json.
  • macOS: the OAuth token is read from the Keychain, with a fallback to ~/.claude/.credentials.json.

Contributing

Contributions are welcome. A few guidelines:

  • Bug reports -- open an issue with your OS, Python version, and the full error output. If the OSD is invisible, include xrandr or system_profiler SPDisplaysDataType output.
  • Pull requests -- keep changes focused. One fix or feature per PR. Run the widget manually on the target platform before submitting.
  • Platform parity -- features that affect the OSD or tray should work on both Linux and macOS, or be clearly gated behind a platform check.
  • No new dependencies -- avoid adding Python packages beyond those already in requirements-macos.txt and the listed GTK stack. If a dependency is truly necessary, discuss it in an issue first.
  • Code style -- follow the existing conventions. No formatter is enforced; just match the surrounding code.

License

MIT

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

claude_usage_widget-0.2.1.tar.gz (95.9 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

claude_usage_widget-0.2.1-py3-none-any.whl (80.2 kB view details)

Uploaded Python 3

File details

Details for the file claude_usage_widget-0.2.1.tar.gz.

File metadata

  • Download URL: claude_usage_widget-0.2.1.tar.gz
  • Upload date:
  • Size: 95.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for claude_usage_widget-0.2.1.tar.gz
Algorithm Hash digest
SHA256 be7c462409e6129ee4130ee47d65a47394c8b2b7c740c94c388d29f231369770
MD5 9fdb695c7ab247e48ca5345e7bbf5d80
BLAKE2b-256 2183e98c8c42b5d20ad47a6ee037d69d5909d98431f7b4af6d0858d059d2bf2c

See more details on using hashes here.

Provenance

The following attestation bundles were made for claude_usage_widget-0.2.1.tar.gz:

Publisher: publish.yml on bozdemir/claude-usage-widget

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file claude_usage_widget-0.2.1-py3-none-any.whl.

File metadata

File hashes

Hashes for claude_usage_widget-0.2.1-py3-none-any.whl
Algorithm Hash digest
SHA256 4575e167483b9f6df0660a6932efb649452ed89494d54dfc230e670e80081376
MD5 8560621f98c9ad48141478dc1bd69d17
BLAKE2b-256 17a3cc808f899f3226f3f7064b4f500326b17d59ca00405f9e781ea335e24585

See more details on using hashes here.

Provenance

The following attestation bundles were made for claude_usage_widget-0.2.1-py3-none-any.whl:

Publisher: publish.yml on bozdemir/claude-usage-widget

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page