From context-engine
Restructure code without adding features. Uses Agent Team for multi-module refactors or single subagent for focused changes.
npx claudepluginhub littlelingo/context-engine --plugin context-engine# /refactor - Refactor Existing Code Restructure code without adding features. Uses Agent Team for multi-module refactors or single subagent for focused changes. ## Process 1. **Understand the goal**: Extract from `$ARGUMENTS`. Common types: extract module, consolidate duplicates, rename across codebase, upgrade pattern, split large file. 2. **Delegate to `researcher` subagent** to map scope: - Files affected, dependencies, existing test coverage. 3. **Create refactor plan** (lighter than full PRP) with: - Goal, scope (N files), risk level (LOW/MEDIUM/HIGH) - Tracks table: tra...
/refactorOrchestrates refactoring for specified scope: assesses architecture and issues, plans incremental transformations with risk mitigation, provides code change guides with examples, validation tests, and monitoring plan.
/refactorSystematically refactors target code area: identifies smells like long functions and duplicates, verifies/adds tests, plans atomic steps, executes with verification, preserves behavior.
/refactorPerforms safe step-by-step code refactoring. Quantitatively scores SOLID principles (0-100 per principle), visualizes technical debt via formula, and prioritizes improvements.
/refactorPerforms safe incremental refactoring on code, scores SOLID principles compliance (0-100 total), detects smells via grep/bash, visualizes technical debt, and prioritizes fixes with examples.
/refactorSafely refactors code progressively using techniques like Extract Method, quantitatively scores SOLID principle adherence (0-100), visualizes technical debt, and prioritizes improvements.
/refactorRefactors code step-by-step using techniques like Extract Method and polymorphism, scores SOLID principles quantitatively, visualizes technical debt, and prioritizes improvements.
Share bugs, ideas, or general feedback.
Restructure code without adding features. Uses Agent Team for multi-module refactors or single subagent for focused changes.
Understand the goal: Extract from $ARGUMENTS. Common types: extract module, consolidate duplicates, rename across codebase, upgrade pattern, split large file.
Delegate to researcher subagent to map scope:
Create refactor plan (lighter than full PRP) with:
[ ] [step] - Track: [track] - Validate: [command]Safety checks (MUST pass before any changes):
a. Clean working tree: If dirty, stop.
b. Tests pass: If failing, stop - don't refactor broken code.
c. Correct branch: If on main/master, create refactor/[scope] branch.
Get approval: Present plan to user. Iterate if needed.
Save plan: Write to .context/features/[NNN]-refactor-[name]/PRP.md. Update FEATURES.md.
Checkpoint (trigger: phase-boundary): Create checkpoint CP-NNN: pre-refactor [scope]. Snapshot .context/ state, tag current git state. This is the rollback point if the refactor breaks things.
Execute:
Multi-track refactor (3+ independent tracks): Create Agent Team.
Checkpoint: Create checkpoint CP-NNN: pre-refactor-team [scope] ONLY if steps were completed since the last checkpoint.
Create an agent team to execute the refactor plan at [PRP path].
Spawn teammates per track:
implement-then-test for refactorsSet up shared task list with dependencies from the plan.
Single-track refactor: Delegate to implementer subagent, one step at a time.
After each step/track: Full test suite must pass. If anything breaks with a non-obvious cause, run /debug [failing test or error] before continuing. For simple regressions, fix inline.
Capture learnings (MANDATORY — use formats from .claude/instructions/CAPTURE-FORMAT.md):
.context/decisions/ADR-NNN-[title].md if the refactor introduced a new architectural pattern.context/patterns/CODE_PATTERNS.md.context/patterns/ANTI_PATTERNS.md (mark as resolved or add prevention guidance).context/knowledge/LEARNINGS.md.context/knowledge/libraries/[name].mdRefactor complete. All tests passing.
Next step options:
1. /validate [PRP path] (recommended — full review + tests + metrics)
2. commit (skip review — learnings already captured, writes metrics first)
3. pause (checkpoint and stop — resume later)
Choose (1/2/3):
/validate with the PRP path as the argument (use the Skill tool with skill="validate"). Remind about /clear first if context > 50%..context/metrics/HEALTH.md Feature Velocity table with available data (mark review columns as SKIPPED). Update FEATURES.md status to COMPLETE (unvalidated).CP-NNN: paused-refactor [scope], leave status as IN_PROGRESS, and stop./checkpoint rollback CP-NNN to restore pre-refactor state. The pre-refactor checkpoint exists for exactly this reason.$ARGUMENTS