Ai Context Kit

io.github.ofershap由 GitHub 账号 ofershap 发布v0.1.2更新于 Oct 24, 2026

Lint, measure, and sync AI context files across Cursor, Claude Code, Copilot.

已验证STDIO仅桌面开发者工具AI 与机器学习

概览

AI 生成的概览

一个本地工具包,让助手加载、测量、检查、筛选并同步 Cursor、Claude Code、Copilot 等工具的 AI 上下文规则文件。

可以做什么
加载并自动识别 Cursor、Claude Code、AGENTS.md、Copilot、Windsurf 和 Cline 等格式的上下文规则文件,解析 frontmatter 并估算每个文件的 token 数、预算检查和占比。检查规则中的冲突、重复、超大文件、目录列表和含糊指令,并给出 0-100 分。按任务在 token 预算内只挑选相关规则,优先 alwaysApply,其次匹配任务词和标签。将单一规则来源同步到其他目标文件,支持试运行预览。按指定格式生成初始规则模板。
适用场景
适用于项目中积累多个重叠或互相矛盾的上下文文件时,想了解其 token 成本、找出冲突和重复,或只注入与当前任务相关的规则。也适合在 CI 流程中让规则错误导致构建失败。
运行要求
以本地 stdio 进程运行;需安装 npm 包 ai-context-kit,通过 npx 调用或作为库导入。未声明认证、环境变量或请求头。作用于包含受支持上下文文件的项目目录。
安装前请注意
sync 命令会写入 CLAUDE.md、AGENTS.md、copilot-instructions.md 等目标文件,建议先用试运行选项预览改动。token 数按每 4 字符约 1 token 粗略估算,并非精确分词结果。lint 在出错时以退出码 1 结束,可能导致 CI 构建失败。

安装

在 SourceWeft 中

  1. 打开 控制台中的 Ai Context Kit,将其添加到工作区。
  2. 为需要使用其工具的对话启用该服务。

Desktop only,通过 STDIO。 STDIO 服务会启动本地进程,因此需要 SourceWeft 桌面宿主。

其他 MCP 客户端

参照 仓库 中的启动说明。

README

[ai-context-kit]

ai-context-kit

How do you measure the token cost of your context?

You spent hours writing the perfect .md context file, just to find out that your agent got worse.
That's not a bug. That's what happens when nobody measures the cost of context.

[Try It Now]   [Install]   [See Example Output]   [Vote on Next Features]

[GitHub stars]   [npm version] [npm downloads] [CI] [TypeScript] [License: MIT] [PRs Welcome]


[Demo]

You write a CLAUDE.md. Then someone adds .cursor/rules/. Then a teammate drops in an AGENTS.md. Then someone copies in a .cursorrules file from a blog post. Nobody removes the old ones.

Six months later your project has four context files that overlap, contradict each other, and dump 8,000 tokens of directory listings and "follow best practices" into every conversation. Your agent follows all of it. It gets slower. It gets confused. You blame the model.

An ETH Zurich study (February 2026) measured what actually happens when you give agents context files:

  • Auto-generated context files reduced task success compared to providing nothing
  • Human-written ones only improved accuracy by 4%
  • Inference costs jumped 20%+ from wasted tokens
  • Performance dropped on some models because agents got too obedient - following unnecessary instructions instead of solving the actual problem

I kept hitting this in my own projects, so I built ai-context-kit - a toolkit to treat context like a budget. Measure it, trim it, inject only what the current task needs.

typescript
import { loadRules, measure, lint, select } from "ai-context-kit";
const rules = await loadRules("./");
measure(rules, 4000); // what does your context cost?lint(rules); // conflicts? duplicates? dead weight?select(rules, {  task: "fix auth bug", // only inject what matters  budget: 2000, // stay within token budget});

Quick Start

bash
npm install ai-context-kit

Run the CLI on any project to see what you're actually injecting:

bash
npx ai-context-kit measure
ai-context-kit measure - 6 rule file(s)
  Total: 4,821 tokens
  ############ 2,100 tokens (44%) - .cursor/rules/conventions.mdc  ######## 1,200 tokens (25%) - CLAUDE.md  ##### 890 tokens (18%) - .cursor/rules/api-patterns.mdc  ## 340 tokens (7%) - AGENTS.md  ## 180 tokens (4%) - .cursor/rules/testing.mdc  # 111 tokens (2%) - .github/copilot-instructions.md

