Skill v1.0.0
currentAutomated scan100/100name: session-context-mastery description: Master context window management for long Claude Code sessions. Use when starting complex multi-hour tasks, when sessions approach context limits, or when output quality degrades mid-session. Covers context budgeting, rewind strategy, compaction, subagent handoffs, and CLAUDE.md progressive disclosure. From Boris Cherny (Claude Code creator) and Thariq (Anthropic). id: session-context-mastery runtime: claude-only canonical_path: ~/.claude/skills/session-context-mastery/SKILL.md updated: 2026-05-18 tags: [context, session, compaction, rewind, budgeting, claude-code] source: shanraisshan/claude-code-best-practice metadata: version: "1.0.0"
Session Context Mastery
Prevent context rot. Manage the 200k window deliberately.
Context Budget Zones
| Zone | Fill % | State | Action | |
|---|---|---|---|---|
| Green | 0–30% | Full capability | None | |
| Yellow | 30–50% | Slight degradation begins | Monitor | |
| Orange / Dumb Zone | 50–70% | Noticeable quality loss | Compact or delegate | |
| Red | 70%+ | High context rot risk | Rewind or clear |
Rule: Compact or rewind before hitting 50% on complex tasks.
Three Strategies
1. Rewind (Precision Tool)
When: A tool call went wrong or context got polluted with bad output.
Ctrl+Z / /rewind
- Rewind to the point before the failed attempt
- Never try to fix a bad outcome on top of polluted context
- Before rewinding: ask subagent to "summarize findings from this section" first
2. Compact (Mid-Task Compression)
When: Context is filling but task isn't done yet.
/compact
- Lossy — appropriate for mid-task, non-critical context
- Claude summarizes what's happened, preserves goal state
- Best for: long research sessions, iterative debugging
3. Clear (Fresh Start)
When: Task is complete, or you need a fully clean slate.
/clear
- Complete reset — use only between major tasks
- Write key findings to files BEFORE clearing
Subagent Handoff Protocol
Delegate intermediate work instead of filling main context:
- Give subagent only the specific task + only relevant files
- Subagent works in isolation (fresh 200k context)
- Subagent returns ONLY the conclusion — not the reasoning trail
- You integrate the conclusion (small) not the process (large)
Keeps main context at 30-40% even for complex multi-step tasks.
CLAUDE.md Progressive Disclosure
Split large CLAUDE.md into modular rule files:
.claude/CLAUDE.md # Entry point — short, links othersrules/security.md # Load only for security tasksn8n-patterns.md # Load only for n8n workapi-contracts.md # Load only for API work
Reference with glob: @.claude/rules/security.md loads only when needed.
Target: <2,000 lines of focused context per task.
compact vs clear — Decision
| Situation | Use | |
|---|---|---|
| Mid-task, continuing the same goal | /compact | |
| Task complete, switching topics | /clear | |
| Last output was wrong/polluted | /rewind | |
| About to start fresh project | /clear |
Warning Signs of Context Rot
- AI starts repeating itself or looping
- Suggestions contradict earlier decisions in the same session
- Code quality noticeably drops without explanation
- AI "forgets" conventions established earlier in the session
Act immediately: compact, rewind, or delegate to subagent.
Session Start Checklist
- [ ] Clear context from previous session (unless explicitly continuing)
- [ ] Load ONLY files relevant to this specific task
- [ ] Set explicit goal for this session in first message
- [ ] For multi-session projects: load STATE artifacts (see gsd-workflow skill)