---
description: Context Management
alwaysApply: false
---

# Context Management

Rules for managing conversation context efficiently and preventing context window overflow.

## Capacity Thresholds

- **< 50%** — Normal operation
- **50-80%** — Monitor closely, prepare for summarization
- **80-90%** — MUST summarize immediately
- **> 90%** — CRITICAL: aggressive summarization, drop non-essential context

## What to Keep, Compress, and Remove

**Always preserve**: user's primary goal, current active task, recent messages (last 5-10), active file contents, current errors, active todos, critical constraints.

**Summarize**: completed tasks (keep outcome, drop process), old conversation history (extract key decisions), resolved errors (keep solution), closed todos.

**Discard**: redundant information, repeated explanations, failed attempt details (keep lessons learned), irrelevant file contents.

## Compression Techniques

Extract key decisions — collapse detailed discussions into outcome statements:

```markdown
Before: "Discussed OAuth2 vs JWT. Chose OAuth2. Decided on Google provider.
Chose HTTP-only cookies. Implemented with CSRF state parameter."
After: "Auth: OAuth2 + Google, HTTP-only cookies, CSRF via state param."
```

Summarize completed work — keep outcome, drop step-by-step process.

## Context Summary Format

```markdown
## Context Summary
**Goal**: [Primary objective]
**Completed**: [Outcome list]
**Active**: [Current tasks]
**Constraints**: [Key constraints]
**Key Decisions**: [Decision list]
```

## Proactive Management

- Before reading large files: ask if entire file is needed or specific sections
- At 75%: notify user summarization is approaching
- At 80%: summarize and notify what was compressed
- Never drop context silently — always summarize before removing

## Never Remove

- User's explicit requirements
- Active error messages
- Current file being edited
- Security constraints
- Breaking changes information
