Skip to main content
Glama

mcp-claude-usage

An MCP server that provides your LLM agents with stats on your Claude individual subscription usage and quota headroom.

This might be useful if you wanted, say, to run an autonomous agent opportunistically on a cron job, while making sure that you don’t run past your subscription quota later on when you need it for something more important.

Usage

Call the get_usage tool from Claude Code. It returns:

{
  "5h": {
    "usage": 0.4261,
    "time_elapsed_pct": 0.7269,
    "headroom_pct": 0.3008,
    "resets_at": 1766995200,
    "burn_rate_per_hour": 0.31,
    "runway_seconds": 6664
  },
  "7d": {
    "usage": 0.1372,
    "time_elapsed_pct": 0.3312,
    "headroom_pct": 0.194,
    "resets_at": 1767394800,
    "burn_rate_per_hour": 0.0058,
    "runway_seconds": 535531
  }
}
  • usage: Current utilization (0.0-1.0)

  • time_elapsed_pct: Portion of rate limit window elapsed (0.0-1.0)

  • headroom_pct: Available capacity relative to linear pace

  • resets_at: Unix timestamp when window resets

  • burn_rate_per_hour: Recent consumption rate, as a fraction of the window's quota per hour, estimated from the slope of usage over the trailing half hour of samples. null until the server has two samples to draw a line through; 0.0 when you're idle.

  • runway_seconds: Seconds until the quota runs out at that burn rate. null when the rate is unknown or zero.

Negative headroom means you're consuming tokens at a pace that exceeds your subscription level. Positive headroom means you're still within budget.

The sample history behind the burn rate lives in memory, so after a server restart the burn and runway fields stay null for the first couple of samples. The estimate is a trailing one: a sudden burst of work won't show up until the next sample or two lands.

Related MCP server: claude-usage-mcp

How it works

Anthropic doesn’t provide individual user accounts with an API endpoint that exposes subscription usage statistics. This information is available, however, in the HTTP headers returned from Claude Code requests.

This MCP provides a get_usage tool, which runs a single background request with the claude CLI against a local forwarding proxy. The proxy grabs the rate limit metadata from the HTTP response header, does some arithmetic, and returns the result to the MCP client.

Requirements

  • Claude Code CLI installed (or run in a Docker container)

  • Log in with a Claude Pro or Max subscription (claude login)

Installation

cd /path/to/mcp-claude-usage
uv sync

Configuration

Add to your Claude Code MCP settings (~/.claude/settings.json):

{
  "mcpServers": {
    "claude-usage": {
      "type": "http",
      "url": "http://localhost:8000/mcp"
    }
  }
}

Running locally

Start the server:

uv run mcp-claude-usage

Or run directly:

uv run python mcp_claude_usage.py

You can change the host and port that the MCP server uses with environment variables:

  • HOST: Bind address (default: 127.0.0.1)

  • PORT: Server port (default: 8000)

Running in Docker

docker build -t mcp-claude-usage .
docker run -d -p 8000:8000 --name claude-usage mcp-claude-usage
docker exec -it claude-usage claude login

Start the server, then login via exec. Restart the container after rebuilding to login again.

Cost

Each get_usage call spawns a minimal Haiku request (~$0.00001).

Menu bar widget

claude_usage_widget.py is a macOS menu bar app that answers "when am I going to run out?" at a glance. The title takes one of three forms:

  • πŸ€– 14:32 β€” at your recent pace, the 5-hour quota runs out today at 14:32.

  • πŸ€– Th 09:15 β€” at your recent pace, the 7-day quota runs out first, on Thursday at 09:15.

  • πŸ€– β€” plain robot: you'll coast to both resets at this pace, or there aren't yet enough samples to tell (just after startup, or right after a window reset).

The title compares both windows and shows whichever is projected to run out first; each window renders in its own format (bare HH:MM for the 5-hour window, since it can't span more than a day; Day HH:MM for the 7-day window). The dropdown shows the same per-window projection β€” or, for a window that's coasting, when that window resets instead β€” plus the usage percentage for each window, the 5-hour reset time, and how stale the numbers are, with a manual refresh button below.

Unlike the MCP server above, nothing needs to be running first. The widget manages its own copy of mcp_claude_usage.py as a subprocess.

Install

macOS only β€” pulls in rumps, which is PyObjC-based and won't build on Linux:

uv sync --extra widget

Running it

uv run claude-usage-widget

or directly:

uv run python claude_usage_widget.py

Polling

Each check is a real claude CLI call and spends a small amount of actual API quota, so the widget doesn't poll on a fixed schedule. It starts at a 1-minute interval and doubles every time a check comes back with the usage number unchanged, up to a 1-hour ceiling β€” so an idle session settles down to checking once an hour. Any change in usage resets the interval back to 1 minute. "Refresh Now" in the dropdown forces an immediate check and resets the backoff too.

The burn estimate needs two samples to draw a line through, and the server normally won't spend a probe more than once every five minutes. So on a cold start (or right after a window reset), the widget forces one extra check about a minute in rather than leaving you staring at a bare robot icon while the cache runs out.

Autostart

The plist ships with this repo's own checkout path hardcoded. Edit the two ProgramArguments entries in launchd/wtf.robot.usage.plist to point at your venv's python3 and your checkout's claude_usage_widget.py, then symlink it into ~/Library/LaunchAgents (a symlink, not a copy, so future edits to the plist take effect without reinstalling) and register it with launchctl:

ln -s "$(pwd)/launchd/wtf.robot.usage.plist" ~/Library/LaunchAgents/wtf.robot.usage.plist
launchctl bootstrap gui/$(id -u) ~/Library/LaunchAgents/wtf.robot.usage.plist

RunAtLoad is set, so this also starts the widget immediately, not just on next login.

To stop it autostarting:

launchctl bootout gui/$(id -u)/wtf.robot.usage
rm ~/Library/LaunchAgents/wtf.robot.usage.plist

Logs (widget and its subprocess both) go to ~/Library/Logs/wtf.robot.usage.log.

Environment variables

  • WIDGET_MCP_PORT: Port for the widget's own mcp_claude_usage.py instance (default: 8791 β€” deliberately not the main server's 8000 default, so the two don't collide)

  • WIDGET_POLL_MIN_SECONDS: Poll interval floor, in seconds (default: 60)

  • WIDGET_POLL_MAX_SECONDS: Poll interval ceiling, in seconds (default: 3600)

License

(c) 2025 Schuyler Erle, shared under the MIT License.

Tool Schema Changelog

Recent tool additions, removals, and schema changes observed during successful MCP inspections.

Loading tool schema changelog…

    Related MCP Connectors

    Related MCP Servers

    • A
      license
      A
      quality
      B
      maintenance
      Reports your Claude subscription usage (5-hour and weekly limits) with a forecast and velocity recommendation, using Claude Code's existing OAuth session without requiring an API key.
      2
      4
      MIT
    • A
      license
      Not graded
      quality
      C
      maintenance
      Gives the model visibility into the same 5-hour session, weekly, and per-model usage percentages shown in Claude Code, along with reset times. It also lets a project cap how much of the weekly limit may be spent via start/check/end budget tools that report OK, LOW, or OVER_BUDGET.
      1
      MIT
    • A
      license
      A
      quality
      B
      maintenance
      Enables a Claude Code agent to fetch remaining 5-hour and weekly subscription usage limits, reset times, and per-window breakdowns as JSON. It provides the same figures as /usage through a local, read-only tool.
      1
      1
      MIT