affaan-m/ECC

context-budget

审核Claude Code上下文窗口在代理、技能、MCP服务器和规则中的消耗情况。识别膨胀、冗余组件,并提供优先的令牌节省建议。

66CollectingClaude Code
See how to use itView GitHub source
npx skills add https://github.com/affaan-m/ECC --skill "docs/zh-CN/skills/context-budget"
Automated source guide

Source checked Jul 28, 2026·Refresh due Oct 26, 2026

Reorganized from the pinned upstream SKILL.md

Turn context-budget's source instructions into a guide you can follow

According to the pinned SKILL.md from affaan-m/ECC: 分析 Claude Code 会话中每个已加载组件的令牌开销,并提供可操作的优化建议以回收上下文空间。

npx skills add https://github.com/affaan-m/ECC --skill "docs/zh-CN/skills/context-budget"
Check the pinned source

Best fit

  • 审核Claude Code上下文窗口在代理、技能、MCP服务器和规则中的消耗情况。识别膨胀、冗余组件,并提供优先的令牌节省建议。

Bring this context

  • A concrete task that matches the documented purpose of context-budget.
  • The files, examples, or context the task depends on.
  • Your constraints, target environment, and definition of done.

Expected outputs

  • A result that follows the pinned context-budget instructions.
  • A concise record of assumptions, inputs used, and unresolved questions.
  • A final check against the source workflow and relevant permission signals.

Key source sections

Read context-budget through these 5 source sections

Sections are extracted automatically from the pinned SKILL.md and link back to the source.

01

使用时机

会话性能感觉迟缓或输出质量下降 你最近添加了许多技能、代理或 MCP 服务器 你想知道实际有多少上下文余量 计划添加更多组件,需要知道是否有空间 运行 /context-budget 命令(本技能为其提供支持)

SKILL.md · 使用时机
会话性能感觉迟缓或输出质量下降你最近添加了许多技能、代理或 MCP 服务器你想知道实际有多少上下文余量
02

工作原理

统计每个文件的行数和令牌数(单词数 × 1.3) 提取 description 前言长度 标记:文件 200 行(繁重),描述 30 词(臃肿的前言)

SKILL.md · 工作原理
统计每个文件的行数和令牌数(单词数 × 1.3)提取 description 前言长度标记:文件 200 行(繁重),描述 30 词(臃肿的前言)
03

阶段 1:清单

统计每个文件的行数和令牌数(单词数 × 1.3) 提取 description 前言长度 标记:文件 200 行(繁重),描述 30 词(臃肿的前言)

SKILL.md · 阶段 1:清单
统计每个文件的行数和令牌数(单词数 × 1.3)提取 description 前言长度标记:文件 200 行(繁重),描述 30 词(臃肿的前言)
04

阶段 2:分类

Review the “阶段 2:分类” section in the pinned source before continuing.

SKILL.md · 阶段 2:分类
Review and apply the “阶段 2:分类” source section.
05

阶段 3:检测问题

臃肿的代理描述 — 前言中描述 30 词,会在每次任务工具调用时加载 繁重的代理 — 文件 200 行,每次生成时都会增加任务工具的上下文 冗余组件 — 重复代理逻辑的技能,重复 CLAUDE.md 的规则 MCP 超额订阅 — 10 个服务器,或包装了可免费使用的 CLI 工具的服务器 CLAUDE.md 臃肿 — 冗长的解释、过时的部分、本应成为规则的指令

SKILL.md · 阶段 3:检测问题
臃肿的代理描述 — 前言中描述 30 词,会在每次任务工具调用时加载繁重的代理 — 文件 200 行,每次生成时都会增加任务工具的上下文冗余组件 — 重复代理逻辑的技能,重复 CLAUDE.md 的规则

SkillSignal prompt templates

Provide the task, context, and acceptance criteria

These prompts were written by SkillSignal from the source structure; they are not upstream text.

Task-start prompt

Confirm source fit, inputs, and outputs before acting.

