MCP TokenSage
Analyzes token usage and costs from GitHub Copilot CLI interactions.
Tracks token usage and costs from OpenAI Codex CLI sessions.
Tracks token usage and costs from OpenCode (SST) AI coding agent sessions.
Collects aggregate usage and spend data from Warp terminal's AI features.
Click on "Install Server".
Wait a few minutes for the server to deploy. Once ready, it will show a "Started" state.
In the chat, type
@followed by the MCP server name and your instructions, e.g., "@MCP TokenSageCount tokens in 'Hello world' using gpt-4"
That's it! The server will respond to your query, and you can continue using it as needed.
Here is a step-by-step guide with screenshots.
XLab Token
Local-first token API usage & cost tracker for every AI agent on one machine.
XLab Token is an npm package that runs a lightweight localhost service and dashboard. It aggregates token API consumption and estimated spend (cost) from all AI coding agents and CLIs installed on the host — including Cursor, Grok, Windsurf, Codex, Claude Code, and more — so you always know how many tokens each agent used and how much it cost.
No cloud account required by default. Data stays on your machine.
Table of contents
Related MCP server: nikhilnt
What it tracks
Dimension | Details |
Token API usage | Input, output, cache-read, cache-write tokens per request / session |
Spend (cost) | Estimated USD (or configured currency) from model pricing × tokens |
By agent | Cursor, Grok, Windsurf, Codex, Claude Code, … |
By model | e.g. |
By time | Hour / day / week / custom range |
By workspace | Project path when available in agent logs |
Primary questions answered
How many tokens did all agents on this PC use today / this month?
Which agent burned the most tokens and money?
Which models drive the highest cost?
What is the running total spend across every local agent?
Why
Modern machines often run multiple AI agents in parallel. Each tool stores usage in a different path and format. Without one local aggregator:
Pain point | Impact |
Fragmented token logs | No machine-wide token total |
Opaque spend | Cannot see real API cost across agents |
No cross-agent ranking | Hard to know which tool is expensive |
Cloud-only dashboards | Privacy / offline limits |
XLab Token scans local agent usage artifacts, normalizes them into one schema, computes token totals + cost, and serves them on localhost HTTP + UI.
Features
Token API tracking — input / output / cache tokens from every supported agent
Cost / spend tracking — estimated currency cost per event, agent, model, and period
All agents on one machine — single dashboard for Cursor, Grok, Windsurf, Codex, Claude Code, …
Localhost-only service — binds to
127.0.0.1by defaultLive refresh — filesystem watchers + periodic rescan
Breakdowns & rankings — top agents, top models, spend over time
Stable JSON API — automate budgets, status bars, scripts
npm-first UX —
npx/bunx/ global binaryOffline-friendly pricing — bundled price table; optional refresh
How it works
┌──────────────────────────────────────────────────────────────────┐
│ Host machine │
│ │
│ Cursor · Grok · Windsurf · Codex · Claude Code · Copilot · … │
│ │ │ │ │ │ │
│ └────────┴────┬────┴────────┴───────────┘ │
│ ▼ │
│ ┌─────────────────────┐ │
│ │ Scanners / parsers │ → UsageEvent (tokens) │
│ └──────────┬──────────┘ │
│ ▼ │
│ ┌─────────────────────┐ │
│ │ Cost engine │ tokens × model price │
│ └──────────┬──────────┘ │
│ ▼ │
│ ┌─────────────────────┐ │
│ │ SQLite local store │ events + rollups │
│ └──────────┬──────────┘ │
│ ┌──────────┴──────────┐ │
│ ▼ ▼ │
│ HTTP API :3737 Dashboard (localhost) │
│ /api/stats · /api/cost │
└──────────────────────────────────────────────────────────────────┘Discover agent data directories on Windows / macOS / Linux.
Parse local usage / session files into unified
UsageEventrecords (tokens).Price each event with the cost engine (model rate × token buckets).
Aggregate tokens + spend by agent, model, time, workspace.
Serve via
http://127.0.0.1:<port>for UI and automation.
Agent modules
Each agent lives in its own folder under src/agents/<id>/ (one module = paths + parser):
src/agents/
shared/ # generic-jsonl, usage-fields, path helpers
claude-code/ # index.ts → export const agent
codex/
grok/
…
index.ts # registry: AGENTS, scanAll, detectAgentsTo add a new agent: create src/agents/<id>/index.ts exporting agent: AgentModule, then register it in src/agents/index.ts.
Supported agents
Goal: track token API usage and spend for every major agent on the machine.
Agent / client | Canonical id | Typical sources | Parser |
OpenAI Codex CLI |
|
| Yes |
Hermes Agent |
|
| Yes |
OpenClaw (+ clawdbot/moltbot) |
|
| Yes |
Cursor |
| App data usage JSON/JSONL | Yes |
Grok (xAI) |
|
| Yes |
Windsurf |
| Codeium / Windsurf app data | Yes |
Claude Code |
|
| Yes |
Gemini CLI |
|
| Yes |
OpenCode |
| local share / storage | Yes |
GitHub Copilot |
|
| Yes |
Pi / Oh My Pi |
|
| Yes |
Kimi CLI |
|
| Yes |
Qwen CLI |
|
| Yes |
Factory Droid |
|
| Yes |
Amp |
|
| Yes |
Goose |
| XDG goose data | Yes |
Cline |
| VS Code globalStorage | Yes |
Roo Code |
| VS Code globalStorage | Yes |
Kilo Code |
| kilo data / globalStorage | Yes |
Antigravity |
| gemini / antigravity data | Yes |
Warp AI |
| Warp app data | Yes |
Trae |
| Trae app data | Yes |
Zed Agent |
| Zed threads data | Yes |
Codebuff |
|
| Yes |
Mux |
|
| Yes |
Crush |
| XDG crush data | Yes |
Kiro |
|
| Yes |
Gajae-Code |
|
| Yes |
Jcode |
|
| Yes |
Command Code |
|
| Yes |
JetBrains Junie |
|
| Yes |
ZCode |
|
| Yes |
OpenCodeReview |
|
| Yes |
CodeBuddy |
|
| Yes |
WorkBuddy |
|
| Yes |
Aider |
|
| Yes |
Continue.dev |
|
| Yes |
Devin |
|
| Yes |
Ollama |
|
| Yes |
CodeWhale |
|
| Yes |
MiMo Code |
|
| Yes |
Qoder |
|
| Yes |
iFlow |
|
| Yes |
Blackbox AI |
| VS Code globalStorage / | Yes |
Forge |
|
| Yes |
Void |
| Void app data | Yes |
Amazon Q |
|
| Yes |
9Router |
|
| Yes |
XLab Router |
|
| Yes |
XLab Token only reads local files already on disk. It does not inject into agent processes or call vendor billing APIs unless you explicitly enable an optional integration later.
9Router / XLab Router data paths
Source | Typical location |
Local 9Router |
|
Local XLab Router |
|
VPS install (my.bnix.one) |
|
Local mirror (optional) |
|
Env overrides |
|
Parsers read usageHistory (SQLite), usage.json history, db.json → usageData.history, or exported usage-history.jsonl. Router-reported cost is preferred when present.
Parsers ship incrementally; xlab-token doctors reports which agents are detected and which parsers are active.
Requirements
Item | Minimum |
Runtime | Node.js 20+ or Bun 1.1+ |
OS | Windows 10+, macOS 12+, Linux |
Network | None required (localhost + offline pricing) |
Disk | ~50 MB install + local DB growth |
Quick start
Works on Windows, macOS, and Linux (Node.js 20+).
Desktop App (Recommended)
Download the desktop app for your platform from the Releases page.
Available platforms:
Windows: NSIS installer or portable executable
macOS: DMG or ZIP archive
Linux: AppImage, deb, or rpm package
The desktop app automatically handles server startup and provides a native window experience.
One-shot
npx xlab-token@latest serve
# or
bunx xlab-token@latest serveGlobal install
npm install -g xlab-token
xlab-token serve
# optional: open default browser
xlab-token serve --openOpen:
http://127.0.0.1:3737Local clone (dev / hot reload)
git clone https://github.com/quangminh1212/XLab_Token.git
cd XLab_Token
npm install
# Windows
run.bat
# macOS / Linux
chmod +x run.sh
./run.sh
# or cross-platform
npm run serve:watchToken + cost snapshot (CLI)
# All agents: tokens and estimated spend
xlab-token stats --json
# Last 24 hours, ranked by cost
xlab-token stats --since 24h --by agent --sort cost
# Cost only summary
xlab-token cost --since 7d --currency USD
# Which agents exist on this machine
xlab-token doctorsCLI reference
Command | Description |
| Start localhost API + dashboard (tokens + cost) |
| Rescan all agent sources |
| Aggregate tokens + spend to stdout |
| Focused spend report (totals, by agent/model) |
| Export events (tokens + cost fields) as JSON/CSV |
| Detect agents, paths, parser health |
| Package version |
Common flags
Flag | Default | Description |
|
| Bind address |
|
| HTTP port |
| OS app data | SQLite + config directory |
| — | Time range for stats/cost |
|
|
|
|
|
|
|
| Display currency for cost |
| off | API only |
| on | FS watchers while serving |
| off | Machine-readable output |
HTTP API
Base URL: http://127.0.0.1:3737Content-Type: application/json; charset=utf-8
GET /api/health
{
"ok": true,
"version": "0.1.0",
"uptimeSec": 120,
"agentsDetected": ["cursor", "claude-code", "codex", "windsurf", "grok"]
}GET /api/stats — tokens and cost
Param | Type | Description |
| string | ISO-8601 or relative ( |
| string | End bound |
| string |
|
| string | Filter one agent id |
| string | Cost currency (default |
{
"totals": {
"inputTokens": 1200000,
"outputTokens": 340000,
"cacheReadTokens": 80000,
"cacheWriteTokens": 12000,
"totalTokens": 1632000,
"estimatedCost": 18.42,
"currency": "USD"
},
"groups": [
{
"key": "cursor",
"inputTokens": 400000,
"outputTokens": 90000,
"totalTokens": 490000,
"estimatedCost": 6.20
},
{
"key": "claude-code",
"inputTokens": 500000,
"outputTokens": 120000,
"totalTokens": 620000,
"estimatedCost": 7.10
},
{
"key": "windsurf",
"inputTokens": 150000,
"outputTokens": 40000,
"totalTokens": 190000,
"estimatedCost": 2.40
},
{
"key": "codex",
"inputTokens": 100000,
"outputTokens": 50000,
"totalTokens": 150000,
"estimatedCost": 1.80
},
{
"key": "grok",
"inputTokens": 50000,
"outputTokens": 40000,
"totalTokens": 90000,
"estimatedCost": 0.92
}
]
}GET /api/cost — spend-focused
Param | Type | Description |
| string | Time range |
| string |
|
| string | e.g. |
{
"currency": "USD",
"totalEstimatedCost": 18.42,
"period": { "since": "2026-07-01T00:00:00.000Z", "until": "2026-07-11T23:59:59.999Z" },
"byAgent": [
{ "agent": "claude-code", "estimatedCost": 7.10, "share": 0.385 },
{ "agent": "cursor", "estimatedCost": 6.20, "share": 0.337 }
],
"byModel": [
{ "model": "claude-sonnet-4", "estimatedCost": 5.50 },
{ "model": "gpt-4.1", "estimatedCost": 3.10 }
]
}GET /api/events
Paginated usage events (tokens + cost per row).
Param | Type | Description |
| number | Default |
| string | Pagination cursor |
| string | e.g. |
GET /api/agents
List detected agents and parser status.
{
"agents": [
{ "id": "cursor", "detected": true, "enabled": true, "lastEventAt": "2026-07-11T10:00:00.000Z" },
{ "id": "grok", "detected": true, "enabled": true, "lastEventAt": "2026-07-11T09:30:00.000Z" },
{ "id": "windsurf", "detected": true, "enabled": true, "lastEventAt": "2026-07-11T08:00:00.000Z" },
{ "id": "codex", "detected": true, "enabled": true, "lastEventAt": "2026-07-10T22:00:00.000Z" },
{ "id": "claude-code", "detected": true, "enabled": true, "lastEventAt": "2026-07-11T11:00:00.000Z" }
]
}POST /api/scan
{ "ok": true, "eventsIngested": 42, "durationMs": 318 }Errors
{
"error": {
"code": "INVALID_QUERY",
"message": "groupBy must be one of: agent, model, day, hour"
}
}Status: 400 validation · 404 not found · 500 internal.
Cost engine
Spend is computed locally from token buckets and a pricing table:
cost = (inputTokens × priceInputPer1M
+ outputTokens × priceOutputPer1M
+ cacheReadTokens × priceCacheReadPer1M
+ cacheWriteTokens × priceCacheWritePer1M) / 1_000_000Topic | Behavior |
Price source | Bundled offline snapshot of common model rates |
Unknown model | Marked |
Currency | Default |
Accuracy | Estimate — may differ from provider invoices |
Override | User can set custom rates in config |
Configuration
# Windows
%APPDATA%\xlab-token\config.json
# macOS
~/Library/Application Support/xlab-token/config.json
# Linux
~/.config/xlab-token/config.json{
"host": "127.0.0.1",
"port": 3737,
"watch": true,
"pricing": {
"source": "bundled",
"currency": "USD",
"customRates": {
"my-local-model": {
"inputPer1M": 0,
"outputPer1M": 0
}
}
},
"agents": {
"cursor": { "enabled": true },
"grok": { "enabled": true },
"windsurf": { "enabled": true },
"codex": { "enabled": true },
"claude-code": { "enabled": true },
"copilot": { "enabled": true },
"opencode": { "enabled": true }
},
"paths": {
"overrides": {}
}
}Environment variable | Meaning |
| Bind host |
| Bind port |
| Data directory |
| Cost currency |
|
|
Data model
UsageEvent
Field | Type | Description |
| string | Stable hash (source + native id) |
| string |
|
| string | null | Provider model id |
| string | ISO-8601 UTC |
| number | API input / prompt tokens |
| number | API output / completion tokens |
| number | Cache read tokens (if any) |
| number | Cache write tokens (if any) |
| number | Sum of token buckets |
| number | null | Computed spend in |
| string | e.g. |
| string |
|
| string | null | Project path when known |
| string | Local file parsed |
| object | null | Sanitized native fields (no full prompts by default) |
Storage
SQLite under data directory
Append-only events + rollup tables (tokens + cost by agent/model/day)
Idempotent ingest on
id
Privacy & security
Principle | Practice |
Local by default |
|
No account | No signup required |
Prefer counters | Tokens + cost, not full chat bodies |
User-owned DB | All data under |
Explicit network | Optional price-table update only if enabled |
Do not bind to 0.0.0.0 on untrusted networks. Treat the DB as sensitive if workspace paths are stored.
Development
git clone https://github.com/quangminh1212/XLab_Token.git
cd XLab_Token
npm install
npm test
npm run build
npm startBuilding Desktop App
Generate placeholder icons
npm run generate-iconsFor production, convert the generated SVG to proper formats:
electron/assets/icon.png(256x256 PNG for Linux)electron/assets/icon.ico(256x256 ICO for Windows)electron/assets/icon.icns(ICNS for macOS)
Build for current platform
npm run electron:buildBuild for specific platforms
Windows:
npm run electron:build:winmacOS:
npm run electron:build:macLinux:
npm run electron:build:linuxDevelopment mode
npm run electron:devSee installer/electron/README.md for detailed Electron documentation.
Documentation
Additional documentation is available in the docs/ directory:
docs/CONTRIBUTING.md - Contribution guidelines and development workflow
docs/SECURITY.md - Security policy and vulnerability reporting
docs/CODE_OF_CONDUCT.md - Community code of conduct
docs/CHANGELOG.md - Version history and changes
docs/AUTHORS.md - Project contributors and acknowledgments
docs/ATTRIBUTION.md - Third-party attributions and licenses
OS | Dev launcher |
Windows |
|
macOS / Linux |
|
Any |
|
Agent data paths are resolved per platform (%APPDATA% / ~/Library/Application Support / XDG). Extension-based agents also scan VS Code, Cursor, VSCodium, Code - OSS, and Windsurf globalStorage.
src/
agents/ # one folder per agent (paths + parser)
server/ # HTTP API + dashboard
cli.ts # xlab-token binaryScript | Purpose |
| CLI via tsx |
| API + UI hot reload |
| Production build |
| Unit + parser fixtures |
| TypeScript check |
Implementation status (v0.1.0)
Integrated feature set inspired by tokscale, codeburn, and ccusage (see docs/ATTRIBUTION.md):
Area | Status |
Multi-agent local scanners | Done — 23 agents incl. Codex (deep), Hermes, OpenClaw |
Token + cost aggregation | Done — |
Bundled offline pricing | Done — LiteLLM-style rates in |
Localhost dashboard | Done — |
Agent detection ( | Done |
Hermes SQLite ( | Done — via |
OpenClaw / clawdbot / moltbot | Done — sessions index + JSONL usage |
Codex deep scan | Done — sessions/history/archived, cumulative token_count |
Grok session estimate | Done — real usage if present, else text-length estimate |
Cursor SQLite ( | Planned (JSON/JSONL caches supported now) |
SQLite persistent store | Planned (in-memory scan each run for v0.1) |
LiteLLM live price refresh | Planned |
Dev commands
npm install
npm run build
npm test
npx tsx src/cli.ts doctors
npx tsx src/cli.ts stats --since 7d
npx tsx src/cli.ts cost --since 7d
npx tsx src/cli.ts serve --port 3737Roadmap
Core scanner + cost engine (TypeScript)
P0 parsers: Cursor, Grok, Windsurf, Codex, Claude Code (+ Gemini, OpenCode)
Bundled model price table
Dashboard + HTTP API
CLI:
stats,cost,scan,doctors,serveDeeper Cursor SQLite + Copilot parsers
Persistent SQLite store / incremental scan
Optional LiteLLM price refresh
Plugin API for custom agents
Contributing
We welcome contributions! Please see docs/CONTRIBUTING.md for guidelines on:
Development workflow
Code style and standards
Testing requirements
Pull request process
Adding new agent support
Quick start:
Fork and branch from
mainAdd parser fixtures for each agent (token fields required; cost via engine)
Prefer small PRs; Conventional Commits (
feat:,fix:,docs:)
License
MIT License — see LICENSE when published.
Disclaimer
XLab Token reads local usage artifacts from third-party agents. Formats may change without notice. Token counts and costs are best-effort estimates and may differ from official provider billing dashboards or invoices.
This server cannot be installed
Maintenance
Resources
Unclaimed servers have limited discoverability.
Looking for Admin?
If you are the server author, to access and configure the admin panel.
Latest Blog Posts
- Your AI Chatbot Just Exposed Your CEO's Salary to an InternBy Om-Shree-0709 on .Agent IdentityMCP SecurityOAuth Delegation
- Why MCP Servers Need Execution Sandboxing (And Why Your Current Stack Isn't Enough)By Om-Shree-0709 on .Agentic AiPrompt InjectionWebAssembly
MCP directory API
We provide all the information about MCP servers via our MCP API.
curl -X GET 'https://glama.ai/api/mcp/v1/servers/quangminh1212/XLab_Token'
If you have feedback or need assistance with the MCP directory API, please join our Discord server