/context-health
Analyze the current session context for health issues including degradation, poisoning indicators, and optimization opportunities.
System Prompt
EXECUTION DIRECTIVE: When the user invokes this command, you MUST:
- IMMEDIATELY analyze the current session context
- Calculate health metrics (token usage, degradation risk, poisoning indicators)
- Provide recommendations for improvement
DO NOT:
- Skip analysis steps
- Provide generic responses without actual metrics
- Modify any context (read-only analysis)
Usage
/context-health [options]
Options
| Option | Type | Default | Description |
|---|---|---|---|
--verbose | boolean | false | Show detailed metrics breakdown |
--recommendations | boolean | true | Include improvement suggestions |
--format | string | text | Output format (text, json, markdown) |
Analysis Components
1. Token Utilization
- Current token count (estimated)
- Percentage of context limit used
- Category breakdown (system prompt, conversation, tool outputs)
2. Attention Degradation
- Identify "lost-in-middle" risk areas
- Map critical information positions
- Flag attention-degraded regions (middle 60% of context)
3. Context Poisoning
- Error accumulation check
- Contradiction detection
- Hallucination marker identification
4. Health Score
- Composite score (0.0 - 1.0)
- Status classification (Healthy/Warning/Degraded/Critical)
Output Format
Standard Output
CONTEXT HEALTH REPORT
=====================
Health Score: 0.82
Status: Healthy
Metrics:
├── Token Utilization: 45%
├── Degradation Risk: Low
└── Poisoning Risk: None
Recommendations:
1. Context is healthy - continue monitoring
Verbose Output (--verbose)
CONTEXT HEALTH REPORT (DETAILED)
================================
Health Score: 0.72
Status: Warning
Token Analysis:
├── Total Tokens: ~36,000 / 80,000
├── System Prompt: 2,500 (7%)
├── Conversation: 18,000 (50%)
├── Tool Outputs: 15,500 (43%)
└── Utilization: 45%
Attention Distribution:
├── Beginning (0-10%): 8,000 tokens [HIGH ATTENTION]
├── Middle (10-90%): 64,000 tokens [DEGRADED ATTENTION]
└── End (90-100%): 8,000 tokens [HIGH ATTENTION]
Critical Information Positions:
├── System prompt: Position 0-2,500 ✓ Safe
├── Task context: Position 25,000-30,000 ⚠ At Risk
└── Recent outputs: Position 72,000-80,000 ✓ Safe
Poisoning Indicators:
├── Error accumulation: 2 errors detected (Low risk)
├── Contradictions: None detected
└── Hallucination markers: None detected
Recommendations:
1. Move critical task context closer to beginning or end
2. Consider summarizing tool outputs (43% of context)
3. Monitor error accumulation as session continues
JSON Output (--format json)
{
"health_score": 0.72,
"status": "warning",
"metrics": {
"token_count": 36000,
"utilization": 0.45,
"degradation_score": 0.28,
"poisoning_risk": "low"
},
"issues": {
"lost_in_middle": {
"at_risk": [25000, 30000],
"safe": [0, 2500, 72000, 80000]
},
"poisoning": {
"error_count": 2,
"contradictions": 0,
"hallucination_markers": 0
}
},
"recommendations": [
"Move critical task context closer to beginning or end",
"Consider summarizing tool outputs"
]
}
Examples
Basic Health Check
/context-health
Quick overview with health score and status.
Detailed Analysis
/context-health --verbose
Full breakdown with position analysis and category metrics.
Export for Logging
/context-health --format json
Machine-readable output for automated monitoring.
Recommendations Only
/context-health --recommendations --no-verbose
Focus on actionable improvements.
Related Components
Invokes Agent
context-health-analyst: Performs the actual analysis
Related Commands
/cx: Session management (can incorporate health checks)/cxq: Context query (complements health analysis)
Related Skills
context-degradation: Detection algorithmscontext-fundamentals: Core conceptscontext-optimization: Improvement strategies
Implementation Notes
This command invokes the context-health-analyst agent to perform analysis. The agent:
- Estimates token count using ~4 chars/token heuristic
- Simulates attention distribution based on U-shaped attention curve research
- Scans for error, contradiction, and hallucination patterns
- Calculates composite health score
- Generates context-aware recommendations
When to Use
Use this command when:
- Session feels "sluggish" or responses seem less coherent
- After many tool calls with verbose outputs
- Before starting a complex multi-step task
- To validate context quality after major changes
Not needed when:
- Short, simple conversations
- Starting a fresh session
- Context is clearly minimal
Success Output
When context health check completes:
✅ COMMAND COMPLETE: /context-health
Health Score: X.XX
Status: <Healthy|Warning|Degraded|Critical>
Token Utilization: X%
Degradation Risk: <Low|Medium|High>
Recommendations: N provided
Completion Checklist
Before marking complete:
- Token count estimated
- Degradation analyzed
- Poisoning checked
- Health score calculated
- Recommendations generated
Failure Indicators
This command has FAILED if:
- ❌ No health score calculated
- ❌ No status determined
- ❌ Analysis incomplete
- ❌ No output displayed
When NOT to Use
Do NOT use when:
- Fresh session just started
- Short simple conversation
- Context clearly minimal
Anti-Patterns (Avoid)
| Anti-Pattern | Problem | Solution |
|---|---|---|
| Ignore warnings | Context degrades | Act on recommendations |
| Skip after long session | Missed issues | Check periodically |
| No action on critical | Session failure | Summarize or restart |
Principles
This command embodies:
- #9 Based on Facts - Metric-based analysis
- #6 Clear, Understandable - Clear status
- #3 Complete Execution - Full health check
Full Standard: CODITECT-STANDARD-AUTOMATION.md