Use context-budget to help me with: [specific task]. Context: [files, data, or background]. Constraints: [environment, scope, and prohibited actions]. Before acting, check the pinned SKILL.md and explain which sections apply, what inputs are still missing, and what you will deliver.

Source-guided execution

Make the Agent explicitly follow the key extracted sections.

Apply the pinned context-budget source to [task]. Pay particular attention to these source sections: “使用时机”, “工作原理”, “阶段 1:清单”, “阶段 2:分类”, “阶段 3:检测问题”. Preserve the important decision at each step. Mark facts not covered by the source as “needs confirmation” instead of inventing them. Then verify the result against my acceptance criteria: [criteria].

Result-review prompt

Check omissions, permissions, and source drift before delivery.

Review the current context-budget result: (1) does it satisfy the original task; (2) were any applicable steps or limits in the pinned SKILL.md missed; (3) did it perform any unauthorized file, command, network, or data action; and (4) which conclusions remain unverified? List issues first, then fix only what the source or user authorization supports.

Output checklist

Verify each item before delivery

The task matches the purpose documented in the SKILL.md.

The source section “使用时机” has been checked.

The source section “工作原理” has been checked.

The source section “阶段 1:清单” has been checked.

The source section “阶段 2:分类” has been checked.

Inputs, constraints, and acceptance criteria are explicit.

Unverified facts, compatibility, and outcome claims are clearly marked.

Any file, command, network, or data action has been reviewed.

Choose a different workflow

When another Skill is the better fit

FAQ

What does context-budget do?

分析 Claude Code 会话中每个已加载组件的令牌开销,并提供可操作的优化建议以回收上下文空间。

How do I start using context-budget?

The catalog detected this source-specific install command: npx skills add https://github.com/affaan-m/ECC --skill "docs/zh-CN/skills/context-budget". Inspect the command and pinned source before running it.

Which Agent platforms does it declare?

claude code

Repository stars
234,327
Repository forks
35,711
Quality
66/100
Source repository last pushed

Quality breakdown

Based on traceable docs and repository signals; stars are not treated as quality.

66/100
Documentation20/30
Specificity14/25
Maintenance20/20
Trust signals12/25

Compare before choosing

Related Agent Skills and source variants

These links are selected from shared tasks, functions, stacks, platforms, and same-name variants. Compare the source owner, documentation, permissions, and maintenance signals.

View original Skill.mdThis page is parsed directly from the repository SKILL.md without editorial rewriting. Collected: Jul 28, 2026 · about 1 min

上下文预算

分析 Claude Code 会话中每个已加载组件的令牌开销,并提供可操作的优化建议以回收上下文空间。

使用时机

  • 会话性能感觉迟缓或输出质量下降
  • 你最近添加了许多技能、代理或 MCP 服务器
  • 你想知道实际有多少上下文余量
  • 计划添加更多组件,需要知道是否有空间
  • 运行 /context-budget 命令(本技能为其提供支持)

工作原理

阶段 1:清单

扫描所有组件目录并估算令牌消耗:

代理 (agents/*.md)

  • 统计每个文件的行数和令牌数(单词数 × 1.3)
  • 提取 description 前言长度
  • 标记:文件 >200 行(繁重),描述 >30 词(臃肿的前言)

技能 (skills/*/SKILL.md)

  • 统计 SKILL.md 的令牌数
  • 标记:文件 >400 行
  • 检查 .agents/skills/ 中的重复副本 — 跳过相同副本以避免重复计数

规则 (rules/**/*.md)

  • 统计每个文件的令牌数
  • 标记:文件 >100 行
  • 检测同一语言模块中规则文件之间的内容重叠

MCP 服务器 (.mcp.json 或活动的 MCP 配置)

  • 统计配置的服务器数量和工具总数
  • 估算模式开销约为每个工具 500 令牌
  • 标记:工具数 >20 的服务器,包装简单 CLI 命令的服务器 (gh, git, npm, supabase, vercel)

