Harry Xin
GITHUB 17.6K · 26 TOOLSFILESYSTEM 4.1K · 11 TOOLSTOTAL 21.7K TOKENS≈ $0.1084 / MSGCREATE_OR_UPDATE_FILE 1.4KCREATE_PULL_REQUEST 1.2KLIST_COMMITS 760LINT · 27 FINDINGS · ~859 TOKENS/MSGTOOL SEARCH · −3.5K UPFRONTGITHUB 17.6K · 26 TOOLSFILESYSTEM 4.1K · 11 TOOLSTOTAL 21.7K TOKENS≈ $0.1084 / MSGCREATE_OR_UPDATE_FILE 1.4KCREATE_PULL_REQUEST 1.2KLIST_COMMITS 760LINT · 27 FINDINGS · ~859 TOKENS/MSGTOOL SEARCH · −3.5K UPFRONT
ctxtax · Context Report 2026上下文报告 2026

Before the first prompt,
the bill has started.
还没开始提问,
上下文已经有了开销。

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 都受预算约束。

Open on GitHub在 GitHub 打开
npm install -g ctxtax
Context tax per request每次请求的上下文开销21.7ktokens · ≈ $0.1084 / message条README sampleREADME 示例
ctxtax · Context Report 2026上下文报告 202602

Letter to readers致读者信

Every 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 作者

  1. Figure from the ctxtax README, not measured for this page.数字出自 ctxtax README,并非本页实测。
ctxtax · Context Report 2026上下文报告 202603

Key figures财务摘要

21.7ktokens per request in the sample report示例报告中每次请求的 token
$0.1084per message at the model’s input price按模型输入价格折算的每条消息费用
81%of it from one server, github (17.6k of 21.7k)来自同一个服务器 github(21.7k 中的 17.6k)
−3.5ksaved upfront if deferrable servers load on demand可延迟的服务器按需加载时,开头节省的量
Composition of context cost上下文开销构成README · claude-opus-4-8
github · 26 tools个工具
17.6k
filesystem · 11 tools个工具
4.1k
Total合计
21.7k
  1. All figures on this page are the sample output printed in the ctxtax README.本页所有数字均为 ctxtax README 中的示例输出。
ctxtax · Context Report 2026上下文报告 202604

Audit method审计方法

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

  1. 01Discover: read .mcp.json or take a server command.发现:读取 .mcp.json,或直接接收一条服务器命令。
  2. 02Connect: speak MCP over stdio or Streamable HTTP and call tools/list.连接:通过 stdio 或 Streamable HTTP 连接,调用 tools/list 取得真实定义。
  3. 03Count: convert each tool to the Anthropic tool shape and measure its marginal cost.计数:把每个工具转换成 Anthropic 的工具格式,计算边际开销。
  4. 04Report: sorted bars per server, totals and dollars per message.出表:按服务器排序的条形图、合计与每条消息费用。

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

  1. The README notes that tiktoken, OpenAI’s tokenizer, undercounts Claude by about 15–20% on ordinary text, and more on JSON.README 指出,OpenAI 的分词器 tiktoken 对 Claude 普通文本少算约 15%–20%,对 JSON 少算更多。
  2. The estimate falls back to the length of the JSON definitions.估算基于 JSON 定义的长度。
ctxtax · Context Report 2026上下文报告 202605

Statements报表

Context cost by server and tool按服务器与工具列出的上下文开销
Server / tool服务器 / 工具TokensRelative size相对大小
github26 tools · ≈ $0.0879/msg26 个工具 · 约 $0.0879/条17.6k
create_or_update_file1.4k
create_pull_request1.2k
list_commits760
… 23 more tools… 另外 23 个工具
filesystem11 tools · ≈ $0.0205/msg11 个工具 · 约 $0.0205/条4.1k
Total context tax上下文开销合计21.7k≈ $0.1084 / message条
  1. Sample output from the ctxtax README.ctxtax README 中的示例输出。
ctxtax · Context Report 2026上下文报告 202606

Management discussion管理层讨论

Four commands, each answering a different question about the same budget.四个子命令,各自回答同一笔预算的一个问题。

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 徽章。

lint

Where 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

toolsearch

What 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

Always loaded全部预加载21.7k
Deferred upfront延迟后开头18.2k

ci

Will this pull request blow the budget? See the next page.这个 PR 会不会超预算?见下一页。

  1. Tool Search figures are modelled: a deferred server is assumed to keep a name and a one-line stub in the index.Tool Search 的数字是模拟值:假设延迟加载的服务器在索引中保留名称和一行简介。
ctxtax · Context Report 2026上下文报告 202607

Risk control风控

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 里贴出一条逐个工具的差异评论,写入任务摘要;合计超过阈值时,检查失败。

ctxtaxcommented on this pull request评论了这个 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 }}
  1. Illustration. “+4 tools, +3,200 tokens” is the README’s example; the base is the README’s sample total.示意。「新增 4 个工具,+3,200」取自 README 的例子,基准数取自 README 示例的合计。
ctxtax · Context Report 2026上下文报告 202608

Risk factors风险因素

  • Real counts depend on the model, the schema and the counting method.实际计数取决于模型、工具定义和计数方式。
  • Billing also depends on prompt caching and how requests are made; ctxtax does not quote a bill.实际计费还受提示缓存和请求方式影响;ctxtax 不提供账单报价。
  • Without an API key, figures are estimates and are labelled so.没有 API 密钥时,数字为估算,并明确标注。
  • Tool Search figures are a model of deferred loading, not a measurement.Tool Search 的数字是对延迟加载的模拟,并非实测。
  • The sample figures on this page were not re-measured: running third-party MCP servers locally for this page was not done.本页的示例数字没有重新实测:制作本页时没有在本机运行第三方 MCP 服务器。
ctxtax · Context Report 2026上下文报告 202609

Company profile公司概况

Package发布ctxtax@0.1.0 · npm
Language语言TypeScript · Node ≥ 18
Built on依赖MCP SDK · Anthropic SDK · commander
Transports连接方式stdio · Streamable HTTP
CIGitHub 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)
  1. ctxtax --help run locally on 2026-11-07.ctxtax --help 为 2026-11-07 在本机运行的输出。