Finds all REFACTOR markers in codebase, validates associated ADRs exist, identifies stale markers (30+ days old), and detects orphaned markers (no ADR reference)...
Quick Start ā What Is This | When to Use | Simple Example
Validation Flow ā Find Markers | Validate ADRs | Health Report
Help ā Troubleshooting | Anti-Patterns | Best Practices
Reference ā Health Categories | Remediation Guide
Monitors refactor health by detecting all active REFACTOR markers in the codebase, validating their associated ADRs exist, and identifying issues such as stale markers (>30 days old), orphaned markers (missing ADR), and completed-but-not-removed markers. Essential for maintaining clean refactor tracking, preventing technical debt accumulation, and ensuring refactor work is properly documented and completed.
Use this skill when:
Check refactor marker health across your codebase:
# Find all REFACTOR markers (file-level and method-level)
grep -rn "^# REFACTOR:" src/ --include="*.py"
grep -rn "# REFACTOR(" src/ --include="*.py"
# Validate ADR existence
test -f docs/adr/in_progress/027-service-result-migration.md && echo "ADR exists" || echo "ADR missing"
# Calculate marker age (if STARTED date present)
# Current date - STARTED date > 30 days = STALE
Typical output:
Use grep to locate both marker types:
File-level markers:
grep -rn "^# REFACTOR:" src/ --include="*.py" --include="*.ts" --include="*.js"
Method-level markers:
grep -rn "# REFACTOR(" src/ --include="*.py" --include="*.ts" --include="*.js"
Extract from each match:
File-level marker format:
# REFACTOR: ADR-027 - ServiceResult Migration
# STATUS: IN_PROGRESS
# STARTED: 2025-10-10
# PERMANENT_RECORD: docs/adr/in_progress/027-service-result-migration.md
Method-level marker format:
# REFACTOR(ADR-027): Migrate to ServiceResult pattern
def get_user(user_id: int):
pass
Parsing logic:
ADR-(\d+)# STATUS: line# STARTED: line (YYYY-MM-DD)# PERMANENT_RECORD: lineFor each unique ADR number found:
Check ADR existence:
# Search for ADR file in all ADR directories
find docs/adr -name "*027-*.md" -type f
Validation outcomes:
ADR location patterns to check:
docs/adr/in_progress/XXX-title.md # Active refactors
docs/adr/implemented/XXX-title.md # Completed refactors
docs/adr/deprecated/XXX-title.md # Deprecated refactors
Calculate marker age:
# For markers with STARTED date
STARTED_DATE="2025-09-01"
CURRENT_DATE=$(date +%Y-%m-%d)
AGE_DAYS=$((( $(date -d "$CURRENT_DATE" +%s) - $(date -d "$STARTED_DATE" +%s) ) / 86400))
# Check if stale
if [ $AGE_DAYS -gt 30 ]; then
echo "ā ļø STALE: Marker is $AGE_DAYS days old"
fi
Staleness criteria:
Check ADR completion status:
# If ADR moved to implemented/ but markers remain
if [ -f docs/adr/implemented/027-*.md ]; then
echo "š“ Should be removed: ADR complete but markers present"
fi
Report structure:
health: GOOD | ATTENTION_NEEDED | CRITICAL
active_refactors:
- adr: ADR-XXX
title: Title from ADR
files: Count of files with markers
markers: Total marker count
age_days: Age since STARTED date
status: IN_PROGRESS | BLOCKED | REVIEW
adr_valid: true | false
stale_markers: []
orphaned_markers: []
should_be_removed: []
summary: Human-readable summary
Health classification:
docs/adr/implemented/User: "What's my progress on the feature?"
@statuser workflow:
1. Check todo.md status (TodoRead)
2. Check quality metrics (pytest, pyright)
3. Invoke detect-refactor-markers skill
4. Include refactor health in status report
Report includes:
- Task completion percentage
- Quality gate status
- Refactor health status
- Blockers or issues
User: "Mark feature complete"
@feature-completer workflow:
1. Verify all tasks complete
2. Verify quality gates pass
3. Invoke detect-refactor-markers skill
4. Block completion if markers present
Decision logic:
- If active markers found: ā Block completion
- Reason: "Cannot complete feature with active refactor markers"
- Action: "Complete or remove markers first"
- If no markers: ā
Allow completion
User: "How's the refactor going?" OR "Check refactor status"
Agent workflow:
1. Invoke detect-refactor-markers skill
2. Generate comprehensive health report
3. Recommend actions for each issue
Report sections:
- Active refactors summary
- Stale markers (prioritized by age)
- Orphaned markers (needs immediate cleanup)
- Completion suggestions
Agents that should auto-invoke this skill:
Trigger conditions:
The Output Format section below shows comprehensive report examples including:
See references/health-categories-guide.md for detailed health classification logic.
See references/remediation-guide.md for step-by-step fix instructions for each issue type.
# Grep returns no results
grep -rn "^# REFACTOR:" src/ --include="*.py"
# (no output)
Report:
ā
No active refactors (healthy state)
All code is clean, no ongoing migrations.
# Old marker format (missing STARTED field)
# REFACTOR: ADR-015 - Database Migration
# STATUS: IN_PROGRESS
# (no STARTED date)
Handling:
- Can't calculate age
- Report as "Unknown age (missing STARTED date)"
- Recommend adding STARTED date
# Valid: Method markers can exist without file marker
# REFACTOR(ADR-027): Migrate to ServiceResult
def get_user():
pass
# REFACTOR(ADR-027): Migrate to ServiceResult
def update_user():
pass
Report:
ā
Valid markers (method-only is allowed)
File: src/services/user_service.py
Markers: 2 method-level (no file-level)
# Valid: Multiple refactors can overlap
# REFACTOR: ADR-027 - ServiceResult Migration
# STATUS: IN_PROGRESS
# STARTED: 2025-10-10
# REFACTOR(ADR-042): Payment Service Refactor
def process_payment():
pass
Report:
ā
Multiple active refactors in file
File: src/services/payment_service.py
- ADR-027: ServiceResult Migration (file-level)
- ADR-042: Payment Refactor (1 method marker)
# Marker references old path
# PERMANENT_RECORD: docs/adr/in_progress/027-service-result-migration.md
# But ADR actually at:
docs/adr/implemented/027-service-result-migration.md
Detection:
š“ Should be removed: ADR moved to implemented/
Action: Remove markers (refactor complete)
With manage-refactor-markers skill:
With validate-refactor-adr skill:
With @statuser agent:
With @architecture-guardian agent:
With @feature-completer agent:
ā DON'T: Ignore orphaned markers
ā DON'T: Let markers go stale without action
ā DON'T: Remove markers that still have work to do
ā DON'T: Forget to check all file types
ā DON'T: Skip ADR validation
find or test -fā DO: Run health checks regularly
ā DO: Clean up orphaned markers immediately
ā DO: Review stale markers monthly
ā DO: Validate ADRs exist before trusting markers
find docs/adr -name "*XXX-*.md"ā DO: Remove markers when ADR complete
docs/adr/implemented/ directoryIssue: Grep finds no markers but you know they exist
# Possible causes:
# 1. Wrong directory (not in project root)
pwd # Check current directory
cd /path/to/project/root
# 2. Wrong pattern (marker format different)
# Try broader search:
grep -rn "REFACTOR" src/
# 3. Markers in different file types
grep -rn "REFACTOR" src/ --include="*.py" --include="*.ts" --include="*.js" --include="*.tsx"
Issue: ADR validation always reports "missing"
# Check ADR directory structure
ls -R docs/adr/
# Expected structure:
# docs/adr/in_progress/
# docs/adr/implemented/
# docs/adr/deprecated/
# If different structure, adjust validation paths
Issue: Age calculation fails
# Check date format in marker
# Expected: YYYY-MM-DD (2025-10-16)
# If different format, parsing will fail
# Verify date command works
date +%Y-%m-%d
# For macOS vs Linux compatibility:
# macOS: date -j -f "%Y-%m-%d" "2025-10-16" +%s
# Linux: date -d "2025-10-16" +%s
Issue: Multiple marker formats in codebase
# Handle variation:
# Format 1: # REFACTOR: ADR-027 - Title
# Format 2: # REFACTOR(ADR-027): Description
# Format 3: # REFACTOR [ADR-027] Title
# Use flexible regex:
grep -rn "REFACTOR.*ADR-[0-9]" src/
# Extract ADR number with sed:
sed -n 's/.*ADR-\([0-9]\+\).*/\1/p'
Healthy Report:
health: GOOD
active_refactors:
- adr: ADR-027
title: ServiceResult Migration
files: 2
markers: 10
age_days: 6
status: IN_PROGRESS
adr_valid: true
adr_path: docs/adr/in_progress/027-service-result-migration.md
stale_markers: []
orphaned_markers: []
should_be_removed: []
summary: All refactors healthy. 1 active refactor (ADR-027) with 10 markers across 2 files.
Unhealthy Report:
health: CRITICAL
active_refactors:
- adr: ADR-027
title: ServiceResult Migration
files: 2
markers: 10
age_days: 6
status: IN_PROGRESS
adr_valid: true
stale_markers:
- adr: ADR-015
title: Database Migration
file: src/infrastructure/database.py
age_days: 45
started: 2025-09-01
status: IN_PROGRESS
issue: Stale (>30 days without completion)
action: Review progress, update ADR status, or complete work
orphaned_markers:
- adr: ADR-042
file: src/services/payment_service.py
markers: 4
issue: ADR file not found in any docs/adr directory
possible_causes:
- ADR deleted without removing markers
- ADR moved to different directory
- Incorrect ADR number in markers
action: |
1. Search for ADR: find docs/adr -name "*payment*"
2. If found: Update marker ADR numbers
3. If not found: Remove markers using manage-refactor-markers
should_be_removed:
- adr: ADR-028
title: Cache Layer Implementation
files: 4
markers: 12
adr_status: COMPLETE
adr_path: docs/adr/implemented/028-cache-layer.md
issue: ADR complete and moved to implemented/ but markers remain
action: Remove all markers using manage-refactor-markers remove
summary: |
3 critical issues requiring attention:
- 1 stale marker (ADR-015, 45 days old)
- 1 orphaned marker set (ADR-042, 4 markers)
- 1 should-be-removed set (ADR-028, 12 markers)
Recommended priority:
1. Remove orphaned ADR-042 markers (critical)
2. Remove completed ADR-028 markers (cleanup)
3. Review stale ADR-015 refactor (assess continuation)
No external dependencies required. This skill uses only built-in tools:
grep: Find markers in source filesfind: Locate ADR filestest -f: Validate file existencedate: Calculate marker ageProject context required:
.claude/refactor-marker-guide.md: Marker format referencedocs/adr/: ADR directory structuresrc/ directorySee also: