tygwan

context-optimizer

1
0
# Install this skill:
npx skills add tygwan/cc-initializer --skill "context-optimizer"

Install specific skill from multi-skill repository

# Description

Optimize context loading for efficient token usage. Use when working with large codebases, context limits, or when the user mentions "context", "token", "optimize", "summarize", or asks to reduce context size.

# SKILL.md


name: context-optimizer
description: Optimize context loading for efficient token usage. Use when working with large codebases, context limits, or when the user mentions "context", "token", "optimize", "summarize", or asks to reduce context size.


Context Optimizer

Optimize AI context loading for efficient token usage and focused development sessions.

When to Use This Skill

Use this skill when:
- Working with large codebases (>50 files)
- Context window is approaching limits
- User mentions "context", "token", "optimize"
- Need to focus on specific subsystem
- Starting a new development session

Core Workflow

Step 1: Analyze Current Context

Identify loaded files:
- Recently read files
- Referenced documentation
- Active working files

Assess relevance:
- Current task requirements
- File dependencies
- Historical usage patterns

Step 2: Context Scoring

Score files by relevance (1-10):

Factor Weight Description
Direct relevance 40% Directly related to current task
Dependency chain 25% Required by relevant files
Recent access 20% Recently read or modified
Reference frequency 15% Often referenced in codebase

Step 3: Optimization Strategies

Strategy A: Essential Only

Load only:
- Files directly being modified
- Critical type definitions
- Immediate dependencies
Token savings: 60-80%

Strategy B: Focused Context

Load:
- Working files + 1 level dependencies
- Relevant documentation
- Key configuration
Token savings: 40-60%

Strategy C: Summarized Context

Load:
- Full working files
- Summaries of related files
- Index of available resources
Token savings: 30-50%

Context Summary Format

File Summary Template

## [filename] Summary
**Purpose:** [one-line description]
**Key exports:** [list of main functions/classes]
**Dependencies:** [key imports]
**Size:** [lines] lines

### Key Sections
- [Section 1]: Lines X-Y - [description]
- [Section 2]: Lines X-Y - [description]

Project Context Template

# Project Context Summary

## Architecture
- Pattern: [MVVM/MVC/etc]
- Language: [language + version]
- Framework: [framework details]

## Key Files
| File | Purpose | Priority |
|------|---------|----------|
| file1.cs | Main entry | High |
| file2.cs | Core logic | High |
| file3.cs | Utilities | Medium |

## Current Focus
Working on: [current task]
Relevant files: [list]

Output Format

Context Analysis Report

## Context Optimization Analysis

### Current Context
- Files loaded: 25
- Estimated tokens: ~45,000
- Utilization: 75%

### Recommended Optimization

**Strategy:** Focused Context
**Expected savings:** 40%

#### Keep (High Priority)
- ViewModel.cs - direct modification
- Model.cs - type definitions
- Services/*.cs - active dependencies

#### Summarize (Medium Priority)
- Utils/*.cs - create summaries
- Helpers/*.cs - create summaries

#### Defer (Low Priority)
- Tests/*.cs - load on demand
- Docs/*.md - reference only

### Action
Apply optimization? [Yes/No]

Integration with dev-docs-writer

This skill works with the dev-docs-writer agent for optimal context management:

Document Priority Loading

Priority 1 (Always Load):
  - docs/CONTEXT.md      # Quick reference, architecture snapshot
  - docs/PROGRESS.md     # Current phase, active tasks

Priority 2 (Phase-Specific):
  - docs/phases/phase-N/SPEC.md     # Current phase details
  - docs/phases/phase-N/TASKS.md    # Phase tasks
  - src/[active-module]/*           # Active development files

Priority 3 (On-Demand):
  - docs/PRD.md          # Requirements reference
  - docs/TECH-SPEC.md    # Technical details
  - src/**/*             # Specific files as needed

Session Continuity

## Starting a new session:

1. Load: docs/CONTEXT.md
2. Check: Current phase from PROGRESS.md
3. Load: Phase-specific files (docs/phases/phase-N/)
4. Resume: Work from last checkpoint

Token Budget Guidelines