Then lint it:

bash
npx ai-context-kit lint
ai-context-kit lint - 6 rule file(s)
  [!] .cursor/rules/conventions.mdc      Rule is 2100 tokens. Consider splitting to keep each file under 2000 tokens.
  [x] CLAUDE.md      Conflicts with AGENTS.md: "always use semicolons" vs "never use semicolons"
  [!] CLAUDE.md      Duplicated line also found in .cursor/rules/conventions.mdc. Duplicates waste tokens.
  [i] AGENTS.md      Contains vague instruction matching "follow best practices".      Specific instructions produce better results than general advice.
  Score: 70/100 (FAILED)

That's the difference between guessing and knowing.


What's Different

Other approachesai-context-kit
Context costNobody measures itToken count per file with budget check
ConflictsYou find out when the agent does something weirdDetects contradictions across all files automatically
DuplicatesSame rule in 3 files, 3x the tokensFlagged and scored
Task relevanceEvery rule injected every timeselect() picks only what matters for the current task
Multi-toolLocked to one IDE's formatWorks across Cursor, Claude Code, Copilot, Windsurf, Cline
CIHope for the bestlint exits with code 1 on errors. Drop it in your pipeline

What This Answers

  1. How much context am I injecting? Token count per file, percentage breakdown, budget check
  2. Are my rules fighting each other? Conflict detection across all files and formats
  3. What's wasting tokens? Directory listings, duplicate content, vague advice
  4. Which rules matter for this task? Task-relevant selection with token budget

How It Works

ai-context-kit reads every context file format in the ecosystem, parses frontmatter, estimates token cost, and gives you tools to analyze and manage them.

loadRules()Auto-detects .cursor/rules/, .cursorrules, CLAUDE.md, AGENTS.md, copilot-instructions.md, .windsurfrules, .clinerules
measure()Token cost per rule, percentage of total, budget check
lint()Conflicts, duplicates, bloat, vague instructions, useless directory trees. Scores 0-100
select()Picks rules relevant to the current task. Respects a token budget. alwaysApply rules first, then by relevance
sync()Single source of truth. Write once in .cursor/rules/, sync to CLAUDE.md, AGENTS.md, and the rest
init()Starter template with tips from the research

API

loadRules(rootDir?)

typescript
const rules = await loadRules("./");// Finds every context file in the project
const rules = await loadRules(".cursor/rules/");// Or load from a specific directory

Returns RuleFile[] with parsed frontmatter, body, format, path, and token count.

measure(rules, budget?)

typescript
const report = measure(rules, 4000);
report.totalTokens; // 3847report.overBudget; // falsereport.rules; // sorted by size, each with tokens + percentage

lint(rules)

typescript
const report = lint(rules);
report.score; // 85/100report.passed; // true (no errors, warnings don't fail)report.issues; // array of { rule, path, severity, message }

What the linter catches:

RuleSeverityWhat it finds
token-budgetwarning/errorFiles over 2,000 tokens (warning) or 5,000 (error)
empty-rulewarningFiles too short to do anything
duplicate-contentwarningSame instruction repeated across files
conflicterror"always use X" in one file, "never use X" in another
directory-listingwarning10+ line directory trees that agents don't need
vague-instructioninfo"follow best practices", "write clean code", "be consistent"

select(rules, options)

The core insight from the research: don't inject everything. Pick what matters.

typescript
const relevant = select(rules, {  task: "fix auth bug in /api/auth",  budget: 2000,  tags: ["security", "api"],  exclude: ["style"],});

Scoring: alwaysApply: true in frontmatter gets highest priority. Then task words matched against file paths and content. Then tag matches. Budget is respected - highest-scored rules are included first until the budget runs out.

sync(options)

Write rules once, sync everywhere.

typescript
await sync({  source: ".cursor/rules/",  targets: ["CLAUDE.md", "AGENTS.md", ".github/copilot-instructions.md"],});

Supports dryRun: true to preview changes without writing.

