| allowed-tools | ["Read","Write","Grep","Glob","Bash"] |
| description | Use when debugging fails 3 times, same approach repeats, or context usage exceeds 60% to trigger state dump and recovery. |
| name | context-health-monitor |
| trigger | ์ปจํ
์คํธ ์ํ ํ์ธ, ์ธ์
๋คํ, 3-strike ๋ฐ๋, ์ธ์
์ธ์์ธ๊ณ, context health, session handoff, ์ปจํ
์คํธ ์์ถ, context compact, ์ธ์
์ผ์์ค์ง, session pause, ์ํ ๊ฐ์ง, circular detection, ๋ถํ์ค์ฑ ๋ก๊น
, uncertainty logging, ์ปจํ
์คํธ ํ์ , context rot, ํจํด ์ถ์ถ, pattern extraction, ์ํ ์ ์ฅ, state dump, 3 strike rule, circular detection, context window full, token limit |
Quick Reference
- 3-Strike Rule: ๋์ผ ์ด์ 3ํ ์คํจ โ STOP โ STATE.md ์ ์ฅ โ fresh session ๊ถ์ฅ
- Circular Detection: ๋์ผ ์ ๊ทผ 2ํ ๋ฐ๋ณต โ ๊ทผ๋ณธ์ ๋์ ์ ์ ๋๋
/pause
- Uncertainty: ๋ช
ํํ์ง ์์ ์ ์ถ์ธก ๊ธ์ง โ DECISIONS.md ๊ธฐ๋ก ํ ์ฌ์ฉ์ ํ์ธ
- Context >60%: ํ ํฐ ์ฌ์ฉ๋ 60% ์ด๊ณผ ์ ์ฆ์
/compact ์คํ (80% ์๋ ์ )
- Pattern Extraction: ํต์ฌ ํ์ต ์ PATTERNS.md ์ ์ฅ (2KB/20๊ฐ ์ด๋ด ์ ์ง)
Purpose
Prevent "Context Rot" โ the quality degradation that occurs as the agent processes more information in a single session.
When This Skill Activates
The agent should self-monitor for these warning signs:
Warning Signs
| Signal | Threshold | Action |
|---|
| Repeated debugging | 3+ failed attempts | Trigger state dump |
| Going in circles | Same approach tried twice | Stop and reassess |
| Confusion indicators | "I'm not sure", backtracking | Document uncertainty |
| Context window filling | >60% token usage | Run /compact proactively |
| Session length | Extended back-and-forth | Recommend /pause or /handoff |
Behavior Rules
Rule 1: The 3-Strike Rule
If debugging the same issue fails 3 times:
- STOP attempting fixes
- Document in
.hxsk/STATE.md:
- What was tried
- What errors occurred
- Current hypothesis
- Recommend user start fresh session
- Do NOT continue with more attempts
Rule 2: Circular Detection
If the same approach is being tried again:
- Acknowledge the repetition
- List what has already been tried
- Propose a fundamentally different approach
- Or recommend
/pause for fresh perspective
Rule 3: Uncertainty Logging
When uncertain about an approach:
- State the uncertainty clearly
- Document in
.hxsk/DECISIONS.md:
- The uncertain decision
- Why it's uncertain
- Alternatives considered
- Ask user for guidance rather than guessing
Rule 4: Proactive Compaction
When context window usage exceeds ~60%:
- Run
/compact before auto-compaction kicks in (~80%)
- If task is nearly done: finish first, then compact
- If task is complex with much remaining work: compact now to preserve budget
- If context is beyond recovery (repeated compactions, degrading quality): use
/handoff and start fresh
Pattern Memory
Prerequisites
.hxsk/memories/ directory structure must exist
Purpose
Detect recurring failure patterns across sessions. Store health events for trend analysis so systemic issues are surfaced early.
On 3-Strike Trigger
Check if the same issue has recurred, then store the event:
Grep(pattern: "3-strike|{issue}", path: ".hxsk/memories/health-event/", output_mode: "files_with_matches")
bash .hxsk/hooks/md-store-memory.sh \
"3-Strike: {issue}" \
"{approaches tried, errors seen, current hypothesis}" \
"health,3-strike,{component}" \
"health-event"
If the search reveals the same issue appeared before, flag it as a recurring problem in the state dump.
On Circular Detection
Check if the same loop pattern was seen before, then store:
Grep(pattern: "circular|{approach}", path: ".hxsk/memories/health-event/", output_mode: "files_with_matches")
bash .hxsk/hooks/md-store-memory.sh \
"Circular: {approach}" \
"{what repeated, why it looped}" \
"health,circular,{component}" \
"health-event"
On Session Handoff
Persist session context for the next session:
bash .hxsk/hooks/md-store-memory.sh \
"Handoff: {reason}" \
"{current state, recommendations for next session}" \
"health,handoff" \
"session-handoff"
Proactive Check
When this skill activates, scan recent memory files for failure trends:
Glob(pattern: ".hxsk/memories/health-event/*.md")
Read the most recent files and review for clusters of 3-strike, circular, or blocked keywords. If a trend is detected (2+ similar events), warn the user proactively before beginning work.
State Dump Format
When triggered, write to .hxsk/STATE.md:
## Context Health: State Dump
**Triggered**: [date/time]
**Reason**: [3 failures / circular / uncertainty]
### What Was Attempted
1. [Approach 1] โ Result: [outcome]
2. [Approach 2] โ Result: [outcome]
3. [Approach 3] โ Result: [outcome]
### Current Hypothesis
[Best guess at root cause]
### Recommended Next Steps
1. [Fresh perspective action]
2. [Alternative approach to try]
### Files Involved
- [file1.ext] โ [what state it's in]
- [file2.ext] โ [what state it's in]
Pattern Extraction
When valuable patterns are discovered during a session, extract to .hxsk/PATTERNS.md:
What to Extract
| Category | Examples |
|---|
| Architecture | "jose > jsonwebtoken for Edge runtime" |
| Conventions | "API routes: src/app/api/{resource}/route.ts" |
| Gotchas | "httpOnly cookies require HTTPS even on localhost" |
| Integrations | "Stripe webhooks need raw body parser disabled" |
Extraction Protocol
- During task completion, identify reusable learnings
- Check current count:
grep -c "^-" .hxsk/PATTERNS.md
- If < 20 items: Append new pattern
- If >= 20 items: Replace oldest (least referenced) pattern
- Size check: Keep under 2KB
wc -c .hxsk/PATTERNS.md
Pattern Format
## {Category}
- {Concise pattern description} โ {file:line if applicable}
Context File Management
Active Layer (Read Every Session)
| File | Size Limit | Purpose |
|---|
| PATTERNS.md | 2KB | Core learnings |
| CURRENT.md | 1KB | Session context |
| prd-active.json | 3KB | Pending tasks |
Archive Layer (Don't Read Routinely)
| File/Folder | Purpose |
|---|
| JOURNAL.md | Session history |
| CHANGELOG.md | Change history |
| prd-done.json | Completed tasks |
| reports/ | Analysis reports |
| research/ | Research docs |
| archive/ | Monthly archives |
Integration
This skill integrates with:
/compact โ Proactive context compaction (Rule 4)
/handoff โ Lightweight session transfer when context is beyond recovery
/pause โ Full HXSK session handoff with state archival
/resume โ Loads the state dump context
PATTERNS.md โ Pattern extraction on session end
.gemini/GEMINI.md Rule 3 (Context Hygiene) โ After 3 failed debug attempts: STOP, summarize to STATE.md, document blocker in DECISIONS.md, recommend fresh session
Scripts
.hxsk/hooks/compact-context.sh: Archive old entries, prune PATTERNS.md to 2KB limit
Iron Laws
NO CONTINUE DEBUGGING WITHOUT STATE.md DUMP FIRST (After 3 failures)
NO REPEAT APPROACH WITHOUT ALTERNATIVE PROPOSAL OR /pause FIRST (After 2 loops)
NO EXCEED 80% CONTEXT WITHOUT /compact FIRST (Trigger at 60%)
NO APPEND TO PATTERNS.md WITHOUT SIZE/COUNT CHECK FIRST (Max 2KB, 20 items)
NO GUESS SOLUTION WITHOUT USER GUIDANCE FIRST (When uncertain)
NO STORE MEMORY WITHOUT .hxsk/memories/ DIRECTORY FIRST
NO RECOMMEND FRESH SESSION WITHOUT DOCUMENTING STATE FIRST
NO COMPACT MID-FINISH WITHOUT COMPLETING TASK FIRST (If task is nearly done)