AI Usage

v0.17.1
io.github.MohitBansal321/ai-usage-mcp Checked 5 hours ago Published 14 days ago

Token usage and cost from Claude Code, Codex CLI and OpenCode data.

These tools were reported by the server itself during our smoke test (tools/list), not copied from the README.

usage_summary Usage summary

Total token usage and cost for a period, split by client (Claude Code, OpenCode, Codex). Tokens are broken out into input / output / cache-read / cache-write / reasoning, because cache tokens typically dwarf input and a single blended total is misleading. Reported cost (from OpenCode) and estimated cost (computed for Claude Code and Codex, which record none) are always listed separately and must not be summed. Also reports the cache hit rate and reads-per-write, which are what say whether the cache is paying for itself -- the raw cache counts alone cannot.

ParameterTypeDescription
clientRestrict to these clients (a single id also works).
comparestringAlso report the equally long window just before this one, with the delta. Needs a fixed-length period (days, today, or since AND until); an open-ended one is rejected.
daysintegerLook back this many days, counted from local midnight. Omit for all time.
includeSubagentsbooleanInclude subagent turns. Default true: they are real spend.
modelsarrayRestrict to these model ids, as recorded (see model_usage).
projectPathstringDeprecated: use projectPaths.
projectPathsarrayRestrict to these projects: absolute working directories, matched exactly (see project_usage). A path matching nothing is reported, not answered as empty.
sincestringISO 8601 start of the period (inclusive).
todaybooleanRestrict to today, in local time.
untilstringISO 8601 end of the period (exclusive).

session_usage Session usage

Usage for one session: client, model(s), duration, token breakdown and cost. Accepts a full session id or an unambiguous fragment of one. Subagent turns are reported separately from main-thread turns.

ParameterTypeDescription
sessionId *stringSession id, or an unambiguous part of one.
includeSubagentsbooleanInclude subagent turns in the totals. Defaults to true.

model_usage Usage by model

Per-model token usage and cost, highest token count first. Use this to answer "which model consumed the most tokens". Cost is labelled reported vs estimated per model.

ParameterTypeDescription
clientRestrict to these clients (a single id also works).
daysintegerLook back this many days, counted from local midnight. Omit for all time.
includeSubagentsbooleanInclude subagent turns. Default true: they are real spend.
limitintegerRows to return.
modelsarrayRestrict to these model ids, as recorded (see model_usage).
offsetintegerRows to skip; pass `nextOffset` from the previous result.
projectPathstringDeprecated: use projectPaths.
projectPathsarrayRestrict to these projects: absolute working directories, matched exactly (see project_usage). A path matching nothing is reported, not answered as empty.
sincestringISO 8601 start of the period (inclusive).
sortstringDescending order. Reported and estimated cost are never summed, so there is no plain "cost": pick the basis you mean.
todaybooleanRestrict to today, in local time.
untilstringISO 8601 end of the period (exclusive).

client_usage Usage by client

Token usage and cost per coding agent (Claude Code, OpenCode, Codex). Note that the two cost figures are not comparable as a single number: OpenCode reports actual charged cost, while the Claude Code and Codex figures are API-equivalent estimates (a subscription has $0 marginal cost per request).

ParameterTypeDescription
daysintegerLook back this many days, counted from local midnight. Omit for all time.
includeSubagentsbooleanInclude subagent turns. Default true: they are real spend.
limitintegerRows to return.
modelsarrayRestrict to these model ids, as recorded (see model_usage).
offsetintegerRows to skip; pass `nextOffset` from the previous result.
projectPathstringDeprecated: use projectPaths.
projectPathsarrayRestrict to these projects: absolute working directories, matched exactly (see project_usage). A path matching nothing is reported, not answered as empty.
sincestringISO 8601 start of the period (inclusive).
sortstringDescending order. Reported and estimated cost are never summed, so there is no plain "cost": pick the basis you mean.
todaybooleanRestrict to today, in local time.
untilstringISO 8601 end of the period (exclusive).

project_usage Usage by project

Per-project token usage and cost, highest token count first. A project is the working directory a turn ran in. Use this to answer "which repository is my spend going to". Turns whose project could not be resolved are grouped as (unknown) rather than dropped, and cost is labelled reported vs estimated per project.

