Communitygithub.com

context-budget

Claude Code のコンテキストウィンドウの消費量を、エージェント、スキル、MCPサーバー、ルールごとに監査します。肥大化、冗長なコンポーネントを特定し、優先順位付けされたトークン節約提案を生成します。コンテキストウィンドウが急速に埋まってきて、その原因となっているエージェント、スキル、MCPサーバー、またはルールを特定したい場合に使用します。

context-budget とは?

Context Budget スキルは、Claude Code セッション内で読み込まれているすべてのコンポーネント(エージェント、スキル、ルール、MCPサーバー、CLAUDE.md)をスキャンし、トークンのオーバーヘッドを分析します。各コンポーネントのトークン消費量を推定し、ファイルサイズの大きさ、重複、冗長な記述、不要なMCPサーバーの購読など、コンテキストを圧迫する問題パターンを検出します。最終的に、コンテキスト予算レポートを生成し、どのコンポーネントがどれだけのトークンを消費しているかを可視化するとともに、トークン削減のための具体的なアクションを優先順位付きで提案します。このスキルはClaude Code上で動作し、`/context-budget` コマンドによって呼び出されます。通常監査と詳細モード(`--verbose`)をサポートし、ファイルごとのトークン数、行ごとの内訳、重複ルールの行比較、MCPツールごとのスキーマサイズ推定などを出力できます。開発者はこのスキルを使って、コンテキストウィンドウの使用状況を把握し、パフォーマンス低下の原因を特定し、新しいコンポーネントを追加する前に空き容量を確認することができます。

対応✓Claude Code~Codex CLI~Cursor
npx skills add https://github.com/affaan-m/ECC/tree/main/skills/context-budget

お気に入りのAIに質問する

このエージェントスキルを事前に読み込んだ状態で新しいチャットを開きます。

ドキュメント

コンテキスト予算 (Context Budget)

Claude Code セッション内のすべての読み込まれているコンポーネントにおけるトークンのオーバーヘッドを分析し、コンテキスト領域を回復するための実行可能な最適化を明らかにします。

使用するタイミング

  • セッションのパフォーマンスが低下している、または出力品質が劣化している場合
  • 最近多くのスキル、エージェント、またはMCPサーバーを追加した場合
  • 実際にどの程度のコンテキストの空き容量があるかを把握したい場合
  • さらにコンポーネントを追加する予定があり、追加可能かどうかを確認したい場合
  • /context-budget コマンドを実行する場合(このスキルがバックエンドとして機能します)

仕組み

フェーズ1: インベントリ

すべてのコンポーネントディレクトリをスキャンし、トークン消費量を推定します。

