Skip to content
context-degradation logo

Context Degradation Monitor

context-degradation

Token-range severity zones (Green/Yellow/Orange/Red/Critical) with detection checklist, early warning indicators, and corrective routing actions for context window degradation

SKILL.md

Full skill instructions

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).

ZoneUsage %~Tokens (200K)StatusAction
Green< 65%< 130KHealthyNormal operation
Yellow65–80%130K–160KCautionBegin selective compression
Orange/​Red80–90%160K–180KWarningCompress aggressively; summarize completed phases; spawn fresh subagent if needed
Critical90–93%180K–186KSevereHalt complex reasoning; compress immediately; do not attempt multi-step tasks
Auto-compact> 93%> 186KImminentClaude 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):

  1. Repeated tool calls — Agent re-reads files already read in same session
  2. Contradictory reasoning — Later steps contradict earlier decisions
  3. Missing prior context — Agent "forgets" task scope or constraints stated at session start
  4. Over-explanation — Agent re-explains concepts already established
  5. 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:

  1. 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.
  2. Verify task state — Read .claude/​context/​runtime/​edit-counter.json and current task files to confirm what was completed before compaction and what remains.
  3. 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.
  4. 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.
  5. 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

  1. ALWAYS check token count at every phase boundary — not just when problems appear or after completing a large task.
  2. 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.
  3. ALWAYS treat 2+ early warning indicators as one severity zone higher than the raw usage percentage suggests.
  4. ALWAYS invoke context-compressor at Yellow zone (65–80%) before context bloat becomes severe — prevention is cheaper than recovery.
  5. 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-PatternWhy It FailsCorrect Approach
Waiting until output quality degrades before checking contextBy the time quality drops, the context is already in Red/​Critical zoneRun 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 forgottenSpawn fresh subagent at Critical zone (90%) with compressed context
Ignoring early warning indicators because token count looks fineIndicators are more reliable than raw token counts; a 30K session with 3 indicators is already YellowTreat 2+ indicators as one zone higher regardless of token count
Spawning a subagent without a written handoff documentSubagent starts from scratch, duplicating work or missing constraintsAlways write phase summary to .claude/​context/​tmp/ before spawning
Compressing context by deleting tool call results without summarizingCompression without summarization loses critical findings from earlier phasesSummarize 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.

More Finance & Trading skills

ponytail-debt logo
Finance & Trading

ponytail-debt

Harvest every `ponytail:` comment in the codebase into a debt ledger, so the deliberate shortcuts and deferrals ponytail leaves behind get tracked instead of rotting into "later means never". One-shot report, changes nothing.

155.5K 27.9K
View
stripe-integration logo
Finance & Trading

stripe-integration

Stripe payment processing with checkout sessions, subscriptions, webhooks, and customer management.

40.2K 12.9K
View

Build comprehensive 3-5 year financial models with revenue projections, cost structures, cash flow analysis, and scenario planning for early-stage startups. Use this skill when creating financial projections, calculating burn rate or runway, modeling fundraising scenarios, or preparing investor-r...

40.2K 12K
View
stock-analysis logo
Finance & Trading

stock-analysis

Stock and cryptocurrency analysis with portfolio management and multi-dimensional scoring.

46 11.9K
View
coinglass logo
Finance & Trading

coinglass

Real-time crypto derivatives positioning, whale tracking, liquidations, and institutional ETF flows across 37 specialized tools.

27 11.5K
View

Master dbt (data build tool) for analytics engineering with model organization, testing, documentation, and incremental strategies. Use when building data transformations, creating data models, or implementing analytics engineering best practices.

40.2K 10.5K
View

Finance AI tools

C

ChainClarity explains 700+ crypto whitepapers in plain English, with layered summaries, comparisons, research tools, alerts, and a $4.99 Pro plan.

Freemium
View
Finalle.ai logo
Finance

Finalle.ai

Stay Ahead with Finalle.ai: The Ultimate Financial News and Tools Platform

Free
View

AI-powered Pine Script code generator for TradingView

Paid
View
TradeUI logo
Finance

TradeUI

Empower your investment strategies with AI signals, option flow data, and advanced chart patterns.

Paid
View
D
Finance

Danelfin

Danelfin review covering its AI stock and ETF scores, rankings, portfolio tools, current pricing, strengths, risks, and alternatives for investors.

Freemium
View
E
Finance

Ellisense

A software for comprehensive market sentiment analysis.

Paid
View

'Stock Correlations' App by Freshly.ai: Reveal Stock Patterns and Trends

Free
View