Session Type Token Budget Loading Strategy
Quick check ~2K CONTEXT.md only
Standard dev ~10K CONTEXT + PROGRESS + active files
Deep dive ~30K All docs + relevant source
Full context ~50K+ Complete project load

Phase-Aware Context Loading

μžλ™ Phase 감지

# settings.json
context-optimizer:
  auto_load_phase_docs: true
  token_budget:
    quick: 2000
    standard: 10000
    deep: 30000
    full: 50000

Phase λ¬Έμ„œ λ‘œλ”© μ „λž΅

Phase 감지 흐름:
1. PROGRESS.mdμ—μ„œ ν˜„μž¬ Phase 확인
2. ν•΄λ‹Ή Phase 디렉토리 λ‘œλ“œ
3. SPEC.md β†’ λ²”μœ„ 및 μš”κ΅¬μ‚¬ν•­
4. TASKS.md β†’ ν˜„μž¬ μž‘μ—… λͺ©λ‘
5. CHECKLIST.md β†’ μ™„λ£Œ 체크

Phase별 μ»¨ν…μŠ€νŠΈ ν…œν”Œλ¦Ώ

# Phase {{N}} Context Summary

## ν˜„μž¬ μƒνƒœ
- Phase: {{PHASE_NAME}}
- μ§„ν–‰λ₯ : {{PROGRESS}}%
- ν™œμ„± Task: {{ACTIVE_TASKS}}

## 핡심 파일
{{PRIORITY_FILES}}

## ν˜„μž¬ μž‘μ—…
{{CURRENT_WORK}}

## μ°Έμ‘° λ¬Έμ„œ
- [SPEC.md](docs/phases/phase-{{N}}/SPEC.md)
- [TASKS.md](docs/phases/phase-{{N}}/TASKS.md)

μ„Έμ…˜ 볡ꡬ μ›Œν¬ν”Œλ‘œμš°

μƒˆ μ„Έμ…˜ μ‹œμž‘ μ‹œ:

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚  CONTEXT.md λ‘œλ“œ    │◀─── ν•„μˆ˜
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
          β”‚
          β–Ό
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚ PROGRESS.md 확인    │◀─── Phase N 감지
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
          β”‚
          β–Ό
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚ Phase N λ¬Έμ„œ λ‘œλ“œ   │◀─── SPEC + TASKS
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
          β”‚
          β–Ό
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚ μž‘μ—… 재개           β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

토큰 μ˜ˆμ‚°λ³„ Phase λ‘œλ”©

μ˜ˆμ‚° λ‘œλ“œ λ²”μœ„ 토큰
Quick CONTEXT.md + PROGRESS.md ~2K
Standard + ν˜„μž¬ Phase (SPEC, TASKS) ~10K
Deep + 인접 Phase + μ†ŒμŠ€ μ½”λ“œ ~30K
Full λͺ¨λ“  Phase + 전체 λ¬Έμ„œ ~50K+

Sprint 톡합

Phase와 Sprint λ™μ‹œ μ‚¬μš© μ‹œ:

Context Loading Priority:
  1. CONTEXT.md
  2. PROGRESS.md
  3. ν˜„μž¬ Sprint (sprints/sprint-N/)
  4. μ—°κ²°λœ Phase (phases/phase-N/)
  5. μ†ŒμŠ€ μ½”λ“œ

Best Practices

  1. Start Lean: Load minimum required context
  2. Expand as Needed: Add files when referenced
  3. Summarize Utilities: Keep only interfaces for helpers
  4. Cache Summaries: Reuse context summaries across sessions
  5. Document Dependencies: Track what requires what
  6. Use Phase Documents: Leverage doc-splitter phase structure
  7. Update PROGRESS.md: Record session outcomes for continuity
  8. Phase-First: ν˜„μž¬ Phase λ¬Έμ„œ μš°μ„  λ‘œλ“œ
  9. Token Budget: μ„Έμ…˜ μœ ν˜•μ— λ§žλŠ” 토큰 μ˜ˆμ‚° μ„€μ •

# Supported AI Coding Agents

This skill is compatible with the SKILL.md standard and works with all major AI coding agents:

Learn more about the SKILL.md standard and how to use these skills with your preferred AI coding agent.