ParameterTypeDescription
clientRestrict to these clients (a single id also works).
daysintegerLook back this many days, counted from local midnight. Omit for all time.
includeSubagentsbooleanInclude subagent turns. Default true: they are real spend.
limitintegerRows to return.
modelsarrayRestrict to these model ids, as recorded (see model_usage).
offsetintegerRows to skip; pass `nextOffset` from the previous result.
projectPathstringDeprecated: use projectPaths.
projectPathsarrayRestrict to these projects: absolute working directories, matched exactly (see project_usage). A path matching nothing is reported, not answered as empty.
sincestringISO 8601 start of the period (inclusive).
sortstringDescending order. Reported and estimated cost are never summed, so there is no plain "cost": pick the basis you mean.
todaybooleanRestrict to today, in local time.
untilstringISO 8601 end of the period (exclusive).

daily_usage Usage by day

Token usage and cost bucketed on the time axis, newest first. Use this for "how much did I use yesterday", for a trend over a period, or -- with grain "hour-of-day" -- for "when during the day do I burn tokens". Buckets with NO activity are included and flagged `zeroFilled`, because omitting them hides the gaps and makes an ordinary bucket look like a spike beside one weeks earlier. All buckets are local time, so they agree with the period filter rather than drifting by a timezone offset. Cost is labelled reported vs estimated per bucket.

ParameterTypeDescription
clientRestrict to these clients (a single id also works).
daysintegerLook back this many days, counted from local midnight. Omit for all time.
grainstringTime bucket, local time (default day). "hour-of-day" folds every day onto one 24-slot clock: "when during the day do I burn tokens".
includeSubagentsbooleanInclude subagent turns. Default true: they are real spend.
modelsarrayRestrict to these model ids, as recorded (see model_usage).
projectPathstringDeprecated: use projectPaths.
projectPathsarrayRestrict to these projects: absolute working directories, matched exactly (see project_usage). A path matching nothing is reported, not answered as empty.
sincestringISO 8601 start of the period (inclusive).
todaybooleanRestrict to today, in local time.
untilstringISO 8601 end of the period (exclusive).

usage_breakdown Usage broken down by two dimensions

Token usage and cost cut by two or more dimensions at once -- project x day, model x day, client x day -- as one tidy row set. Use this for "which of my projects is getting more expensive", which the single-axis tools cannot answer: project_usage gives a total with no trend, and daily_usage narrowed to one project gives one series, so answering it otherwise means enumerating projects and issuing one call each. Combinations with no activity are absent rather than returned as zero rows. Cost stays labelled reported vs estimated per row and the two are never summed.

ParameterTypeDescription
axes *arrayDimensions to cross, in output order: client, model, provider, project, session, day, hour, hour-of-day. At most 3, and each at most once. The time axes bucket in local time, identically to daily_usag…
clientRestrict to these clients (a single id also works).
daysintegerLook back this many days, counted from local midnight. Omit for all time.
includeSubagentsbooleanInclude subagent turns. Default true: they are real spend.
limitintegerRows to return.
modelsarrayRestrict to these model ids, as recorded (see model_usage).
offsetintegerRows to skip; pass `nextOffset` from the previous result.
projectPathstringDeprecated: use projectPaths.
projectPathsarrayRestrict to these projects: absolute working directories, matched exactly (see project_usage). A path matching nothing is reported, not answered as empty.
sincestringISO 8601 start of the period (inclusive).
sortstringDescending order. Reported and estimated cost are never summed, so there is no plain "cost": pick the basis you mean.
todaybooleanRestrict to today, in local time.
untilstringISO 8601 end of the period (exclusive).

counterfactual_cost Cost on another model

What the tokens from a period would have cost at another model’s list rates, alongside what they actually cost. Use this for "would Sonnet have been cheaper than Opus for this". It re-prices the exact token counts that were recorded, grouped by client, model and speed so the fast-mode premium and the two different reasoning-token conventions are handled correctly. Also reports what the same tokens would have cost with NO prompt caching at all, per model -- which is the figure that says whether caching is paying for itself. IMPORTANT: the model scenarios are a counterfactual, not a saving —…

