Context Master - Intelligent Context Management System
Stop losing context in long coding sessions. Let Context Master manage your AI's memory intelligently.
The Problem
Every AI coding agent has a context window limit. When conversations get long or codebases are large:
- The agent "forgets" earlier instructions
- Important decisions get lost in the noise
- Repetitive information wastes precious context
- The agent starts giving contradictory answers
Context Master solves this with a smart, tiered context management system.
Core Architecture
Three-Tier Context Model
┌─────────────────────────────────────────────┐
│ TIER 1: HOT CONTEXT (Always Loaded) │
│ - Current task description │
│ - Active file contents │
│ - Recent decisions (last 10) │
│ - User preferences │
│ Budget: 30% of context window │
├─────────────────────────────────────────────┤
│ TIER 2: WARM CONTEXT (Loaded on Demand) │
│ - Related file summaries │
│ - Architecture decisions │
│ - Error history & fixes │
│ Budget: 40% of context window │
├─────────────────────────────────────────────┤
│ TIER 3: COLD CONTEXT (Archived) │
│ - Old conversation summaries │
│ - Historical decisions │
│ - Resolved issues │
│ Accessed via semantic search │
│ Budget: 30% of context window │
└─────────────────────────────────────────────┘
Smart Features
1. Automatic Context Budget
The skill calculates optimal context allocation based on:
- Model context window size (128K, 200K, 1M, etc.)
- Current usage level (percentage consumed)
- Task complexity (number of files involved)
- Conversation length (number of turns)
When context reaches 70% capacity, it automatically:
- Summarizes the oldest conversation turns
- Archives resolved decisions
- Compresses redundant information
- Promotes critical info to Tier 1
2. Smart File Prioritization
When working with large codebases, not all files are equally important. Context Master uses a dependency graph to prioritize:
Priority Score = f(dependency_depth, change_frequency, relevance_to_task, test_coverage_inverse)
Files are ranked:
- P0 (Must Include): Currently editing, directly imported by editing files
- P1 (Should Include): Types/interfaces, utilities used by editing files
- P2 (Nice to Have): Related tests, configuration files
- P3 (Skip): Unrelated modules, documentation, generated files
3. Conversation Summarization
When summarizing conversations, Context Master preserves:
| What to Keep | What to Summarize | What to Discard |
|---|---|---|
| Final decisions | Discussion process | Greetings/pleasantries |
| Code changes made | Alternative approaches | Error output (keep summary) |
| Architecture choices | Reasoning chains | Repetitive confirmations |
| User preferences | Trade-off analysis | "OK", "thanks" responses |
| Open questions | Constraints discovered | Duplicate information |
| Error patterns | Debugging journey | Failed attempts summary |
4. Decision Log
Every important decision is captured in a structured format:
## Decision Log
### [DEC-001] Use Zustand instead of Redux (Session 3)
- **Date**: 2026-03-20
- **Context**: Choosing state management for new React project
- **Decision**: Use Zustand for state management
- **Reasoning**: Smaller bundle size, simpler API, sufficient for our scale
- **Alternatives Considered**: Redux Toolkit, Jotai, Context API
- **Impact**: Affects all components, store setup pattern
- **Reversible**: Yes (medium effort)
5. Rolling Context Window
Instead of a simple FIFO queue, Context Master uses a smart rolling window:
- Anchor points: Critical decisions and current task are always kept
- Recency bias: More recent information has higher priority
- Reference counting: Files/code mentioned multiple times stay longer
- Semantic relevance: Information related to current task is promoted
Session Management
Session Start Protocol
When a new session begins:
- Load project context from
.context/directory - Read decision log to understand past choices
- Detect project state (what was being worked on)
- Calculate context budget based on model and task
- Display summary: "Context Master: 47 files indexed, 23 decisions loaded, budget: 128K tokens"
During Session
- Monitor context usage every 5 turns
- Auto-summarize when reaching 70% threshold
- Track references to maintain importance scores
- Capture decisions when agent makes a choice
Session End Protocol
- Save current state to
.context/session-latest.md - Update decision log with any new decisions
- Archive old summaries that are no longer relevant
- Generate handoff note for next session
Cross-Session Handoff
## Session Handoff Note
**From**: Session #12 (2026-03-20 14:30)
**To**: Next session
### Current Task
Implementing user authentication flow with JWT tokens
### Progress
- [x] Login API endpoint
- [x] JWT token generation
- [ ] Token refresh mechanism
- [ ] Protected route middleware
### Key Decisions
- Using bcrypt for password hashing (DEC-015)
- JWT expires in 24h (DEC-016)
- Refresh tokens stored in httpOnly cookies (DEC-017)
### Open Questions
- Should we implement rate limiting on login?
### Files Modified
- src/api/auth.ts (added login endpoint)
- src/middleware/auth.ts (JWT verification)
- src/utils/jwt.ts (new file - token helpers)
### Next Steps
1. Implement refresh token rotation
2. Add rate limiting to login endpoint
3. Write integration tests for auth flow
Context Store Structure
.context/
├── config.toml # Context management config
├── decisions/
│ ├── DEC-001.md # Individual decisions
│ └── ...
├── summaries/
│ ├── session-001.md # Session summaries
│ └── ...
├── files/
│ ├── index.json # File dependency graph
│ └── priorities.json # Current file priorities
├── handoff.md # Latest handoff note
└── stats.json # Usage statistics
Smart Commands
| Command | Description |
|---|---|
"context status" |
Show current context usage and budget |
"context summarize" |
Force a conversation summary |
"context decisions" |
Show all decisions made |
"context handoff" |
Generate handoff note for next session |
"context priority <file>" |
Manually set file priority |
| `"context search " | Search archived context |
"context compact" |
Force context compaction |
"context budget <size>" |
Set context window size |
Anti-Patterns Prevented
- Context Amnesia: Agent forgets instructions from earlier in the conversation
- Decision Drift: Agent makes contradictory choices across sessions
- Noise Accumulation: Low-value information fills up the context window
- Repetition: Agent asks the same questions it already received answers to
- Context Shock: Too much new context loaded at once overwhelms the agent
Integration Notes
This skill works with any AI coding agent that supports the SKILL.md standard:
- Claude Code, Codex CLI, Cursor, Windsurf, GitHub Copilot
- CodeBuddy, OpenClaw, and any compatible agent
- No external dependencies required - all logic is embedded in this skill
- Context store uses plain markdown files for maximum compatibility