エージェント (agents/*.md)

  • ファイルごとに行数とトークン数をカウント(単語数 × 1.3)
  • フロントマターの description の長さを抽出
  • フラグ: 200行超のファイル(重い)、30語超のdescription(肥大化したフロントマター)

スキル (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: 問題の検出

以下の問題パターンを特定します。

  • 肥大化したエージェントdescription — フロントマターのdescriptionが30語超で、Taskツールの呼び出しごとに読み込まれる
  • 重いエージェント — ファイルが200行超で、タスクツールのコンテキストを毎回膨張させる
  • 冗長なコンポーネント — エージェントのロジックを複製するスキル、CLAUDE.md を複製するルール
  • MCPの過剰購読 — 10サーバー超、または無料で利用可能なCLIツールをラップしたサーバー
  • CLAUDE.md の肥大化 — 冗長な説明、古いセクション、ルールであるべき指示

フェーズ4: レポート

コンテキスト予算レポートを生成します。

コンテキスト予算レポート
═══════════════════════════════════════

推定総オーバーヘッド: ~XX,XXX トークン
コンテキストモデル: Claude Sonnet (200K ウィンドウ)
有効利用可能コンテキスト: ~XXX,XXX トークン (XX%)

コンポーネント内訳:
┌─────────────────┬────────┬───────────┐
│ コンポーネント   │ 数      │ トークン   │
├─────────────────┼────────┼───────────┤
│ エージェント     │ N      │ ~X,XXX    │
│ スキル           │ N      │ ~X,XXX    │
│ ルール           │ N      │ ~X,XXX    │
│ MCPツール        │ N      │ ~XX,XXX   │
│ CLAUDE.md       │ N      │ ~X,XXX    │
└─────────────────┴────────┴───────────┘

警告: 検出された問題 (N 件):
[トークン節約量でランク付け]

上位3つの最適化案:
1. [アクション] → 約 ~X,XXX トークン節約
2. [アクション] → 約 ~X,XXX トークン節約
3. [アクション] → 約 ~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ツールリスト(ツールごとのサイズ)、重複ルール行の並列表示

追加前の空き容量確認

ユーザー: MCPサーバーをさらに5つ追加したいのですが、空き容量はありますか?
スキル: 現在のオーバーヘッド33% → 5サーバー追加(約50ツール)で約25,000トークン増加 → オーバーヘッド45%に
       推奨: まずCLIで代替可能なサーバーを2つ削除し、40%未満に抑える

ベストプラクティス

  • トークン推定: 散文には 単語数 × 1.3、コード中心のファイルには 文字数 / 4 を使用
  • MCPが最大のレバレッジポイント: 各ツールスキーマは約500トークン。30ツールのサーバー1つで、すべてのスキルを合わせたよりもコストがかかる
  • エージェントのdescriptionは常に読み込まれる: エージェントが呼び出されなくても、そのdescriptionフィールドはすべてのTaskツールのコンテキストに存在する
  • デバッグには詳細モード: 通常の監査ではなく、オーバーヘッドの原因となっている正確なファイルを特定する必要がある場合に使用
  • 変更後は監査を実行: エージェント、スキル、またはMCPサーバーを追加した後は、早期に肥大化を発見するために実行する

Individual skills in this repo

This repo contains 20 individual skills — each has its own dedicated page.

accessibility

Design, implement, and audit inclusive digital products using WCAG 2.2 Level AA. Use when building or auditing UI that must meet WCAG 2.2 Level AA, or when reviewing a change for keyboard, contrast, or screen-reader support.

affaan-m/content-engine

Create platform-native content systems for X, LinkedIn, TikTok, YouTube, newsletters, and repurposed multi-platform campaigns. Use when the user wants social posts, threads, scripts, content calendars, or one source asset adapted cleanly across platforms.

affaan-m/ECC

Multi-platform content distribution across X, LinkedIn, Threads, and Bluesky. Adapts content per platform using content-engine patterns. Never posts identical content cross-platform. Use when the user wants to distribute content across social platforms.

affaan-m/fal-ai-media

Unified media generation via fal.ai MCP — image, video, and audio. Covers text-to-image (Nano Banana), text/image-to-video (Seedance, Kling, Veo 3), text-to-speech (CSM-1B), and video-to-audio (ThinkSound). Use when the user wants to generate images, videos, or audio with AI.

affaan-m/manim-video

日本語翻訳:このファイルは manim-video 用の日本語翻訳が必要です

affaan-m/remotion-video-creation

Remotion のベストプラクティス - React で動画を作成する。3D、アニメーション、音声、字幕、チャート、トランジションなどをカバーするドメイン固有の29のルール。

affaan-m/video-editing

AI-assisted video editing workflows for cutting, structuring, and augmenting real footage. Covers the full pipeline from raw capture through FFmpeg, Remotion, ElevenLabs, fal.ai, and final polish in Descript or CapCut. Use when the user wants to edit video, cut footage, create vlogs, or build video content.

agent-architecture-audit

Full-stack diagnostic for agent and LLM applications. Audits the 12-layer agent stack for wrapper regression, memory pollution, tool discipline failures, hidden repair loops, and rendering corruption. Produces severity-ranked findings with code-first fixes. Essential for developers building agent applications, autonomous loops, or any LLM-powered feature. Use when an agent or LLM feature misbehaves and the failing layer is unknown, or before shipping an agent stack.

agent-eval

Head-to-head comparison of coding agents (Claude Code, Aider, Codex, etc.) on custom tasks with pass rate, cost, time, and consistency metrics. Use when choosing between coding agents, or when a change to an agent setup needs measured pass rate, cost, and time rather than an impression.

agent-harness-construction

Design and optimize AI agent action spaces, tool definitions, and observation formatting for higher completion rates. Use when defining or revising an agent

agentic-engineering

Operate as an agentic engineer using eval-first execution, decomposition, and cost-aware model routing. Use when planning or executing engineering work that agents will carry out end to end.

agentic-os

Build persistent multi-agent operating systems on Claude Code. Covers kernel architecture, specialist agents, slash commands, file-based memory, scheduled automation, and state management without external databases. Use when building a persistent multi-agent system on Claude Code with its own memory, commands, and scheduling.

agent-introspection-debugging

Structured self-debugging workflow for AI agent failures using capture, diagnosis, contained recovery, and introspection reports. Use when an agent run fails and you need a reproducible diagnosis instead of a retry.

agent-payment-x402

Add x402 payment execution to AI agents with per-task budgets, spending controls, and non-custodial wallets. Supports Base through agentwallet-sdk and X Layer through OKX Payments / OKX Agent Payments Protocol. Use when an agent must pay for something itself and needs per-task budgets, spending controls, and a non-custodial wallet.

agent-self-evaluation

Use after completing any non-trivial task. The agent self-rates its output on 5 axes — accuracy, completeness, clarity, actionability, conciseness — with concrete evidence per criterion. Produces a structured 1-5 scorecard with specific improvement suggestions.

agent-sort

Build an evidence-backed ECC install plan for a specific repo by sorting skills, commands, rules, hooks, and extras into DAILY vs LIBRARY buckets using parallel repo-aware review passes. Use when ECC should be trimmed to what a project actually needs instead of loading the full bundle.

ai-first-engineering

Engineering operating model for teams where AI agents generate a large share of implementation output. Use when setting team process, review gates, or ownership rules for a codebase largely written by agents.

ai-regression-testing

Regression testing strategies for AI-assisted development. Sandbox-mode API testing without database dependencies, automated bug-check workflows, and patterns to catch AI blind spots where the same model writes and reviews code. Use when adding regression coverage to AI-assisted code, or when the same model both wrote and reviewed a change.

android-clean-architecture

Clean Architecture patterns for Android and Kotlin Multiplatform projects — module structure, dependency rules, UseCases, Repositories, and data layer patterns. Use when structuring modules, layers, or data flow in an Android or KMP project.

angular-developer

Generates Angular code and provides architectural guidance. Trigger when creating projects, components, or services, or for best practices on reactivity (signals, linkedSignal, resource), forms, dependency injection, routing, SSR, accessibility (ARIA), animations, styling (component styles, Tailwind CSS), testing, or CLI tooling.

関連スキル