# Context Manager

> Smart context selection engine. Analyzes the current task, consults the Project Graph, and returns only the documents and skills needed. Prevents context window overflow by loading minimum relevant information.

- Skill: `kok-o/context-manager-2` (Agent Skill, multi-file: 6 files)
- Install (CLI): `npx skillmds@latest add kok-o/context-manager-2`
- Raw SKILL.md: https://api.skillmd.com/api/skills/kok-o/context-manager-2/raw
- Safety review: pending
- Works with: Claude Code, Claude.ai, OpenAI Codex
- Category: Productivity
- Author: kok-o (https://skillmd.com/u/kok-o)
- Updated: 2026-09-17
- Page: https://skillmd.com/skills/kok-o/context-manager-2

---


# context-manager

## Overview

Deterministic context window optimizer. Analyzes user task intent and queries project dependency graphs to inject minimal relevant files and skills, preventing LLM attention loss and context pollution.

## When to Use

Activate during multi-file investigations, large refactorings, or complex tasks where dumping entire directory trees would blow past context budgets.

## Rules & Patterns

You are the **Context Manager**. Your job is to prevent context overload.

## How It Works

When given a task:

### Step 1: Classify the task

```yaml
task:
  type: [frontend | backend | fullstack | architecture | bugfix | refactor | deploy | review]
  scope: [module | feature | file | project-wide]
  module: {{module_name from Project Graph}}
```

### Step 2: Consult the Project Graph

If `docs/PROJECT_GRAPH.md` or `.graphify/graph.json` exists (or activate `graphify` skill to extract AST dependencies):

1. Find the module this task belongs to
2. Get the module's dependencies
3. Get the module's required skills
4. Get the files this task will likely touch

### Step 3: Apply Context Rules

Load `references/context-rules.md` and apply the task type → document mapping.

### Step 4: Return Context Package

Output a context package:

```yaml
context:
  documents:
    required:
      - docs/API.md          # sections: [appointments]
      - docs/ARCHITECTURE.md # sections: [backend, api-layer]
    optional:
      - docs/decisions/0003-postgres.md
    skipped:
      - docs/UI.md           # reason: backend task
      - docs/DATABASE.md     # reason: no schema change
  
  skills:
    loaded: [typescript, node, postgres, testing]
    skipped: [react, tailwind]  # reason: backend task
  
  project_graph:
    module: appointments
    dependencies: [auth, patients]
    affected_files:
      - src/modules/appointments/api/**
      - src/modules/appointments/services/**
```

### Step 5: Validate Budget

Check total token count. If over budget (see context-rules.md):

1. Trim Level 1 docs to summaries
2. Load only affected sections of Level 2 docs
3. Keep Level 3 (skills) at full detail

## Context Caching

After first compilation for a module, cache the result:

```
.cache/
  frontend.context.yaml
  backend.context.yaml
  appointments.context.yaml
```

Invalidate cache when:

- A document is updated
- A skill is added/removed
- The Project Graph changes
- A Decision Record is added

## Questions the Context Manager Can Answer

- "What documents do I need for this task?"
- "Which skills should be loaded?"
- "What modules are affected by this change?"
- "Is this context package within budget?"
- "Why was this document skipped?"


## Code Examples

See `EXAMPLES.md` for detailed code examples.

## Validation Checklist

What to verify during the review phase before completing the task.

## Common Mistakes

Anti-patterns and things to explicitly avoid. See `TROUBLESHOOTING.md`.

## Integration Notes

How this skill interacts with other skills.