CLAUDE.md(项目级 + 用户级)

  • 统计 CLAUDE.md 链中每个文件的令牌数
  • 标记:合并总数 >300 行

阶段 2:分类

将每个组件归入一个类别:

类别标准操作
始终需要在 CLAUDE.md 中被引用,支持活动命令,或匹配当前项目类型保留
有时需要特定领域(例如语言模式),未在 CLAUDE.md 中引用考虑按需激活
很少需要无命令引用,内容重叠,或无明显的项目匹配移除或延迟加载

阶段 3:检测问题

识别以下问题模式:

  • 臃肿的代理描述 — 前言中描述 >30 词,会在每次任务工具调用时加载
  • 繁重的代理 — 文件 >200 行,每次生成时都会增加任务工具的上下文
  • 冗余组件 — 重复代理逻辑的技能,重复 CLAUDE.md 的规则
  • MCP 超额订阅 — >10 个服务器,或包装了可免费使用的 CLI 工具的服务器
  • CLAUDE.md 臃肿 — 冗长的解释、过时的部分、本应成为规则的指令

阶段 4:报告

生成上下文预算报告:

上下文预算报告
═══════════════════════════════════════

总预估开销:约 XX,XXX 个词元
上下文模型:Claude Sonnet (200K 窗口)
有效可用上下文:约 XXX,XXX 个词元 (XX%)

组件细分:
┌─────────────────┬────────┬───────────┐
│ 组件            │ 数量   │ 词元数    │
├─────────────────┼────────┼───────────┤
│ Agents          │ N      │ ~X,XXX    │
│ Skills          │ N      │ ~X,XXX    │
│ Rules           │ N      │ ~X,XXX    │
│ MCP tools       │ N      │ ~XX,XXX   │
│ CLAUDE.md       │ N      │ ~X,XXX    │
└─────────────────┴────────┴───────────┘

WARNING: 发现的问题 (N):
[按可节省词元数排序]

前 3 项优化建议:
1. [action] → 节省约 X,XXX 个词元
2. [action] → 节省约 X,XXX 个词元
3. [action] → 节省约 X,XXX 个词元

潜在节省空间:约 XX,XXX 个词元 (占当前开销的 XX%)

在详细模式下,额外输出每个文件的令牌计数、最繁重文件的行级细分、重叠组件之间的具体冗余行,以及 MCP 工具列表和每个工具模式大小的估算。

示例

基本审计

/context-budget
技能:扫描设置 → 16个代理(12,400个令牌),28个技能(6,200),87个MCP工具(43,500),2个CLAUDE.md(1,200)
       标记:3个重型代理,14个MCP服务器(3个可替换为CLI)
       最高节省:移除3个MCP服务器 → -27,500个令牌(减少47%开销)

详细模式

/context-budget --verbose
技能:完整报告 + 按文件细目显示 planner.md(213 行,1,840 个令牌),
       MCP 工具列表及每个工具的大小,重复规则行并排显示

扩容前检查

User: 我想再添加5个MCP服务器,有空间吗?
Skill: 当前开销33% → 添加5个服务器(约50个工具)会增加约25,000个tokens → 开销将升至45%
       建议:先移除2个可用CLI替代的服务器以保持在40%以下

最佳实践

  • 令牌估算:对散文使用 words × 1.3,对代码密集型文件使用 chars / 4
  • MCP 是最大的杠杆:每个工具模式约消耗 500 令牌;一个 30 个工具的服务器开销超过你所有技能的总和
  • 代理描述始终加载:即使代理从未被调用,其描述字段也存在于每个任务工具上下文中
  • 详细模式用于调试:需要精确定位导致开销的确切文件时使用,而非用于常规审计
  • 变更后审计:添加任何代理、技能或 MCP 服务器后运行,以便及早发现增量
Source repo
affaan-m/ECC
Skill path
docs/zh-CN/skills/context-budget/SKILL.md
Commit SHA
4e973d3eaf92
Repository license
MIT
Data collected