ctxcap
What it does
Offline context-budget MCP server for AI coding agents.
- Connects 在你的电脑上运行
- Account or key No key needed
- Category 开发者工具
安装
选择你使用的 AI 应用,然后复制设置。
通过 3/3 项检查 · 在你的电脑上运行 · ✓ 命令已检查 2026年11月13日
第一步:你用哪个 AI?
选择你用的应用,步骤会显示在下方。
可连接 Claude,但需要先准备
需要先在电脑上安装 Node.js(只需一次) · 仅限电脑上的 Claude 应用(Windows 或 Mac),网页和手机不可用
打开电脑版 Claude 应用的设置文件
SettingsDeveloperEdit Config
粘贴这些设置并保存文件
{ "mcpServers": { "ctxcap": { "command": "npx", "args": [ "-y", "ctxcap-mcp" ] } } }退出 Claude 再重新打开
试一试
用 ctxcap 告诉我你能帮我做什么,然后做一件给我看✓ 如果 Claude 说正在使用 ctxcap,或回答中出现 ctxcap 的工具名称,就表示连接成功
菜单名称已于 2026年11月11日 对照 Anthropic 帮助页面核实 · 你的界面可能因版本略有不同
ChatGPT 暂时无法连接 ctxcap
ctxcap 需要安装在你的电脑上,而 ChatGPT 只能连接在网上运行的服务器
你可以改用这些方式
A · 使用能连接 ctxcap 的应用
- 需要先在电脑上安装 Node.js(只需一次) · 仅限电脑上的 Claude 应用(Windows 或 Mac),网页和手机不可用
- 需要先在电脑上安装 Node.js(只需一次)
- 需要先在电脑上安装 Node.js(只需一次)
- 需要先在电脑上安装 Node.js(只需一次)
B · 开发者工具 类中能连接 ChatGPT 的其他服务器
从同类中使用较多的里挑选,仅限用地址即可连接、无需密钥的
- Sentry✓ ChatGPT
- Compiler Explorer✓ ChatGPT
- GitDiagram✓ ChatGPT
可连接 Claude Code,但需要先准备
需要先在电脑上安装 Node.js(只需一次)
打开终端
Mac:按 Command+空格,输入 Terminal · Windows:打开 PowerShell
粘贴这条命令并按 Enter
claude mcp add --scope user ctxcap -- npx -y ctxcap-mcp在 Claude Code 中输入 /mcp
应能看到 ctxcap 在列表中并显示已连接
试一试
用 ctxcap 告诉我你能帮我做什么,然后做一件给我看✓ 如果 Claude Code 说正在使用 ctxcap,或回答中出现 ctxcap 的工具名称,就表示连接成功
菜单名称已于 2026年11月11日 对照 Anthropic 帮助页面核实 · 你的界面可能因版本略有不同
可连接 Cursor,但需要先准备
需要先在电脑上安装 Node.js(只需一次)
在 Cursor 中以 Agent 模式打开 AI 聊天
试一试
用 ctxcap 告诉我你能帮我做什么,然后做一件给我看✓ 如果 Cursor 说正在使用 ctxcap,或回答中出现 ctxcap 的工具名称,就表示连接成功
菜单名称已于 2026年11月11日 对照 Cursor 帮助页面核实 · 你的界面可能因版本略有不同
可连接 VS Code,但需要先准备
需要先在电脑上安装 Node.js(只需一次)
在 VS Code 中以 Agent 模式打开 AI 聊天
试一试
用 ctxcap 告诉我你能帮我做什么,然后做一件给我看✓ 如果 VS Code 说正在使用 ctxcap,或回答中出现 ctxcap 的工具名称,就表示连接成功
菜单名称已于 2026年11月11日 对照 VS Code 帮助页面核实 · 你的界面可能因版本略有不同
开发者专用:终端命令和 JSON 设置
安装在电脑上
Claude Code
claude mcp add --scope user ctxcap -- npx -y ctxcap-mcpClaude Desktop (claude_desktop_config.json)
{
"mcpServers": {
"ctxcap": {
"command": "npx",
"args": [
"-y",
"ctxcap-mcp"
]
}
}
}Cursor (~/.cursor/mcp.json)
{
"mcpServers": {
"ctxcap": {
"command": "npx",
"args": [
"-y",
"ctxcap-mcp"
]
}
}
}VS Code (mcp.json)
{
"servers": {
"ctxcap": {
"type": "stdio",
"command": "npx",
"args": [
"-y",
"ctxcap-mcp"
]
}
}
}这些设置是根据作者在注册中心的条目生成的。如果 README 的写法不同,请以 README 为准。
一览
哪些应用可以使用它
依据这个服务器的连接方式和各应用自己的文档,检查于 2026年11月10日。
在你的电脑上运行,适用于
ClaudeGooseLM StudioMsty StudioCherry StudioCursorVS Code + GitHub CopilotVisual StudioWindsurf (Devin Desktop)ZedKiroClineContinueJetBrains AI AssistantClaude CodeCodex CLIGemini CLIOpenCodenodecodeWarpLibreChatRaycast
它能做什么
它在你的电脑上运行;安装后,工具列表会显示在你的 AI 应用中。
基础检查i
我们检查的是任何人都能看到的信息;我们没有阅读代码。不适用的检查项不计入总数。 · 检查于 2026年11月13日
- ✓ 通过
作者与仓库一致
注册名称已通过 GitHub 账户 Naeha-S 验证,该账户拥有此仓库
- ✓ 通过
仍在维护
代码最后更新于今天
- ✓ 通过
有许可证
使用 MIT
- – 不适用
端点有响应
它在你的电脑上运行,没有互联网端点
- – 不适用
使用 OAuth 登录
在你的电脑上运行,改用本地设置
- … 尚未检查
工具描述中没有隐藏指令
它在你的电脑上运行;我们只能读取互联网端点的工具列表
讨论
提问、分享技巧或报告无法使用。按“有帮助”数量排序。
用户评价
还没有评价
与“开发者工具”中的其他服务器比较i
- 星标数多于此分类中其他 5839 个服务器的 0%
- 发布到注册中心的时间比此分类中其他 5839 个服务器的 99% 更新
- 基础检查结果等于或优于此分类中其他 5839 个服务器的 100%
与注册中心里这个分类中所有活跃的服务器比较。只有当发布者拥有该仓库时,星标数才计入。
常见问题
ctxcap 安全吗?
它在 3 项适用的基础检查中通过了 3 项。我们没有阅读代码。在添加密钥或令牌之前,请先看看这个服务器要求哪些权限,并使用只具备所需权限的密钥。
它需要哪些密钥或代码?
注册中心没有列出必需的密钥,不过有些服务器会在首次使用时要求你登录。
它在我的电脑上运行还是在云端?
它在你的电脑上运行。你的 AI 应用会在需要时启动它,数据不会经过作者的服务器(除非它自己调用在线服务)。
它还在维护吗?
GitHub 仓库最后更新于今天,最新版本(0.1.4)于今天进入注册中心。
哪些应用可以使用它?
支持 MCP 的应用,例如 Claude Desktop、Claude Code、Cursor 和 VS Code。你的电脑上还需要有 Node.js。
有什么可以替代它?
同一分类中有:REA, GitHub, Serena MCP: the IDE for your agent
同类别的其他选择
同一分类中其他作者的服务器,按星标数排序。
如何看卡片:↓ 每周下载量i★ GitHub 星标i三大支柱:评价 · 检查 · 使用情况i更新 = 最新版本发布到注册中心的时间i
GitHub
Connect AI assistants to GitHub - manage repos, issues, PRs, and workflows through natural language.
Serena MCP: the IDE for your agent
A powerful toolkit for coding, providing semantic retrieval and editing capabilities.
作者的 README
打开 README
按原文从作者的仓库复制。PopNx MCP 没有审查或背书其内容。HTML、图片和脚本已被移除。链接会离开本站。
ctxcap
Offline token-budget linter for agent context files. It measures CLAUDE.md, AGENTS.md, prompts/**, and .cursor/rules/**, finds references that no longer resolve, and hands your agent a ranked, verifiable plan to get back under budget.
No config, API key, network, or telemetry. Node >= 20. Two runtime dependencies: fast-glob and gpt-tokenizer.
npx ctxcap --json
The loop
Context files get trimmed by agents badly: the agent rewrites the file from memory, drops the ## Never rules, hits the budget, and ships a worse file. ctxcap closes that loop with line ranges, safety flags, and verification.
npx ctxcap --plan --budget 40000 # ranked plan, JSON
npx ctxcap --plan --budget 40000 --apply # splice atomically npx ctxcap --verify # catch drift and violations
Three rules for the agent:
- Splice by
startLine/endLine. Never rewrite a file from scratch. - Never cut a span listed in
preserve. - If
satisfiableis false, reportminAchievableand stop.
Where plans live
CLI plans are written to .ctxcap/plans/ .json. Add .ctxcap/ to .gitignore; plans are local working state, not source. Plans expire after 24 hours. If a plan is missing or expired, verification returns the structured PLAN_EXPIRED error and you should generate a new plan. Run --apply on a clean tree, then review with git diff before committing. Do not run --apply in CI.
Agents can fetch the five-line loop from llms.txt.
Before and after
This is a real measurement from the ctxcap repository itself:
$ npx ctxcap --json
total: 476 baseline: 363 delta: +113 files: 2
$ npx ctxcap --plan --budget 400 satisfiable: false current: 476 minAchievable: 476 tokensRemaining: 76 plan: [] preserve: AGENTS.md:19-20, llms.txt:17-30
The result correctly stops instead of cutting load-bearing instructions. For a successful before/after case study, use a public repository with a larger context file and publish the commit, JSON reports, plan, and verification result together.
To publish a reproducible case study, include the repository commit, the ctxcap --json report before and after, the plan JSON, and the verification result. This makes the reclaim measurable and lets readers reproduce it.
Context can be stale as well as large. Run the dead-reference pass to find paths, commands, globs, and @path/#path references that no longer resolve:
npx -y ctxcap --stale --json
It reports reclaimable tokens and emits inline SARIF annotations with --sarif. Use --fail-on stale to gate CI, or --stale-fix to print a deletion diff without modifying files.
The stale pass skips fenced code blocks and suspicious tokens containing ~, $, ://, or <. Add to a line to suppress that line. --stale-fix prints a deletion diff; there is deliberately no --stale --apply mode.
Why
Agent context files — CLAUDE.md, AGENTS.md, prompts/**, .cursor/rules/ — grow every sprint. They get pasted into every request and silently burn your context window. Nothing gates them at the repo level.
ctxcap fixes that: it measures context files, tracks token deltas against a committed baseline, finds stale references, produces ranked plans, verifies edits, fails CI when you define a budget, and exposes an MCP server so agents can check themselves.
How this differs from tokenlint
tokenlint hooks your editor and reminds you per turn about wasteful habits. ctxcap gates the repo: it measures context files against a committed baseline, reports the delta on every PR, and fails only when you ask it to. Different layer — CI and review, not keystrokes.
No baseline, stale-reference pass, ranked plan, verify step, SARIF, or MCP surface there. If you want per-turn nudges inside Claude Code, use theirs; if you want a gate on prompts/**, use this.
Install
npm i -D ctxcap
npx ctxcap --update-baseline
Or run without installing:
npx -y ctxcap --json
Test another repository
Run the unpinned latest ctxcap from the repository you want to inspect. It reads the current working directory, so no files need to be copied into the ctxcap repository:
cd path/to/your-repo
npx ctxcap --json npx ctxcap --stale --json npx ctxcap --plan --budget 40000
Use the pinned version in release checks or reproducible CI. For a real edit loop, review the plan, apply it, then verify the saved plan:
npx -y ctxcap@1.2.0 --plan --budget 40000
npx -y ctxcap@1.2.0 --plan --budget 40000 --apply npx -y ctxcap@1.2.0 --verify
Start with a baseline when you want pull requests to report growth:
npx -y ctxcap@1.2.0 --update-baseline
git add ctxcap-baseline.json git commit -m "Add ctxcap baseline"
Add a .ctxcap.json file to customize included paths, ignored paths, or budgets. The default scan is intentionally limited to common agent context files.
CLI
| Flag | Effect | |||
|---|---|---|---|---|
--json | Machine-readable JSON report on stdout | |||
--sarif | SARIF 2.1.0 on stdout | |||
--suggest | Include compression suggestions | |||
--stale | Find dead paths, commands, globs, and references | |||
--stale-glob | Include globs that match zero files | |||
--stale-fix | Print a deletion diff; never writes files | |||
| `--fail-on increase\ | budget\ | stale\ | never` | When to exit 1 (default: never) |
--baseline | Read baseline from a git ref (CI uses merge base automatically) | |||
--update-baseline | Write ctxcap-baseline.json and exit | |||
--config | Config file path (default: .ctxcap.json) | |||
--root | Working directory (default: .) | |||
--plan | Print a ranked context-budget edit plan | |||
--apply | Apply the generated plan atomically | |||
--verify | Verify a saved plan and preserve spans | |||
--budget | Target budget for --plan |
Exit codes: 0 clean, 1 breach under --fail-on, 2 internal error.
Config
.ctxcap.json — all fields optional:
{
"include": ["AGENTS.md", "prompts/", ".cursor/rules/"], "ignore": ["prompts/archive/**"], "budgets": { "total": 40000, "AGENTS.md": 500, "prompts/system.md": 8000 }, "failOn": "budget" }
Defaults (when no config exists): scans CLAUDE.md, AGENTS.md, .github/copilot-instructions.md, prompts/**, *.prompt, .cursor/rules/**.
GitHub Action
permissions:
contents: read pull-requests: write security-events: write # for SARIF upload; drop if you set upload-sarif: false
steps:
- uses: actions/checkout@v4 with: { fetch-depth: 0 }
- uses: Naeha-S/ctxcap@v1 with: { fail-on: increase }
Pinned form for reproducibility: uses: Naeha-S/ctxcap@v1.2.0
Inputs:
| Input | Default | Description | |||
|---|---|---|---|---|---|
fail-on | never | increase \ | budget \ | stale \ | never |
config | .ctxcap.json | Path to config file | |||
path | . | Root directory to lint | |||
comment | true | Post sticky PR comment | |||
upload-sarif | true | Upload SARIF to code scanning | |||
stale | false | Run the stale-reference pass | |||
stale-glob | false | Include zero-match globs |
What you get on every run:
- Workflow annotations on over-budget files
- Job step summary with token table and delta
When the token can write (non-fork PRs):
- Sticky PR comment, updated in place (one comment, not a new one each run)
- SARIF upload to GitHub code scanning
Fork PRs
With plain pull_request, fork PRs get a read-only token: annotations and job summary only. For the full experience on forks, use pull_request_target as shown in examples/pull-request-target.yml.
Code scanning requires GitHub Advanced Security on private repos; SARIF upload silently no-ops without it.
MCP
Run the MCP server directly — no config needed:
npx -y ctxcap-mcp
Configure in your MCP client:
{
"mcpServers": { "ctxcap": { "command": "npx", "args": ["-y", "ctxcap-mcp"] } } }
The same stdio command works with Claude Code, Codex, and Cursor. See the MCP package guide for client-specific setup. The server reads the MCP client's current working directory and makes no network calls. Registry metadata is prepared in server.json; publication is manual and intentionally not performed by this repository workflow.
Tools exposed:
| Tool | Description |
|---|---|
measure_context | Returns the full JSON report for the current working directory |
context_budget_plan | Returns a deterministic ranked splice plan with safety classifications and preserve spans |
context_budget_verify | Reports missed edits and preserve-span violations after applying a plan |
trim_to_budget | Deprecated alias for context_budget_plan; always returns apply: false |
The agent loop is also available as the five-line llms.txt contract. The standalone MCP wrapper keeps plan verification in the same server process; the CLI persists plans under .ctxcap/plans/.
Output schema
{
"schema": "ctxcap/v1", "approximate": true, "tokenizer": "gpt-tokenizer@3.0.1", "total": 1247, "totalBudget": 40000, "delta": +82, "over": false, "baselineFound": true, "files": [ { "path": "AGENTS.md", "tokens": 420, "delta": +12, "budget": 500 } ], "suggestions": [] }
Full report schema: schema/report.schema.json. Plan schema: schema/plan.schema.json. Plan responses include ranked plan entries, preserve spans, and a diff summary.
Accuracy
Counts, tokensFreed, and confidence use heuristics and are approximate against Claude and Gemini (±5% for token counts). Every report carries "approximate": true and the tokenizer ID. Compare deltas, not absolutes; review the plan before applying it.
Packages
| Package | Description |
|---|---|
ctxcap | CLI + GitHub Action + embedded MCP server |
ctxcap-mcp | Standalone MCP server wrapper (thin bin, pulls ctxcap as a dep) |
Publish and share
The packages are published on npm:
npm view ctxcap version # 1.2.0
npm view ctxcap-mcp version # 0.1.2
Share the npm packages, the GitHub repository, or the pinned GitHub Action:
- CLI:
npx -y ctxcap@1.2.0 - MCP:
npx -y ctxcap-mcp@0.1.2 - Action:
Naeha-S/ctxcap@v1.2.0 - Repository: https://github.com/Naeha-S/ctxcap
For a release post, show a real before/after from another repository, include the plan and verification loop, and link to the cold-install results. Ask early users to report false positives from their context-file layouts.
MIT.