Reports real token usage and cost from Claude Code and OpenCode data. Nothing leaves your machine.
Copy the AI prompt to install this server into Claude Code, Cursor, or another agent β or use 1-click editor setup below.
π‘ Paste the JSON block into your client's configuration file under mcpServers, then restart the application.
A local-first MCP server that answers, from real data on your machine:
How many tokens have I used, from which client, model and session β and what did it cost?
Phase 1 supports two coding agents: Claude Code and OpenCode. It reads the data those clients already wrote to disk, normalises it into one schema, stores it in a local SQLite database, and exposes seven MCP tools -- plus resources, prompts and a debug CLI.
It never fabricates a number. If a source does not record something, it is reported as unavailable β not as zero.
Requires Node.js 22.13+. No compiler, build tools or particular npm version needed:
storage uses Node's built-in node:sqlite, which is unflagged from 22.13.0 onward. There is
no mandatory native dependency.
better-sqlite3 remains an optional fallback for hosts whose Node predates
that. It is never required β if it cannot be built, npm skips it and the server still runs.
Nothing to install first β npx fetches it on demand:
-s user makes it available in every project. Drop it to add the server to the current
project only. Then run /mcp inside Claude Code to confirm it connected.
claude command? (VS Code / JetBrains extension users)The extension reads the same configuration as the CLI, so you can add the server by editing a file β no CLI needed. Pick whichever scope you want:
For one project β create .mcp.json in the project root:
Claude Code asks you to approve a project-scoped server the first time it loads it. This file is safe to commit if you want your team to get it too.
For all your projects β add the same mcpServers block at the top level of
~/.claude.json (%USERPROFILE%\.claude.json on Windows):
That file already exists and holds other settings β add the mcpServers key alongside them
rather than replacing the file.
Then reload the window (Developer: Reload Window in VS Code) and run /mcp. Configuration
is read when a session starts, so an already-open session will not pick it up.
Or add it to ~/.config/opencode/opencode.jsonc:
Confirm with opencode mcp list.
The MCP server needs no install. To also get the ai-usage CLI on your PATH:
Or run it without installing:
Windows: no longer needs a particular npm. The
node-gypfailure that used to break this install came from the nativebetter-sqlite3dependency, which is now optional and unused on Node 22.13+. If npm still reports a build failure for it, that message is a skipped optional dependency, not a failed install βai-usage statuswill showSQLite driver: node:sqliteand everything works.
Verified against Claude Code 2.1.251 and OpenCode 1.18.25.
npx -y ai-usage-mcp β the form the instructions above use β re-resolves the version every
time your client cold-starts the server, so it keeps itself current. Restart the client to pick
up a new release.
A global install is pinned until you update it by hand:
ai-usage status tells you when you are behind:
The MCP server says so too, because most people never run the CLI. When the server finds a
newer release it says it once per process, through whichever channel comes first: a line
added to the instructions it returns at handshake time, or a one-off note attached to the
next tool result. It is a separate content block, so the numbers a tool returns stay exactly
what the CLI prints for the same query, and it never repeats itself on later calls. The same
line goes to the server's stderr log, and @usage://status shows the state on demand.
The advice differs by how you installed it, and the notice says the right one:
| Installed as | What actually fixes it |
|---|---|
npm i -g ai-usage-mcp | npm i -g ai-usage-mcp@latest |
npx -y ai-usage-mcp | Restart the server -- npx re-resolves on a cold start |
| A version pinned in your MCP config | Change it there; no command will do it for you |
| A project dependency | npm i ai-usage-mcp@latest |
| A source checkout | git pull && npm run build |
That check is the only network call in the package: a version lookup against the npm registry,
at most once a day, cached in <config dir>/update-check.json, skipped when CI is set, and
silently abandoned after 1.5s if you are offline. It sends no usage data and no identifier --
just a GET for a version string. Set AI_USAGE_NO_UPDATE_CHECK=1 to turn it off everywhere,
CLI and server alike. In the server it runs after the handshake, never during it, so it
cannot slow down a client starting up.
Once connected, ask in plain language:
| Tool | Returns |
|---|---|
usage_summary | Totals for a period, split by client, tokens + cost |
session_usage | One session: client, model, duration, token breakdown, cost |
model_usage | Per-model tokens and cost |
client_usage | Per-client (Claude Code vs OpenCode) tokens and cost |
recent_sessions | Recent sessions with project, client, tokens, cost |
project_usage | Per-project tokens and cost, by the directory a turn ran in |
daily_usage | Per-day tokens and cost, newest day first |
Every period-based tool takes projectPath to narrow the report to one project.
Three resources can be pulled into a conversation with an @ mention, instead of asking for a
tool call:
| Resource | Contents |
|---|---|
usage://today | Today's totals, split by client |
usage://session/latest | The most recent session in detail |
usage://status | Which build is answering, its sources, and whether it is stale |
Three prompts appear as slash commands in a client that surfaces them:
| Prompt | Asks |
|---|---|
daily-review | What did I spend today, and on what |
why-was-today-expensive | Which model, session and project drove today's cost |
project-cost | What one project has cost over a period |
Each prompt names the tools to call and carries the reported-vs-estimated cost rule with it, so a paraphrased summary cannot quietly merge the two cost bases.
Same service layer, different frontend β so the two can never disagree.
Add --json to any command for machine-readable output, and --project <path> to any
period-based command to restrict it to one project.
ai-usage stats --today returns exactly what the usage_summary tool returns; a test in
tests/mcp/parity.test.ts asserts they are byte-identical.
Cost is never a single blended number. Every figure carries a basis:
No reviews yet β be the first to share how this listing worked for you.
Showcase your server listing on GitHub or your project documentation. Embed this dynamic SVG badge to highlight official listing status and live engagement.
[](https://allmcps.com/mcp/ai-usage)<a href="https://allmcps.com/mcp/ai-usage"><img src="https://allmcps.com/api/badge/ai-usage?style=directory" alt="AI Usage on AllMCPs" /></a>