managing-agent-contextlisted
Install: claude install-skill Krosebrook/loxihart-skills
# Agent Context Window Management
The context window is the agent's working memory. When it fills up, the
agent loses access to its own history. This skill covers architectural
patterns for managing that constraint in production agent loops.
Distinct from `ecc:strategic-compact` which handles Claude Code session
compaction for interactive developer sessions. This skill covers autonomous
agent loops that accumulate context across hundreds of tool calls.
---
## The Core Problem
Every turn of an agent loop adds tokens:
- The original task and system prompt (fixed)
- Each user message and assistant response (growing)
- Each tool call and tool result (growing fast)
- Accumulated reasoning and intermediate state (growing)
At some point: context limit reached → agent fails or must be restarted.
Solution: proactive context management before the limit is hit.
---
## Decision Tree
```
What's your situation?
│
├─ Agent is hitting context limits in production
│ → Section 1: Emergency Reduction Patterns
│
├─ Designing a new multi-turn agent
│ → Section 2: Context Budget Planning
│
├─ Building an autonomous loop (many tool calls)
│ → Section 3: Rolling Window Architecture
│
└─ Agent loses important context mid-session
→ Section 4: Critical Context Preservation
```
---
## Section 1: Emergency Reduction Patterns
If an agent is hitting context limits in production now:
**Option A: Truncate oldest messages (fastest fix)**
Drop the oldest user/