mcp

v0.9.13
@agent-finops/mcp Checked 4 days ago Published 1 month ago

Local MCP server for Tilden’s aibill CLI: inspect coding-agent usage, cost evidence and Context Health from a compatible AI client.

Inspect Claude Code and Codex activity on your machine, see its estimated value at published API rates, and find what deserves a closer look. Add supported provider cost reports when you need billing evidence. Estimates, reported costs and missing data stay separate. Free and MIT-licensed. Node.js 22+. No account or provider key is needed for the local workflow. aibill is the short command for the same ai-spend-agent CLI. CLI guide · Source coverage · Workspace sharing

Summary extracted from the README.

aibill — Tilden’s free AI spend CLI

CI npm version MIT license node >=22

Understand your coding-agent usage before you mistake it for a bill.

Inspect Claude Code and Codex activity on your machine, see its estimated value at published API rates, and find what deserves a closer look. Add supported provider cost reports when you need billing evidence. Estimates, reported costs and missing data stay separate.

npx aibill@latest init

Free and MIT-licensed. Node.js 22+. No account or provider key is needed for the local workflow. aibill is the short command for the same ai-spend-agent CLI.

CLI guide · Source coverage · Workspace sharing

This public repository contains the free CLI, its shared libraries, and Glance for macOS.

Use aibill on its own or with Workspace. Start with a free local review, without an account. If you already use Tilden Workspace, keep working locally and, as the Workspace owner, connect your CLI to explicitly share supported coding activity into your spending review. Connect your CLI to Workspace.

Get started

Run these from a project directory:

npx aibill@latest init       # first receipt; scans supported local financial evidence
npx aibill@latest --full     # inspect the evidence and its coverage

init looks back 30 days across supported local agent records on the machine. The current project selects where project state lives; it does not limit the scan to that project. It preserves existing connector and audit state and seeds the private Claude Code/Codex status cache. It does not change Claude settings or connect Workspace.

Read the basis beside each number: API-equivalent value is an estimate, not your subscription charge or invoice. A missing price or token component stays missing. If supported records are absent, the CLI says so and offers a diagnostic step; it never substitutes demo dollars.

Want to inspect the format first?

npx aibill@latest --sample   # labeled illustrative data

Local analysis does not send transcripts to Tilden. The CLI can send command-count events after its first interactive notice. Disable them with npx aibill@latest telemetry off or set AI_SPEND_NO_TELEMETRY=1 before running. Optional sharing paths are explained in Privacy & trust.

Who it helps and what to do next

Your job Start here What you can learn
Developer using Claude Code or Codex: understand a heavy week npx aibill@latest --full Observed usage, API-rate estimates and reported plan limits where available. These do not establish what your subscription billed.
Founder or engineering lead: explain which projects need investigation npx aibill@latest --group-by project Project activity where local working-directory evidence supports it; missing attribution stays visible. This is the current machine’s evidence, not a team census.
Developer: investigate context and test one bounded change npx aibill@latest context, then npx aibill@latest improve Context evidence and a guided comparison of matched completed sessions. A token change requires user-declared quality; it is not cash savings or ROI.
Agency or team with provider admin access: prepare a cost discussion npx aibill@latest connect openai or connect anthropic Setup for a separate, explicit provider sync. Grouping by client, user or workspace works only where the source or confirmed mapping supplies that dimension.

Why use this alongside provider dashboards?

Provider reports answer what that source recorded. Local transcripts help explain coding activity on your machine. aibill puts the available evidence in one local review while preserving the difference between them. It shows source, freshness and gaps so you can decide what to investigate without treating token volume as a reconciled bill.

It does not sit in the inference path, route your requests or change providers. It cannot infer a person’s billed cost, business value or productivity from activity alone.

Local estimates and provider reports

CLI label Meaning
verified Source-authoritative provider-reported cost or usage from an authenticated API/export; not necessarily the final invoice.
estimated A calculated or qualified value. Local transcript values use published API rates and are not subscription charges.
detected_unverified A detected signal that has not been reconciled against billing.
missing The evidence does not support a value; missing does not mean zero.

Reader validation is separate. live_verified and fixture_verified describe how a reader or connector was exercised, not whether every number is a bill. npx aibill@latest doctor --sources shows validation, financial evidence, freshness and recorded errors. Permission to read a folder is not verification of its contents.

Data sources

Local CLI source Current boundary
Claude Code and Codex Supported local readers; live_verified. Usage with a supported price basis is estimated, otherwise missing. Reported plan windows appear only when present.
Gemini CLI Experimental, fixture_verified reader for supported chats JSON/JSONL. Financial CLI/report only; excluded from statusline, Glance, Context Health, Apply, recommendations and plan/runway. logs.json is detection-only.
OpenAI Costs/Usage APIs Optional admin-gated connector with non-empty live verification. Evidence depends on endpoint; invoice adjustments and source coverage remain separate.
Anthropic Cost Report / Claude Code Analytics Optional admin-gated connector with non-empty live verification. Evidence and available dimensions depend on the returned rows.
Cursor Admin / GitHub Copilot organization APIs Optional, fixture-verified beta connectors requiring appropriate admin access. Real-account acceptance remains pending.
Other local agents or providers No implied support. Request a source with the decision it would help you make.

