docs/architecture/CONTEXT_WINDOW_ANALYSIS.md
Date: 2025-10-21 Related Issue: #437 - Extreme Context Window Optimization Status: Analysis Complete
Problem: SuperClaude消費 55-60% のcontext window
Resolution (PR #449):
インストール時の読み込み:
~/.claude/superclaude/
├── framework/ # 全フレームワークドキュメント
│ ├── flags.md # ~5KB
│ ├── principles.md # ~8KB
│ ├── rules.md # ~15KB
│ └── ...
├── business/ # ビジネスパネル全体
│ ├── examples.md # ~20KB
│ ├── symbols.md # ~10KB
│ └── ...
├── research/ # リサーチ設定全体
│ └── config.md # ~10KB
├── commands/ # 全コマンド
│ ├── sc_brainstorm.md
│ ├── sc_test.md
│ ├── sc_cleanup.md
│ ├── ... (30+ files)
└── modes/ # 全モード
├── MODE_Brainstorming.md
├── MODE_Business_Panel.md
├── ... (7 files)
Total: ~210KB (推定 50K-60K tokens)
問題点:
~/.claude/ に展開インストール時の読み込み:
site-packages/superclaude/
├── __init__.py # Package metadata (~0.5KB)
├── pytest_plugin.py # Plugin entry point (~6KB)
├── pm_agent/ # PM Agentコアのみ
│ ├── __init__.py
│ ├── confidence.py # ~8KB
│ ├── self_check.py # ~15KB
│ ├── reflexion.py # ~12KB
│ └── token_budget.py # ~10KB
├── execution/ # 実行エンジン
│ ├── parallel.py # ~15KB
│ ├── reflection.py # ~8KB
│ └── self_correction.py # ~10KB
└── cli/ # CLI(使用時のみ)
├── main.py # ~3KB
├── doctor.py # ~4KB
└── install_skill.py # ~3KB
Total: ~88KB (推定 20K-25K tokens)
改善点:
Before (Upstream):
MCP tools (AIRIS Gateway後): 5K tokens (PR #449で改善済み)
Memory files (~/.claude/): 50K tokens (全ドキュメント読み込み)
SuperClaude components: 10K tokens (Component/Installer)
─────────────────────────────────────────
Total consumed: 65K tokens
Available for user: 135K tokens (65%)
After (This PR):
MCP tools (AIRIS Gateway): 5K tokens (同じ)
Memory files (~/.claude/): 0K tokens (何もインストールしない)
SuperClaude pytest plugin: 20K tokens (pytest起動時のみ)
─────────────────────────────────────────
Total consumed (session start): 5K tokens
Available for user: 195K tokens (97%)
※ pytest実行時: +20K tokens (テスト時のみ)
改善: 60K tokens削減 → 30%のcontext window回復
Before (Upstream):
PM Agent Skill全体読み込み:
├── implementation.md # ~25KB = 6K tokens
├── modules/
│ ├── git-status.md # ~5KB = 1.2K tokens
│ ├── token-counter.md # ~8KB = 2K tokens
│ └── pm-formatter.md # ~10KB = 2.5K tokens
└── 関連ドキュメント # ~20KB = 5K tokens
─────────────────────────────────────────
Total: ~17K tokens
After (This PR):
PM Agentコアのみインポート:
├── confidence.py # ~8KB = 2K tokens
├── self_check.py # ~15KB = 3.5K tokens
├── reflexion.py # ~12KB = 3K tokens
└── token_budget.py # ~10KB = 2.5K tokens
─────────────────────────────────────────
Total: ~11K tokens
改善: 6K tokens削減 (35%削減)
Before (Upstream):
全Skills強制インストール: 50K tokens
After (This PR):
デフォルト: 0K tokens
ユーザーが install-skill実行後: 使った分だけ
改善: 50K tokens削減 → オプトイン方式
| 状況 | Before (Upstream + PR #449) | After (This PR) | 改善 |
|---|---|---|---|
| 起動時 | 135K tokens (65%) | 195K tokens (97%) | +60K ⬆️ |
| pytest実行時 | 135K tokens (65%) | 175K tokens (87%) | +40K ⬆️ |
| Skills使用時 | 95K tokens (47%) | 195K tokens (97%) | +100K ⬆️ |
Issue #437のみ (PR #449):
Issue #437 + This PR:
PM Agent Core:
Pytest Integration:
@pytest.mark.confidence_check)CLI Commands:
superclaude doctor (health check)superclaude install-skill (Skills installation)superclaude --versionSkills System:
superclaude install-skill pm)Commands/Modes:
Framework Docs:
~/.claude/superclaude/framework/なし - すべて代替手段あり:
# Before/After同一テストスイート
uv run pytest tests/pm_agent/ -v
Result: 79 passed ✅
# Plugin auto-discovery確認
uv run pytest tests/test_pytest_plugin.py -v
Result: 18 passed ✅
# インストール正常性確認
make doctor
Result:
✅ pytest plugin loaded
✅ Skills installed (optional)
✅ Configuration
✅ SuperClaude is healthy
| 機能 | Before | After | Status |
|---|---|---|---|
| Confidence Check | ✅ | ✅ | 維持 |
| Self-Check | ✅ | ✅ | 維持 |
| Reflexion | ✅ | ✅ | 維持 |
| Token Budget | ✅ | ✅ | 維持 |
| Pytest Fixtures | ✅ | ✅ | 維持 |
| CLI Commands | ✅ | ✅ | 維持 |
| Skills Install | 自動 | オプション | 改善 |
| Framework Docs | ~/.claude | PyPI | 改善 |
| MCP Integration | ✅ | ✅ | 維持 |
結論: 機能喪失なし、すべて維持または改善 ✅
現在:
# pytest起動時に全モジュールimport
from superclaude.pm_agent import confidence, self_check, reflexion, token_budget
提案:
# 使用時のみimport
def confidence_checker():
from superclaude.pm_agent.confidence import ConfidenceChecker
return ConfidenceChecker()
効果: pytest起動時 20K → 5K tokens (15K削減)
現在:
# 事前にインストール必要
superclaude install-skill pm-agent
提案:
# 使用時に自動ダウンロード & キャッシュ
@pytest.mark.usefixtures("pm_agent_skill") # 自動fetch
def test_example():
...
効果: Skills on-demand、ストレージ節約
Issue #437への貢献:
機能喪失リスク: ゼロ ✅
Context Window最適化:
推奨: このPRはIssue #437の完全な解決策 ✅