ParameterTypeDescription
clientRestrict to these clients (a single id also works).
daysintegerLook back this many days, counted from local midnight. Omit for all time.
filterModelsarrayRestrict which turns are included, by model id -- the same scope filter other tools spell `models`. Named apart here because `models` already meant "price against these" on this tool. Use both togethe…
includeSubagentsbooleanInclude subagent turns. Default true: they are real spend.
modelsarrayDeprecated spelling of targetModels. Still honoured.
projectPathstringDeprecated: use projectPaths.
projectPathsarrayRestrict to these projects: absolute working directories, matched exactly (see project_usage). A path matching nothing is reported, not answered as empty.
sincestringISO 8601 start of the period (inclusive).
targetModelsarrayModels to price the selected tokens AGAINST. Not a filter on which turns are included -- that is `filterModels`. Omit to compare every model the pricing table knows. A model with no price is omitted a…
todaybooleanRestrict to today, in local time.
untilstringISO 8601 end of the period (exclusive).

cache_health Cache Health

Finds cache breaks in a session -- turns where the prompt-cache prefix was not reused, so the context was re-written at cache-write prices instead of read back cheaply. A break is a spike in cache writes AND a drop in cache reads; a write spike alone (e.g. reading one large file) is not one. Each break lists the turn, token counts, likely cause (model or speed switch, idle past the 5-minute TTL, or an early-context change such as an edited CLAUDE.md), and its API-equivalent write premium from the pricing table. Also returns the overall cache hit rate and reads-per-write.

ParameterTypeDescription
sessionId *stringSession ID (full or unambiguous prefix) to analyze.
baselineWindowintegerNumber of previous turns to average for the baseline.
includeSubagentsbooleanAlso analyze subagent/sidechain turns, baselined separately from main turns since they keep their own cache. Defaults to false.
minCacheWritesintegerMinimum absolute cache writes on a turn to consider (filters noise).
spikeThresholdnumberMinimum spike ratio (current writes / rolling average) to flag as a break.

usage_report Usage report

Where a period of usage went, how much of it did no new work, and what to change -- the first thing to run for "where are my tokens going" or "why do I hit my limit". Gives a verdict, the share of usage spent re-reading large contexts (every message re-sends the whole conversation) and rebuilding a lost prompt cache, the heaviest sessions by their own titles and git branches, usage per branch, and plain-language fixes. Shares are weighted by API-equivalent list price as a relative measure; on a subscription that figure is not money spent. Defaults to the last 7 days.

ParameterTypeDescription
clientRestrict to these clients (a single id also works).
daysintegerLook back this many days, counted from local midnight. Omit for all time.
includeSubagentsbooleanInclude subagent turns. Default true: they are real spend.
modelsarrayRestrict to these model ids, as recorded (see model_usage).
projectPathstringDeprecated: use projectPaths.
projectPathsarrayRestrict to these projects: absolute working directories, matched exactly (see project_usage). A path matching nothing is reported, not answered as empty.
sincestringISO 8601 start of the period (inclusive).
todaybooleanRestrict to today, in local time.
untilstringISO 8601 end of the period (exclusive).

plan_usage Plan Usage

How much of the Claude Pro/Max 5-hour and weekly usage limits is used, as Claude Code itself last reported it, with when each window resets. Also the average pace within the window and the time it would reach 100% at that pace (a projection, labelled as one), and the tokens and API-equivalent cost of this machine's Claude Code turns since the window began. The percentages are recorded only while `ai-usage statusline` is configured as the Claude Code status line; without it they are reported as unavailable, never as 0%. Answers "how close am I to my limit" and "will I run out before it resets".

ParameterTypeDescription
includeSubagentsbooleanCount subagent turns in this machine's token figures. Defaults to true. Does not affect the percentages, which are Claude Code's own.

recent_sessions Recent sessions

Most recently active sessions with project path, client, model(s), duration, token breakdown and cost. Use the returned session id with session_usage for detail.

ParameterTypeDescription
clientRestrict to these clients (a single id also works).
daysintegerLook back this many days, counted from local midnight. Omit for all time.
includeSubagentsbooleanInclude subagent turns. Default true: they are real spend.
limitintegerRows to return.
modelsarrayRestrict to these model ids, as recorded (see model_usage).
offsetintegerRows to skip; pass `nextOffset` from the previous result.
projectPathstringDeprecated: use projectPaths.
projectPathsarrayRestrict to these projects: absolute working directories, matched exactly (see project_usage). A path matching nothing is reported, not answered as empty.
sincestringISO 8601 start of the period (inclusive).
sortstringDescending order. Reported and estimated cost are never summed, so there is no plain "cost": pick the basis you mean.
todaybooleanRestrict to today, in local time.
untilstringISO 8601 end of the period (exclusive).