A model in the price table is not a connector. Planned providers are not available integrations. CLI support does not automatically enable a source in Workspace. Historical coverage depends on the source and retained records. See the generated local format reference, provider contracts and Workspace coverage.

The OpenAI CLI connector reads organization Costs and completions Usage; it does not read ChatGPT/Codex seat or subscription invoices. The Anthropic CLI connector reads Cost Report and Claude Code Analytics, not every surface in the provider’s API contract. Enterprise Analytics and third-party-hosted activity are outside those implemented endpoints. Final credits, tax, discounts and settlement remain separate from reported API costs.

Connect provider cost and usage

Provider setup is optional and separate from Workspace pairing:

npx aibill@latest connect openai
# Or: npx aibill@latest connect anthropic

connect registers a local connector and prints the next sync-provider command. It does not fetch billing data. Review that command, supply the required admin credential through a local environment-variable reference such as --auth-reference env:OPENAI_ADMIN_KEY, then run the explicit sync. The credential is used with the selected provider’s official read-only API; it is not persisted in aibill state or sent to Workspace by this command.

Provider records are stored locally for the CLI review. They are not uploaded by workspace push. Set up hosted provider connections separately in Workspace. Local estimates do not become invoice line items after connecting.

Choose your next local step

Need Command or guide
Inspect current context npx aibill@latest context
Prepare an inspection and approval plan npx aibill@latest apply writes local artifacts; it does not execute the change.
Test one reversible change npx aibill@latest improve; practice with improve --sample, which writes nothing. You type approval, perform the change and supply the quality check.
Keep a compact view in Claude Code npx aibill@latest statusline install; uninstall with statusline uninstall. Installation is optional; the runner only rereads a private cache.
Keep a repository inside a daily agent budget Commit .aibill/policy.json, then npx aibill@latest guard install; see Guard.
Save a local report npx aibill@latest report --no-open
Prepare a redacted receipt for sharing npx aibill@latest report-card; inspect the output before sharing.
Explore a native monitor Glance for macOS, a source-built preview; no signed public download yet.

Full command reference and experiment limits. The guided experiment compares matched completed Claude Code/Codex session snapshots and requires declared quality. It does not automatically optimize requests, certify outcomes or prove ROI. Ownership and GitHub outcome commands record explicitly supplied or narrowly checked evidence, not company approval routing or automated business-value measurement.

Guard: policy for coding agents

aibill guard turns a committed policy file into Claude Code settings and a hook, per repository and never per person. Run npx aibill@latest guard status in the checkout first: it shows today's figures, and the numbers are larger than intuition suggests, because tokens counts every component and cache reads dominate (one busy repository measured about 390M tokens in a day, 96% of them cache reads, against a few million output tokens). Then write .aibill/policy.json at the checkout root:

{
  "version": 1,
  "models": { "allow": ["sonnet", "haiku"] },
  "budget": { "perDay": { "tokens": 400000000, "outputTokens": 4000000, "sessions": 20 } },
  "message": "This repository's daily agent budget is spent. Ask the platform team for an exception."
}

Then run npx aibill@latest guard install in the checkout Claude Code will start in and commit what it writes. Two files change:

  • .claude/settings.json (Claude Code shared project settings) gains availableModels from models.allow and one command hook on UserPromptSubmit. Add "perToolCall": true to the policy, or pass --per-tool-call, to hook PreToolUse as well; that costs about a tenth of a second per tool call, so it is off by default. Keys that were already there stay as they were; rerunning install changes nothing; guard install --uninstall removes exactly what install added.
  • .aibill/guard-hook.mjs, the hook the settings point at with node "${CLAUDE_PROJECT_DIR}/.aibill/guard-hook.mjs". It runs aibill guard check from the ai-spend-agent package the checkout declares in its package.json (npm install --save-dev aibill), else from a global install it can find: the npm prefix from npm_config_prefix or ~/.npmrc, Volta's package images, the running Node's prefix, or %APPDATA%\npm on Windows, with npm i -g aibill (which nests ai-spend-agent) covered. No npx, no network. When none is found it warns, names the roots it looked in, and lets the prompt through; guard status shows which package the hook would run.

In a linked worktree, install writes into the worktree, because that is where Claude Code reads the shared settings from; the policy and the day's figures belong to the main checkout, and the install output says so.

