claude-usage
Provides Claude plan usage data (session and weekly percentages) as an MCP tool by reading through a logged-in browser, enabling Claude to check its own remaining usage.
README
claude-usage
Read your Claude plan usage from the command line, or as an MCP tool.
These are the numbers behind claude.ai's "Current session" and "Weekly" meters. Anthropic publishes no API for them, so this reads them through a browser you are logged into. See How it works.
$ ./usage
{
"status": "ok",
"session_pct": 14.0,
"session_resets_at": "2026-08-07T18:00:00Z",
"weekly_pct": 38.0,
"weekly_resets_at": "2026-08-08T07:00:00Z",
"blocking": [],
"credits_enabled": false,
"credits_spent": 0.0,
"credits_limit": null,
"source": "browser"
}
Features
- CLI printing JSON, exit 0 on success and 1 on failure
- MCP tool, so Claude can check its own remaining usage
- Works on Windows, macOS and Linux
- Docker optional — needed only on machines without a screen
- No API key, no cookie extraction, no browser download
Requirements
- Python 3.9+
- A browser (Chrome, Chromium or Edge), or Docker on a headless machine
- A machine that stays on, since the browser has to keep running
- One manual login, repeated roughly monthly when the session expires
Install
git clone https://github.com/AlbeeDev/claude-usage.git
cd claude-usage
Then follow A if the machine has a screen, or B if it does not.
A. Machine with a screen
python3 -m venv .venv
.venv/bin/pip install -r requirements.txt
./usage
Windows:
py -3 -m venv .venv
.venv\Scripts\pip install -r requirements.txt
usage
The first run finds a browser and starts one:
$ ./usage
No browser is running. Starting one...
Started /usr/bin/google-chrome
Log into claude.ai in the window that opened, leave it running,
then run this again.
Log in, leave the window open, run ./usage again.
B. Headless machine (Docker)
The container provides the screen you log in through.
docker compose up -d
Then forward the port from your own machine and open http://localhost:3000:
ssh -L 3000:localhost:3000 you@your-server
Log into claude.ai there. Back on the server:
python3 -m venv .venv
.venv/bin/pip install -r requirements.txt
./usage
The Chromium image is about 4.6 GB. Check you have the disk.
Anything that can reach port 9222 controls a browser signed into your Claude account — it can read your conversations, act as you on any site that browser is logged into, and take its cookies. There is no authentication on that port; that is how the debug protocol works. All ports bind to
127.0.0.1for this reason. Do not republish them on0.0.0.0, and treat any machine where you do not trust every local user as unsuitable.
Put it on PATH
To call it from anywhere, or from another program:
./usage --add-to-path
$ cd /anywhere && claude-usage
{"status": "ok", "session_pct": 15.0, ...}
It links into a directory already on your PATH — /usr/local/bin as root,
~/.local/bin otherwise — and prints where it went. On Windows it writes a
small .bat shim instead, since symlinks there need admin rights.
It is a link, not a copy, so updating the repo updates the command, and the venv and browser profile are still found. To remove it, delete the file it names. It will not overwrite a file it did not create.
Usage
./usage # print usage as JSON
./usage --login # open claude.ai in the running browser, to sign in again
./usage --register-mcp # register the MCP server with Claude Code
./usage --add-to-path # install as claude-usage, runnable from anywhere
On Windows, usage instead of ./usage.
MCP
./usage --register-mcp
Registers the server for all projects and prints what it wrote. Start a new
Claude session to pick it up. Claude then gets a claude_usage tool returning
status, session_pct and resets_at.
To register by hand, point command at the Python inside .venv — an MCP
client runs a command, it does not activate anything:
{
"mcpServers": {
"claude-usage": {
"type": "stdio",
"command": "/path/to/claude-usage/.venv/bin/python",
"args": ["/path/to/claude-usage/mcp_server.py"]
}
}
}
On Windows the interpreter is .venv\Scripts\python.exe.
The tool reads the browser but never starts one. If none is running it returns
browser_unavailable; start it with ./usage.
Output
| Field | Meaning |
|---|---|
status |
ok, or why the reading failed |
session_pct |
Percent of the 5-hour window used |
session_resets_at |
When that window rolls over |
weekly_pct |
Percent of the weekly limit used |
weekly_resets_at |
When the week rolls over |
blocking |
Active critical limits, which may name a specific model |
credits_enabled |
Whether extra usage credits are on |
credits_spent / credits_limit |
Credit spend, if enabled |
source |
Always browser |
blocking can name a model that is exhausted while both percentages still look
healthy.
Failure statuses
All exit 1, with the reason in status and detail in detail.
| Status | Meaning | Fix |
|---|---|---|
unauthenticated |
The login expired | ./usage --login, then sign in |
browser_unavailable |
No browser reachable | ./usage, or docker compose up -d |
blocked |
Cloudflare did not clear | Usually temporary; retry |
request_failed |
Endpoint changed, or another error | Read detail |
A response the digest does not recognise is reported as request_failed, never
as ok with null percentages — a null renders as 0%, which reads as plenty of
headroom and is the opposite of the truth. Treat every reading as best-effort
and show "usage unavailable" rather than zero.
Configuration
| Variable | Default | Purpose |
|---|---|---|
USAGE_CDP_URL |
http://localhost:9222 |
Where the browser is |
USAGE_CDP_URL=http://other-host:9222 ./usage
Behaviour
- Results are cached for 60 seconds; polling is cheap.
- Concurrent callers are serialised with a file lock on macOS and Linux. Windows has no such lock, so the cache is the only guard there.
- One claude.ai tab is opened on first use and reused after, so nothing opens, navigates or takes focus while you work.
- On Windows the browser starts minimised once a profile exists. The first run stays visible, because that is the run you log in on.
- The browser uses its own profile directory, not your everyday one. A browser with debugging enabled can be driven by anything else on the machine.
- Closing the browser does not lose the login — it is on disk.
./usagestarts it again.
How it works
Anthropic publishes no API for plan usage. The only source is the endpoint claude.ai's own settings page calls, which needs your session — and Cloudflare rejects any client that is not a real browser.
Cookies alone are not enough, which is worth knowing before trying the obvious shortcut:
- An HTTP client with valid cookies gets
403andcf-mitigated: challenge. - A freshly minted
__cf_bmdoes not change that. - Neither does replaying a complete browser header set.
- Chrome's new headless mode is challenged too, while the same browser visible is not.
What is fingerprinted is the client itself. So a browser you are logged into
stays running, and usage.py connects to it and runs the fetch from inside a
claude.ai tab — the same request the settings page makes. No cookie is copied
out and no browser is launched behind your back.
This reads your own account through your own session. No API key, no token, nothing sanctioned, and therefore best-effort. Do not build anything critical on it.
Tests
./test_usage.py # or: pytest
Covers the digest and the debugger address. No browser or network needed.
License
MIT — see LICENSE.
推荐服务器
Baidu Map
百度地图核心API现已全面兼容MCP协议,是国内首家兼容MCP协议的地图服务商。
Playwright MCP Server
一个模型上下文协议服务器,它使大型语言模型能够通过结构化的可访问性快照与网页进行交互,而无需视觉模型或屏幕截图。
Magic Component Platform (MCP)
一个由人工智能驱动的工具,可以从自然语言描述生成现代化的用户界面组件,并与流行的集成开发环境(IDE)集成,从而简化用户界面开发流程。
Audiense Insights MCP Server
通过模型上下文协议启用与 Audiense Insights 账户的交互,从而促进营销洞察和受众数据的提取和分析,包括人口统计信息、行为和影响者互动。
VeyraX
一个单一的 MCP 工具,连接你所有喜爱的工具:Gmail、日历以及其他 40 多个工具。
graphlit-mcp-server
模型上下文协议 (MCP) 服务器实现了 MCP 客户端与 Graphlit 服务之间的集成。 除了网络爬取之外,还可以将任何内容(从 Slack 到 Gmail 再到播客订阅源)导入到 Graphlit 项目中,然后从 MCP 客户端检索相关内容。
Kagi MCP Server
一个 MCP 服务器,集成了 Kagi 搜索功能和 Claude AI,使 Claude 能够在回答需要最新信息的问题时执行实时网络搜索。
e2b-mcp-server
使用 MCP 通过 e2b 运行代码。
Neon MCP Server
用于与 Neon 管理 API 和数据库交互的 MCP 服务器
Exa MCP Server
模型上下文协议(MCP)服务器允许像 Claude 这样的 AI 助手使用 Exa AI 搜索 API 进行网络搜索。这种设置允许 AI 模型以安全和受控的方式获取实时的网络信息。