affaan-m/ECC/docs/zh-CN/skills/context-budget/SKILL.md
context-budget
Use it for engineering tasks; the detail page covers purpose, installation, and practical steps.
- Source repository stars
- 234,327
- Declared platforms
- 1
- Static risk flags
- 0
- Last source update
- 2026-07-27
- Source checked
- 2026-07-28
Decision brief
What it does—and where it fits
分析 Claude Code 会话中每个已加载组件的令牌开销,并提供可操作的优化建议以回收上下文空间。
Not for
- Tasks that require unconfirmed production actions or broad system permissions.
- Environments where the pinned source and install steps cannot be inspected.
Compatibility matrix
Platform support, with evidence labels
| Platform | Status | Evidence | What to check |
|---|---|---|---|
| Codex | Not declared | No explicit evidence | Portability before use |
| Claude Code | Declared | Source record | Install path and trigger |
| Cursor | Not declared | No explicit evidence | Portability before use |
| Gemini CLI | Not declared | No explicit evidence | Portability before use |
Installation
Inspect first. Install second.
The source command is displayed only when detected. A safe inspection prompt is always available so your agent can explain every action before execution.
npx skills add https://github.com/affaan-m/ECC --skill "docs/zh-CN/skills/context-budget"Inspect the Agent Skill "context-budget" from https://github.com/affaan-m/ECC/blob/4e973d3eaf92d97f8d2e2d8abb39d8bdc8711b38/docs/zh-CN/skills/context-budget/SKILL.md at commit 4e973d3eaf92d97f8d2e2d8abb39d8bdc8711b38. List every install step, command, network request, credential, file read/write, external action, and rollback step. Explain whether it fits my task. Do not install or execute anything until I approve.
Workflow
What the source asks the agent to do
- 01
使用时机
会话性能感觉迟缓或输出质量下降 你最近添加了许多技能、代理或 MCP 服务器 你想知道实际有多少上下文余量 计划添加更多组件,需要知道是否有空间 运行 /context-budget 命令(本技能为其提供支持)
会话性能感觉迟缓或输出质量下降你最近添加了许多技能、代理或 MCP 服务器你想知道实际有多少上下文余量 - 02
工作原理
统计每个文件的行数和令牌数(单词数 × 1.3) 提取 description 前言长度 标记:文件 200 行(繁重),描述 30 词(臃肿的前言)
统计每个文件的行数和令牌数(单词数 × 1.3)提取 description 前言长度标记:文件 200 行(繁重),描述 30 词(臃肿的前言) - 03
阶段 1:清单
统计每个文件的行数和令牌数(单词数 × 1.3) 提取 description 前言长度 标记:文件 200 行(繁重),描述 30 词(臃肿的前言)
统计每个文件的行数和令牌数(单词数 × 1.3)提取 description 前言长度标记:文件 200 行(繁重),描述 30 词(臃肿的前言) - 04
阶段 2:分类
Review the “阶段 2:分类” section in the pinned source before continuing.
Review and apply the “阶段 2:分类” source section.
Permission review
Static risk signals and limitations
No configured static risk pattern was detected
This is not proof of safety. Runtime behavior, indirect dependencies, and hidden external systems are outside the static scan.
Evidence record
Why each signal appears
| Signal | Value | Evidence type | Meaning |
|---|---|---|---|
| Quality score | 66/100 | Computed | Documentation, specificity, maintenance, and trust rules |
| Repository stars | 234,327 | Source | Repository attention, not individual Skill quality |
| Compatibility | 1 platforms | Source | Declared in the catalog source record |
| Usage guide | automated source guide | Editorial | Generated or reviewed according to the visible evidence level |
Pinned source
Provenance and original SKILL.md
- Repository
- affaan-m/ECC
- Skill path
- docs/zh-CN/skills/context-budget/SKILL.md
- Commit
- 4e973d3eaf92d97f8d2e2d8abb39d8bdc8711b38
- License
- MIT
- Collected
- 2026-07-28
- Default branch
- main
View the original SKILL.md
上下文预算
分析 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 服务器后运行,以便及早发现增量
Alternatives
Compare before choosing
affaan-m/ECC
context-budget
Audits Claude Code context window consumption across agents, skills, MCP servers, and rules. Identifies bloat, redundant components, and produces prioritized token-savings recommendations.
affaan-m/ECC
context-budget
Use it for engineering tasks; the detail page covers purpose, installation, and practical steps.
jackchuka/skills
claude-skill-spec-audit
Audit skill SKILL.md files for compliance with the agentskills.io specification and house conventions. Checks frontmatter fields (name, description, compatibility, metadata, argument-hint), metadata sub-fields (author, scope, layer, confirms), and layer/suffix consistency. Use when adding new skills, reviewing skill quality, or ensuring all skills follow the spec. Triggers: "audit skills", "check skill spec", "skill compliance", "are my skills up to spec", "/claude-skill-spec-audit".
affaan-m/ECC
autonomous-loops
Patterns and architectures for autonomous Claude Code loops — from simple sequential pipelines to RFC-driven multi-agent DAG systems.