What it enforces: the model allowlist applies as soon as Claude Code loads the project settings (model limits are the settings' job, availableModels and deniedModels; the hook does not look at models). The hook reads today's Claude Code usage for this repository from the transcripts already on the machine (the UTC day's tokens, output tokens and distinct sessions; a linked worktree counts toward its main checkout) and exits 2 with the policy message and the figure when a budget is spent, which blocks the prompt or tool call:

This repository's daily agent budget is spent. Ask the platform team for an exception.
checkout-api used 410M tokens of its 400M daily budget (UTC 2026-11-04); paused until 00:00 UTC (in 5h12m). aibill guard

The hook fails open: it never blocks a developer on uncertain or stale data. On a missing or invalid policy, a transcript directory it cannot read, hook input it could not parse (the sessions rule then waits for the next prompt while the token rules still apply), or an index still catching up with a large day, it exits 0 with one warning line and the developer continues. A transcript rewritten in place is detected and read again from the start. A line whose token shape the parser does not support counts its present components only, so every figure is a lower bound. A warm run reads only the bytes transcripts gained since the last run, and a run whose verdict cannot have changed exits before loading anything: about 0.05 s when nothing changed, 0.1 s on a recompute, and up to about a second the first time of the day, per prompt (and per tool call when opted in).

npx aibill@latest guard status prints the policy in force, today's figures against it, what is installed where (including which ai-spend-agent the hook would run), and whether managed settings override.

Honest limits. Project settings are a convention: a developer can edit .claude/settings.json, and Claude Code runs project hooks only after the developer trusts the folder. Organizations that need enforcement deploy the same policy as managed settings, which win over every other scope: npx aibill@latest guard install --managed prints that document, including deniedModels from models.deny (a managed-only key that project scope can only report); its hook command is POSIX shell (sh -c, Git Bash on Windows). Model lists match the way Claude Code documents (opus covers the family, claude-opus-5 covers later minor versions). codex.model is reported, not enforced. Nothing here reads provider billing or acts on a provider account; that half lives in Tilden Workspace.

Optional Workspace connection

The CLI includes an optional client for an existing invited Workspace. Confirming the repository in workspace connect, described below, is prepared for the unreleased 0.9.20 version in this checkout; see the changelog. Hosted provider collection and Workspace rollout are separate from this CLI release.

To connect, run npx aibill@latest workspace connect. Inside a Git checkout it asks you to confirm that repository, so a Workspace with self-service machine setup can prepare the connection itself; workspace connect --prepared makes the earlier kind of request, for a machine an administrator prepared. Then complete enrollment and sharing consent in Workspace Settings → Machines, and accept the first-push offer or run npx aibill@latest workspace push to preview and share supported activity. For optional daily uploads, run npx aibill@latest workspace push --schedule daily and review its separate standing-consent prompt. Remove them with npx aibill@latest workspace push --schedule none; manual pushes keep their preview. The browser is needed for setup; it does not need to stay open for later pushes while the machine’s grant and sharing consent remain valid.

Shared activity includes eligible Claude Code/Codex session and token counts, project labels where available, hashed directory references and up to 1,024 device-keyed session identities per daily fact. Raw transcripts and dollar amounts stay out of that upload; provider billing is connected separately. See the setup and sharing guide for the supported dates, data fields and recovery steps.

Privacy & trust

  • Local analysis: transcript processing runs on your machine. Project state lives in .ai-spend-agent/; caches, trust receipts and pairing state use ~/.aibill/. Saved reports remain local until you share them.
  • Telemetry: command-count events can begin only after a notice was shown on an interactive run. The payload includes a random installation ID and operational fields, not command arguments, paths, prompts, project names, dollar amounts or email. Events can be linked to the same installation. npx aibill@latest telemetry shows the exact last payload; telemetry off or AI_SPEND_NO_TELEMETRY=1 disables it. See the full disclosure.
  • Provider sync: an explicit read uses the local environment credential reference with that provider. aibill never sits in the inference path and never stores, prints, or proxies provider credentials.
  • Workspace: pairing is optional; each manual push requires consent to the outgoing facts. workspace push --schedule daily separately opts in to daily uploads without per-batch prompts; --schedule none removes that consent. Project labels may be shared, and a push previews and can send the subscription tier each agent is signed in with, in its own batch when no session fact changed (seven fields, never an account, email or token; AIBILL_NO_PLAN_TIER=1 leaves it out). Device credentials stay in private local pairing state. Disconnect revokes future machine access; accepted facts expire from hosted reads after the retention period shown for the machine's sharing policy in Settings → Machines. A later accepted revision starts that fact's retention period again. Expiry from reads and disconnect do not promise physical deletion; see the sharing guide.
  • Other explicit network actions: outcome github asks the installed gh CLI for merged-PR evidence. The optional signup command sends the displayed email/ref payload only after confirmation. Normal HTTP metadata accompanies network requests. See Tilden’s privacy policy.

Contribute or build from source

git clone https://github.com/futurastudio/ai-spend-agent
cd ai-spend-agent
npm ci
npm run build
node packages/cli/dist/index.js --help

Read CONTRIBUTING.md for checks and synthetic-fixture rules. Report a bug or source request without private transcripts or credentials. Developers integrating the evidence engine can use the supported library preview.

License

MIT © Futura Studio LLC