How Context Window Management Works in Everything Claude Code: A Complete Guide
Everything Claude Code (ECC) uses a layered system of hooks, skills, and performance rules to monitor, preserve, and trim AI context within model token limits while maintaining session continuity.
Context window management is critical for long-running AI coding sessions. In the WorldFlowAI/everything-claude-code repository, ECC implements a sophisticated multi-layered approach that balances automatic safeguards with user-driven control. This article breaks down the exact mechanisms, file paths, and practical commands you need to manage context effectively.
Session-Level Persistence Hooks
ECC maintains continuous context across sessions through dedicated lifecycle hooks in scripts/hooks/.
Session Start Hook
When a new session begins, scripts/hooks/session-start.js automatically loads the most recent session transcript into the system prompt. This ensures the AI picks up exactly where the previous session ended without manual intervention.
// Triggered automatically on session initialization
// Located at: scripts/hooks/session-start.js
await runCommand('session-start');
Session End Hook
Conversely, scripts/hooks/session-end.js serializes the final transcript when a session terminates. This persisted state becomes the starting point for the next session.
Pre-Compaction Checkpoint
The scripts/hooks/pre-compact.js hook runs before any automatic /compact operation. It snapshots the current context state, enabling restoration if the compaction removes valuable information.
Strategic Manual Compaction
ECC includes a dedicated skill that guides users to compact context at logical breakpoints rather than arbitrary moments.
The Strategic Compact skill, defined in skills/strategic-compact/SKILL.md, recommends explicit /compact usage at three key phases:
- After research completion
- Before implementation begins
- After debugging concludes
This approach prevents long-running tasks from exhaustively consuming the context window while preserving relevant intermediate states.
# Example: compact after finishing research phase
/compact
The pre-compact.js hook first saves the full context, then the compaction reduces token usage. If critical information disappears, you can restore from the checkpoint.
Automatic Compaction Triggers
ECC doesn't rely solely on user discipline. The scripts/hooks/evaluate-session.js hook monitors session metrics and automatically suggests compaction when thresholds are met.
According to WORLDFLOWAI.md, ECC suggests /compact after approximately 50 tool calls. This heuristic indicates the context is approaching the model's token limit.
# When ECC displays:
# 👉 Suggest running `/compact` to keep context healthy
/compact
This automatic hint system catches runaway context growth before it degrades response quality.
Token Budget Performance Rules
ECC enforces specific constraints through rules/performance.md to prevent context window exhaustion.
Reserve Margin
Never use the final 20% of the context window for non-essential data. This buffer maintains headroom for critical operations and unexpected token spikes.
MCP Impact Awareness
Enabling all MCPs (Model Context Protocol providers) can collapse a 200k token window to approximately 70k tokens. ECC recommends selective activation:
# Enable only required MCPs
export MCP_ENABLED="git,search"
This dramatic reduction occurs because each active MCP injects its tool definitions and documentation into the context.
Mode-Specific Context Injection
ECC loads targeted context through dedicated system prompt files in contexts/, ensuring only necessary guidance enters the window:
| File | Purpose |
|---|---|
contexts/dev.md |
Development mode guidelines |
contexts/review.md |
Code review standards |
contexts/research.md |
Research and exploration patterns |
Rather than loading universal instructions, ECC injects mode-appropriate context. This selective loading minimizes token consumption while maximizing relevance.
Practical Workflow Example
A typical ECC session leveraging these context management features:
# 1. Session starts automatically loading prior transcript
# (handled by scripts/hooks/session-start.js)
# 2. Activate research mode context
# (loads contexts/research.md only)
# 3. After ~50 tool calls, ECC suggests:
/compact
# (scripts/hooks/pre-compact.js saves state first)
# 4. Switch to implementation mode
# (swaps to contexts/dev.md, research context removed)
# 5. Enable minimal MCPs
export MCP_ENABLED="git"
# 6. Session ends, transcript preserved
# (scripts/hooks/session-end.js serializes state)
Summary
- Session hooks (
session-start.js,session-end.js,pre-compact.js) maintain continuity and safety checkpoints across sessions - Strategic Compact skill guides manual compaction at logical task boundaries
- Automatic triggers suggest
/compactafter ~50 tool calls viaevaluate-session.js - Performance rules mandate 20% context reserve and selective MCP activation
- Mode-specific contexts load only relevant instructions from
contexts/*.mdfiles
Frequently Asked Questions
How does ECC restore context after restarting?
The scripts/hooks/session-start.js hook automatically loads the most recent serialized transcript into the system prompt when a new session begins. This eliminates manual context restoration.
What happens if I compact too aggressively?
The scripts/hooks/pre-compact.js hook creates a snapshot before any /compact operation. If compaction removes necessary information, the checkpoint enables context restoration.
Why does enabling all MCPs reduce my effective context window so drastically?
Each MCP injects its tool schemas, descriptions, and documentation into the context. With multiple providers active, this overhead can consume ~130k tokens of a 200k window, leaving far less for actual code and conversation.
When should I manually trigger /compact versus waiting for the automatic suggestion?
Use manual compaction at natural task boundaries (research complete, before implementation, after debugging) per skills/strategic-compact/SKILL.md. Wait for automatic suggestions only if your workflow lacks clear breakpoints or you've exceeded ~50 tool calls.
Have a question about this repo?
These articles cover the highlights, but your codebase questions are specific. Give your agent direct access to the source. Share this with your agent to get started:
curl -s "https://instagit.com/install.md" Maintain an open-source project? Get it listed too →