scan
How much does each tool cost? The default report, with --json for machines, --html for a shareable card and --badge for a README badge.每个工具花多少?默认报告;--json 输出机器可读格式,--html 生成可分享的卡片,--badge 生成 README 徽章。
A command-line tool that measures what each MCP tool costs every Claude request, in tokens and in dollars, and holds pull requests to a budget.一个命令行工具:测量每个 MCP 工具在每次 Claude 请求中的开销,单位是 token 和美元,并让每个 PR 都受预算约束。
npm install -g ctxtaxEvery MCP tool you connect to Claude adds its JSON schema to the context of every request. Nobody sends that text on purpose and few people ever read it, yet it is paid for on every turn, and it takes room from the conversation itself. The README puts a handful of servers at 30,000 to 60,000 tokens before the first word is typed.1你接入 Claude 的每一个 MCP 工具,都会把自己的 JSON schema 放进每一次请求的上下文。没有人有意发送这段文字,也很少有人读过它,但它每一轮都要付费,还占用了本该留给对话的空间。按 README 的估计,几个服务器在第一句话之前就可能占用 3 万到 6 万个 token。1
ctxtax exists to put that cost on paper: per tool, per server, in tokens and in dollars, counted the way Claude counts. Claude Code’s own /context already shows the total interactively. What it cannot do is run in CI, so ctxtax also turns the budget into a check that every pull request has to pass.ctxtax 要做的,是把这笔开销写在纸上:按工具、按服务器,用 token 和美元两种单位,按 Claude 自己的方式计数。Claude Code 自带的 /context 已经能交互地显示总量,但它进不了 CI,所以 ctxtax 还把预算变成了每个 PR 都要通过的一项检查。
Harry XinAuthor, ctxtaxctxtax 作者
A budgeting tool that is twenty per cent wrong is worse than none. So ctxtax does not use a general-purpose tokenizer; it asks Anthropic’s own token-count endpoint, which is free and specific to each model.1一个误差两成的预算工具,还不如没有。所以 ctxtax 不使用通用的分词器,而是调用 Anthropic 官方的 token 计数接口,免费,且按模型区分。1
.mcp.json or take a server command.发现:读取 .mcp.json,或直接接收一条服务器命令。tools/list.连接:通过 stdio 或 Streamable HTTP 连接,调用 tools/list 取得真实定义。count_tokens(with the tool含该工具) − count_tokens(baseline基准)
Without an API key the report still runs, and every figure is labelled as an estimate.2没有 API 密钥时照样出报告,但每个数字都会标明是估算。2
| Server / tool服务器 / 工具 | Tokens | Relative size相对大小 |
|---|---|---|
| github26 tools · ≈ $0.0879/msg26 个工具 · 约 $0.0879/条 | 17.6k | |
| create_or_update_file | 1.4k | |
| create_pull_request | 1.2k | |
| list_commits | 760 | |
| … 23 more tools… 另外 23 个工具 | ||
| filesystem11 tools · ≈ $0.0205/msg11 个工具 · 约 $0.0205/条 | 4.1k | |
| Total context tax上下文开销合计 | 21.7k | ≈ $0.1084 / message条 |
$ ctxtax
github 17.6k tokens (26 tools) ≈ $0.0879/msg
create_or_update_file ████████████████████████████ 1.4k
create_pull_request ████████████████████████ 1.2k
list_commits ███████████████ 760
...
filesystem 4.1k tokens (11 tools) ≈ $0.0205/msg
...
────────────────────────────────────────────────
TOTAL context tax: 21.7k tokens ≈ $0.1084/msg [model: claude-opus-4-8]Four commands, each answering a different question about the same budget.四个子命令,各自回答同一笔预算的一个问题。
scanHow much does each tool cost? The default report, with --json for machines, --html for a shareable card and --badge for a README badge.每个工具花多少?默认报告;--json 输出机器可读格式,--html 生成可分享的卡片,--badge 生成 README 徽章。
lintWhere can a server author save? It flags long descriptions, bloated schemas, huge enums and redundant titles.服务器作者能省在哪里?指出过长的描述、臃肿的参数结构、过大的枚举和重复的标题。
filesystem / search_files ✖ [long-description] ~121 tokens • [verbose-tool] ~206 tokens 27 findings ~859 tokens/msg recoverable
toolsearchWhat if definitions load on demand? stdio servers can be deferred; HTTP servers are not deferred today, so they pay in full.1如果工具定义按需加载会怎样?stdio 服务器可以延迟加载;HTTP 服务器目前不能,开头要全额支付。1
ciWill this pull request blow the budget? See the next page.这个 PR 会不会超预算?见下一页。
In CI the budget becomes a check. The GitHub Action fetches the base branch’s snapshot, posts one comment on the pull request with the per-tool diff, writes a job summary, and fails when the total crosses the threshold.在 CI 里,预算变成一项检查。GitHub Action 会取回基准分支的快照,在 PR 里贴出一条逐个工具的差异评论,写入任务摘要;合计超过阈值时,检查失败。
| Base branch基准分支 | 21,700 |
|---|---|
| This PR (+4 tools)本 PR(新增 4 个工具) | 24,900 |
| Change变动 | +3,200 |
| Budget预算 | 30,000 |
✓Within budget未超预算
# .github/workflows/ctxtax.yml
- uses: HarryXin0919/ctxtax@v0.1.0
with:
max-tokens: "30000"
anthropic-api-key: ${{ secrets.ANTHROPIC_API_KEY }}| Package发布 | ctxtax@0.1.0 · npm |
|---|---|
| Language语言 | TypeScript · Node ≥ 18 |
| Built on依赖 | MCP SDK · Anthropic SDK · commander |
| Transports连接方式 | stdio · Streamable HTTP |
| CI | GitHub Action · HarryXin0919/ctxtax@v0.1.0 |
| Docs文档 | README in 9 languages9 种语言的 README |
| License协议 | MIT |
$ ctxtax --help
Usage: ctxtax [options] [command]
Measure how many context tokens each MCP server/tool costs your Claude requests.
Commands:
scan [options] [command...] Show the context-token cost of your MCP servers (a bar chart)
ci [options] Enforce a context budget and emit a PR-comment diff (for CI)
lint [options] Suggest token savings for MCP server authors
toolsearch [options] Model Tool Search: always-loaded vs deferred upfront cost (estimate)ctxtax --help run locally on 2026-11-07.ctxtax --help 为 2026-11-07 在本机运行的输出。