init(options?)

typescript
await init({ format: "cursor-rules" });// Creates .cursor/rules/conventions.mdc with research-backed starter template

CLI

bash
npx ai-context-kit lint                    # find issuesnpx ai-context-kit lint --json             # machine-readable outputnpx ai-context-kit measure                 # token cost breakdownnpx ai-context-kit measure --budget 4000   # check against budgetnpx ai-context-kit sync --source .cursor/rules/ --target CLAUDE.md,AGENTS.mdnpx ai-context-kit init                    # scaffold starter rulesnpx ai-context-kit init --format claude-md

All commands support --path <dir> to point at a different project root. lint exits with code 1 on errors (warnings pass).


Use with Vercel AI SDK / LangChain / Custom Agents

This isn't just for Cursor. If you're building agents with Vercel AI SDK, LangChain, or your own framework, ai-context-kit solves the same problem: how much context are you stuffing into the system prompt, and is it helping or hurting?

typescript
import { loadRules, select } from "ai-context-kit";import { generateText } from "ai";
const allRules = await loadRules("./rules");
const relevant = select(allRules, {  task: userMessage,  budget: 3000,});
const systemPrompt = relevant.map((r) => r.body).join("\n\n");
const { text } = await generateText({  model: openai("gpt-4o"),  system: systemPrompt,  prompt: userMessage,});

Any framework that takes a system prompt string. Any rules stored as markdown files.


Supported Formats

FormatFileUsed by
Cursor (modern).cursor/rules/*.mdcCursor IDE
Cursor (legacy).cursorrulesCursor IDE
Claude CodeCLAUDE.mdClaude Code
AGENTS.mdAGENTS.mdCross-agent standard
GitHub Copilot.github/copilot-instructions.mdGitHub Copilot
Windsurf.windsurfrulesWindsurf
Cline.clinerulesCline

ai-context-kit detects the format from the file path. No configuration needed.


Why not just write better rules?

The ETH Zurich study tested both human-written and LLM-generated context files. Human-written ones were better, but only by 4%. The real problem isn't quality - it's volume. More context means more tokens consumed by instructions the agent doesn't need for the current task. The winning strategy is fewer, task-relevant rules, not better prose.

How accurate is the token estimation?

ai-context-kit uses a 4-character-per-token approximation. This is intentionally simple and fast. It's accurate enough for budgeting and comparison (GPT-4 averages ~4 chars/token for English text). If you need exact counts, pipe the output through tiktoken or your model's tokenizer.

Does this work in CI?

Yes. npx ai-context-kit lint returns exit code 1 on errors, 0 on pass. Add it to your CI pipeline the same way you'd add eslint. The --json flag gives machine-readable output for custom reporting.


Tech Stack

ComponentTechnology
Language[TypeScript] strict mode
Testing[Vitest]
Bundler[tsup] ESM + CJS
DependenciesZero runtime dependencies

Contributing

PRs welcome. Whether it's a new lint rule, a format detector, or a bug fix - check out the contributing guide.


Author

[Made by ofershap]

[LinkedIn] [GitHub]


README built with README Builder

License

MIT © Ofer Shapira


Star this repo · Fork it · Report a bug · Join the discussion

来源:README.md,提交 8b1d7a5

工具

0
SourceWeft 尚未在沙箱中启动过该软件包,因此其工具未知。

版本历史

1
  1. v0.1.2最新Sep 16, 2026

评分

已满足适用检查项的 50%

该评分衡量此收录条目的完整程度,依据注册中心条目、端点与公开来源计算得出。它不是对服务器本身的评价,也不表示服务器安全或当前可用:可连通性是带日期的检查结果,评分也不包含安装量或用户评价。

  • 近 30 天内可连通25 分

    请保持端点能够响应 MCP 握手;SourceWeft 每 30 天探测一次。

  • 已声明认证方式10 分

    请在注册中心条目中声明凭据请求头,或保持端点能够响应探测,以便判定其认证方式。

  • 已列出工具15 分

    请让服务器在无凭据时响应 tools/list,或发布可在沙箱中无凭据启动的软件包。

  • 描述必需15 分
  • 图标10 分
  • 文档15 分
  • 许可证10 分