Analyze Claude Code token cost & context attribution. Local, read-only MCP server.
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.
See what your AI-coding session actually cost β and what's eating your context. A local, read-only CLI that parses your Claude Code session logs and shows where the money goes: model output vs. context being re-sent every turn (the hidden 60%+ of most bills).
(A real session, default Opus pricing. Your numbers will differ β prices are overridable.)
Agentic coding (Claude Code, etc.) produces surprise bills, and the cause is mundane: as a session grows, the whole context is re-sent every turn, so cost balloons even when the model writes little. Existing dashboards show totals; tokenscope shows the attribution β output vs. cache-read vs. cache-write vs. fresh input, the per-turn context-growth curve, cost by model, subagent spend, and which tools fill your context β with concrete "trim this" insights.
Runs on a bundled sample session so you see the full report before pointing it at your own logs β no setup, nothing to configure. (The sample is synthetic, for demonstration.)
No install β runs via npx:
Reads ~/.claude/projects/**/*.jsonl. Read-only, local, no network, no telemetry β open the source; nothing leaves your machine.
--max-total N / --max-delta N make scan exit 1 when the token footprint (or a diff's delta) blows a budget β the same check ci-guardrail runs in CI, but locally, before you push. Wire the absolute budget into a git hook so a runaway prompt/config never leaves your machine:
Under budget it prints the report and exits 0; over budget it prints a BLOCKED: line and exits 1. Without a --max-* flag scan just reports (exit 0), so it's opt-in. --max-delta gates the delta between two directories on disk (scan --diff <baseDir> --max-delta N) β point it at a checked-out base tree when you want a regression gate rather than an absolute cap.
Using the pre-commit framework? Add tokenscope to your .pre-commit-config.yaml β no git-hook scripting:
language: node, zero dependencies. With no args it prints the footprint (exit 0); add --max-total N (or --diff <baseDir> --max-delta N) to fail the commit over budget.
--share emits a compact summary built from aggregate numbers only β no file paths, no prompt/response content β so it's safe to paste in public:
--share-svg) β no binary deps; renders inline on GitHub and is trivially shareable.Prefer not to touch a terminal flag? The same render runs entirely in your browser at the web surface in web/: paste your --json output and it draws the full report + the SVG card locally β nothing is uploaded.
There's an MCP server that exposes the same engine to AI agents / MCP clients (Claude Desktop, Claude Code, etc.) as tools: analyze_claude_cost, get_cost_benchmark, and tokenscope_share_summary. Add it to your MCP config:
Then ask your agent "use tokenscope to analyze my last Claude Code session." It's the same local, read-only engine β see mcp/README.md.
Uses documented default prices (Anthropic cache multipliers: write 1.25Γ/2Γ, read 0.1Γ of input). Verify and override for your exact model/tier via ./.tokenscope.json:
Unknown models are flagged (never silently counted as $0). Token counts are read straight from the logs; cost = those counts Γ the prices shown.
tokenscope is the measurement engine behind a sibling tool, and one of three open-source cost projects:
uses: wartzar-bee/ci-guardrail@v1.If you find tokenscope useful, ci-guardrail is the zero-config way to run it on every PR.
tokenscope came out of running autonomous agents and watching the bill. The write-ups behind it:
npm test).--watch live meter; OpenAI/Codex log support.MIT. Not affiliated with Anthropic.
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/tokenscope)<a href="https://allmcps.com/mcp/tokenscope"><img src="https://allmcps.com/api/badge/tokenscope?style=directory" alt="Tokenscope on AllMCPs" /></a>