Context Degradation Monitor
Detects context window degradation and prescribes corrective actions before accuracy drops.
Severity Zones
Thresholds are expressed as a percentage of the context window budget. For a 200K window, Claude Code's auto-compact fires at 187K (93.5%, i.e., contextWindow - 13K).
| Zone |
Usage % |
~Tokens (200K) |
Status |
Action |
| Green |
< 65% |
< 130K |
Healthy |
Normal operation |
| Yellow |
65–80% |
130K–160K |
Caution |
Begin selective compression |
| Orange/Red |
80–90% |
160K–180K |
Warning |
Compress aggressively; summarize completed phases; spawn fresh subagent if needed |
| Critical |
90–93% |
180K–186K |
Severe |
Halt complex reasoning; compress immediately; do not attempt multi-step tasks |
| Auto-compact |
> 93% |
> 186K |
Imminent |
Claude Code auto-compact will fire; initiate post-compact recovery (see below) |
Reference: Claude Code constant AUTOCOMPACT_BUFFER_TOKENS = 13,000. Auto-compact fires at contextWindow - 13K, so for a 200K window that is 187K (93.5%). "Lost in the middle" effect: middle tokens have 20–40% lower recall past ~100K.
Early Warning Indicators
Symptoms that context degradation is affecting output quality (regardless of token count):
- Repeated tool calls — Agent re-reads files already read in same session
- Contradictory reasoning — Later steps contradict earlier decisions
- Missing prior context — Agent "forgets" task scope or constraints stated at session start
- Over-explanation — Agent re-explains concepts already established
- Stale references — Agent references file paths or task IDs that were resolved earlier
If 2+ indicators are present, treat as one zone higher than token count suggests.
Corrective Routing by Zone
Yellow (65–80%):
- Invoke
Skill({ skill: 'context-compressor' }) at the current phase boundary
- Remove completed phase content from active context
- Keep: current task spec, key decisions, in-progress file list
Orange/Red (80–90%):
- Invoke
Skill({ skill: 'context-compressor' }) — aggressive summarization
- Write phase summary to
.claude/context/tmp/phase-summary-{date}.md
- Prune: all resolved task details, intermediate research, superseded plans
- Spawn fresh subagent if remaining work is complex
Critical (90–93%):
- Do NOT continue complex multi-step tasks in current agent
- Spawn a fresh subagent with only the compressed summary as context
- Current agent: write handoff doc → call TaskUpdate(completed) with handoff path in metadata
Auto-compact (>93%):
- Halt immediately
- Write emergency summary: what was done, what remains, key decisions
- Route to
session-handoff skill
- Invoke
Skill({ skill: 'session-handoff' }) before context window forces truncation
- See Post-Compact Recovery section below for steps after auto-compact fires
Detection Checklist (Run at Each Phase Boundary)
[ ] Usage < 65%? → Green, no action
[ ] Usage 65–80%? → Yellow, begin compression
[ ] Usage 80–90%? → Orange/Red, compress aggressively
[ ] Usage 90–93%? → Critical, spawn fresh agent
[ ] Usage > 93%? → Auto-compact imminent; initiate post-compact recovery
[ ] 2+ early warning indicators? → Upgrade one severity zone
[ ] Compression reminder file exists? → Invoke context-compressor immediately
Post-Compact Recovery
When Claude Code's auto-compact fires (or a microcompact is detected), the context has been silently truncated. Follow these steps to restore working state:
- Re-read active files — Read all files from the pre-compact snapshot's
activeFiles list (stored in .claude/context/runtime/pre-compact-snapshot.json). This restores the in-memory view of code you were editing.
- Verify task state — Read
.claude/context/runtime/edit-counter.json and current task files to confirm what was completed before compaction and what remains.
- Check for microcompact indicators — Look for a
microcompact-detected event in the flight recorder (.claude/context/runtime/flight-recorder.jsonl). If present, a silent compaction occurred without a PreCompact hook event; treat your current context as potentially incomplete.
- Reference the pre-compact snapshot — Load
.claude/context/runtime/pre-compact-snapshot.json to recover originalIntent, editCount, correctionCount, and the list of activeFiles written just before compaction.
- Re-invoke your current skill — If you were mid-skill when compaction fired, invoke the skill again so its procedures are in context before continuing work.
These steps ensure that after a compaction event (auto or silent), you resume with full knowledge of where you left off.
Integration
- Pairs with:
context-compressor, context-compressor, session-handoff
- Called by:
planner (at plan start), developer (after each phase), router (before large spawns)
- Trigger: Check at every phase boundary, not just when problems appear
Iron Laws
- ALWAYS check token count at every phase boundary — not just when problems appear or after completing a large task.
- NEVER continue complex multi-step tasks past 90% usage (Critical zone) in the same agent context — spawn a fresh subagent with a compressed handoff instead.
- ALWAYS treat 2+ early warning indicators as one severity zone higher than the raw usage percentage suggests.
- ALWAYS invoke
context-compressor at Yellow zone (65–80%) before context bloat becomes severe — prevention is cheaper than recovery.
- NEVER claim a task complete without writing a context summary when operating in Critical or Auto-compact zone — if it's not written down, the next agent won't know it happened.
Anti-Patterns
| Anti-Pattern |
Why It Fails |
Correct Approach |
| Waiting until output quality degrades before checking context |
By the time quality drops, the context is already in Red/Critical zone |
Run detection checklist at every phase boundary proactively |
| Continuing multi-step tasks past 90% usage (Critical zone) |
"Lost in the middle" effect causes 20–40% recall drop; decisions made early are forgotten |
Spawn fresh subagent at Critical zone (90%) with compressed context |
| Ignoring early warning indicators because token count looks fine |
Indicators are more reliable than raw token counts; a 30K session with 3 indicators is already Yellow |
Treat 2+ indicators as one zone higher regardless of token count |
| Spawning a subagent without a written handoff document |
Subagent starts from scratch, duplicating work or missing constraints |
Always write phase summary to .claude/context/tmp/ before spawning |
| Compressing context by deleting tool call results without summarizing |
Compression without summarization loses critical findings from earlier phases |
Summarize completed phase outputs before pruning raw tool results |
Memory Protocol (MANDATORY)
Before starting:
Read .claude/context/memory/learnings.md
After completing:
- New pattern ->
.claude/context/memory/learnings.md
- Issue found ->
.claude/context/memory/issues.md
- Decision made ->
.claude/context/memory/decisions.md
ASSUME INTERRUPTION: If it's not in memory, it didn't happen.
1---2name: context-degradation3description: 'Token-range severity zones (Green/Yellow/Orange/Red/Critical) with detection checklist, early warning indicators, and corrective routing actions for context window degradation'4version: 1.2.05category: 'Performance & Optimization'6agents: [context-compressor, planner, router]7user_invocable: true8invoked_by: both9tools: [Read, Write, Skill]10tags: [context, tokens, degradation, compression, performance, thresholds]11best_practices:12 - Check at every phase boundary, not just when problems appear13 - Treat 2+ early warning indicators as one zone higher14 - Spawn fresh subagent rather than continuing in critical zone15error_handling: graceful16verified: true17lastVerifiedAt: 2026-03-01T00:00:00.000Z18source: builtin19trust_score: 10020provenance_sha: 0218e724e27c08a521metadata:22 source: https://skillmd.com/skills/oimiragieo/context-degradation23---2425# Context Degradation Monitor2627Detects context window degradation and prescribes corrective actions before accuracy drops.2829## Severity Zones3031Thresholds are expressed as a percentage of the context window budget. For a 200K window, Claude Code's auto-compact fires at ~187K (~93.5%, i.e., `contextWindow - 13K`).3233| Zone | Usage % | ~Tokens (200K) | Status | Action |34| ------------ | ------- | -------------- | -------- | --------------------------------------------------------------------------------- |35| Green | < 65% | < 130K | Healthy | Normal operation |36| Yellow | 65–80% | 130K–160K | Caution | Begin selective compression |37| Orange/Red | 80–90% | 160K–180K | Warning | Compress aggressively; summarize completed phases; spawn fresh subagent if needed |38| Critical | 90–93% | 180K–186K | Severe | Halt complex reasoning; compress immediately; do not attempt multi-step tasks |39| Auto-compact | > 93% | > 186K | Imminent | Claude Code auto-compact will fire; initiate post-compact recovery (see below) |4041Reference: Claude Code constant `AUTOCOMPACT_BUFFER_TOKENS = 13,000`. Auto-compact fires at `contextWindow - 13K`, so for a 200K window that is 187K (93.5%). "Lost in the middle" effect: middle tokens have 20–40% lower recall past ~100K.4243## Early Warning Indicators4445Symptoms that context degradation is affecting output quality (regardless of token count):46471. **Repeated tool calls** — Agent re-reads files already read in same session482. **Contradictory reasoning** — Later steps contradict earlier decisions493. **Missing prior context** — Agent "forgets" task scope or constraints stated at session start504. **Over-explanation** — Agent re-explains concepts already established515. **Stale references** — Agent references file paths or task IDs that were resolved earlier5253If 2+ indicators are present, treat as one zone higher than token count suggests.5455## Corrective Routing by Zone5657**Yellow (65–80%):**5859- Invoke `Skill({ skill: 'context-compressor' })` at the current phase boundary60- Remove completed phase content from active context61- Keep: current task spec, key decisions, in-progress file list6263**Orange/Red (80–90%):**6465- Invoke `Skill({ skill: 'context-compressor' })` — aggressive summarization66- Write phase summary to `.claude/context/tmp/phase-summary-{date}.md`67- Prune: all resolved task details, intermediate research, superseded plans68- Spawn fresh subagent if remaining work is complex6970**Critical (90–93%):**7172- Do NOT continue complex multi-step tasks in current agent73- Spawn a fresh subagent with only the compressed summary as context74- Current agent: write handoff doc → call TaskUpdate(completed) with handoff path in metadata7576**Auto-compact (>93%):**7778- Halt immediately79- Write emergency summary: what was done, what remains, key decisions80- Route to `session-handoff` skill81- Invoke `Skill({ skill: 'session-handoff' })` before context window forces truncation82- See **Post-Compact Recovery** section below for steps after auto-compact fires8384## Detection Checklist (Run at Each Phase Boundary)8586```87[ ] Usage < 65%? → Green, no action88[ ] Usage 65–80%? → Yellow, begin compression89[ ] Usage 80–90%? → Orange/Red, compress aggressively90[ ] Usage 90–93%? → Critical, spawn fresh agent91[ ] Usage > 93%? → Auto-compact imminent; initiate post-compact recovery92[ ] 2+ early warning indicators? → Upgrade one severity zone93[ ] Compression reminder file exists? → Invoke context-compressor immediately94```9596## Post-Compact Recovery9798When Claude Code's auto-compact fires (or a microcompact is detected), the context has been silently truncated. Follow these steps to restore working state:991001. **Re-read active files** — Read all files from the pre-compact snapshot's `activeFiles` list (stored in `.claude/context/runtime/pre-compact-snapshot.json`). This restores the in-memory view of code you were editing.1012. **Verify task state** — Read `.claude/context/runtime/edit-counter.json` and current task files to confirm what was completed before compaction and what remains.1023. **Check for microcompact indicators** — Look for a `microcompact-detected` event in the flight recorder (`.claude/context/runtime/flight-recorder.jsonl`). If present, a silent compaction occurred without a PreCompact hook event; treat your current context as potentially incomplete.1034. **Reference the pre-compact snapshot** — Load `.claude/context/runtime/pre-compact-snapshot.json` to recover `originalIntent`, `editCount`, `correctionCount`, and the list of `activeFiles` written just before compaction.1045. **Re-invoke your current skill** — If you were mid-skill when compaction fired, invoke the skill again so its procedures are in context before continuing work.105106> These steps ensure that after a compaction event (auto or silent), you resume with full knowledge of where you left off.107108## Integration109110- Pairs with: `context-compressor`, `context-compressor`, `session-handoff`111- Called by: `planner` (at plan start), `developer` (after each phase), `router` (before large spawns)112- Trigger: Check at every phase boundary, not just when problems appear113114## Iron Laws1151161. **ALWAYS** check token count at every phase boundary — not just when problems appear or after completing a large task.1172. **NEVER** continue complex multi-step tasks past 90% usage (Critical zone) in the same agent context — spawn a fresh subagent with a compressed handoff instead.1183. **ALWAYS** treat 2+ early warning indicators as one severity zone higher than the raw usage percentage suggests.1194. **ALWAYS** invoke `context-compressor` at Yellow zone (65–80%) before context bloat becomes severe — prevention is cheaper than recovery.1205. **NEVER** claim a task complete without writing a context summary when operating in Critical or Auto-compact zone — if it's not written down, the next agent won't know it happened.121122## Anti-Patterns123124| Anti-Pattern | Why It Fails | Correct Approach |125| --------------------------------------------------------------------- | ----------------------------------------------------------------------------------------------------- | -------------------------------------------------------------------- |126| Waiting until output quality degrades before checking context | By the time quality drops, the context is already in Red/Critical zone | Run detection checklist at every phase boundary proactively |127| Continuing multi-step tasks past 90% usage (Critical zone) | "Lost in the middle" effect causes 20–40% recall drop; decisions made early are forgotten | Spawn fresh subagent at Critical zone (90%) with compressed context |128| Ignoring early warning indicators because token count looks fine | Indicators are more reliable than raw token counts; a 30K session with 3 indicators is already Yellow | Treat 2+ indicators as one zone higher regardless of token count |129| Spawning a subagent without a written handoff document | Subagent starts from scratch, duplicating work or missing constraints | Always write phase summary to `.claude/context/tmp/` before spawning |130| Compressing context by deleting tool call results without summarizing | Compression without summarization loses critical findings from earlier phases | Summarize completed phase outputs before pruning raw tool results |131132## Memory Protocol (MANDATORY)133134**Before starting:**135Read `.claude/context/memory/learnings.md`136137**After completing:**138139- New pattern -> `.claude/context/memory/learnings.md`140- Issue found -> `.claude/context/memory/issues.md`141- Decision made -> `.claude/context/memory/decisions.md`142143> ASSUME INTERRUPTION: If it's not in memory, it didn't happen.