Use when performing multi-pass refactoring across a codebase zone. Examples: "Deep refactor the chat components", "Refactor this module", "Clean up the data layer", "/deep-refactor". Combines GitNexus analysis, parallel safety zones, and multi-pass iteration for thorough, safe refactoring.
Multi-pass refactoring workflow with GitNexus-driven discovery, zone-scoped safety, and before/after metrics.
Announce at start: "I'm using the deep-refactor skill for multi-pass refactoring."
.claude/parallel-zones.md if it exists)/deep-refactor the chat componentsRefactors only the specified area. Phase 0 identifies the scope, then runs Phases 1-4 for that area only.
/deep-refactorFull codebase sweep. If .claude/parallel-zones.md exists, iterates through
every zone sequentially. Otherwise, works through directories/modules one at a time.
Before touching code, identify the scope of the refactoring.
1. If `.claude/parallel-zones.md` exists — find which zone owns the target files
2. If cross-zone: split into per-zone sub-tasks, execute sequentially
3. Record scope in your plan
Map the full scope before changing anything.
Step 1: Find all symbols in scope
gitnexus_query({query: "<target area description>"})
→ Note execution flows, symbol counts, cluster cohesion
Step 2: For each candidate symbol, check blast radius
gitnexus_impact({target: "symbolName", direction: "upstream"})
→ Record: direct callers (d=1), indirect deps (d=2), risk level
Step 3: Cross-check with grep
Grep for `from.*<module>` and `import.*<symbol>` to catch dynamic refs
GitNexus misses string-based imports, re-exports, and dynamic requires
Step 4: Capture baseline metrics
- File count in scope
- Total LOC (wc -l)
- Symbol count from GitNexus
- Number of cross-module dependencies
Output: A ranked list of refactoring targets with risk levels and consumer counts.
Write the refactoring plan as 3 sequential passes. Each pass has a specific focus — do NOT mix concerns across passes.
Change where code lives without changing what it does.
- Delete dead code (0 consumers confirmed by GitNexus + grep)
- Extract shared logic into dedicated modules
- Colocate code with its single consumer
- Move files to correct directories
- Update all import paths
Verification after Pass 1:
# Run your project's type checker
# Run gitnexus_detect_changes({scope: "all"})
Simplify how modules talk to each other.
- Reduce exported surface area (unexport internals)
- Simplify function signatures (fewer params, better types)
- Replace loose types with stricter ones
- Consolidate duplicate type definitions
- Rename for clarity (use gitnexus_rename, never find-and-replace)
Verification after Pass 2:
# Same type-check + lint as Pass 1
# Plus: run tests for all affected execution flows
# gitnexus_detect_changes({scope: "all"})
Improve code inside functions without changing their signatures.
- Simplify conditional logic
- Remove unnecessary abstractions
- Replace verbose patterns with idiomatic alternatives
- Reduce nesting depth
- Improve error messages
Verification after Pass 3:
# Full test suite for the scope
# Final detect_changes to confirm scope
# gitnexus_detect_changes({scope: "all"})
Every pass is executed twice. The first iteration does the heavy lifting; the second iteration reviews what the first produced and catches anything that was missed, could be cleaner, or introduced new opportunities.
For each pass (1, 2, 3):
Iteration A — Primary changes
1. Execute the pass
2. Verify (type-check + lint + tests)
3. Commit: `refactor: pass N.a — <description>`
Iteration B — Review & polish
1. Re-read every file touched in iteration A
2. Look for: missed opportunities, inconsistencies introduced by A,
further simplifications now possible, naming that could be better
3. Apply fixes
4. Verify (type-check + lint + tests)
5. Commit: `refactor: pass N.b — <description>`
Proceed directly to next pass — no user approval gate between passes.
After ALL passes complete → report full metrics to user for review.
No feedback gates between passes. The skill runs all 3 passes (6 iterations) autonomously. The only user checkpoint is at the end (Phase 4 metrics report).
gitnexus_detect_changes() to confirm scope hasn't drifted.After all passes complete, produce a before/after comparison:
| Metric | Before | After | Delta |
|---------------------------|--------|-------|-------|
| Files in scope | | | |
| Lines of code | | | |
| Exported symbols | | | |
| Cross-module dependencies | | | |
| Dead code files | | | 0 |
| GitNexus risk assessment | | | |
| Check | When | Tool |
|---|---|---|
| Scope identification | Before starting | Check for .claude/parallel-zones.md |
| Blast radius per symbol | Before each edit | gitnexus_impact |
| Import cross-check | After GitNexus audit | Grep for dynamic refs |
| Scope verification | After each pass | gitnexus_detect_changes |
| Type check | After each pass | Your project's type checker |
| Tests | After each pass | Your project's test suite |
| Final scope | Before merge | gitnexus_detect_changes({scope: "compare", base_ref: "main"}) |
.claude/parallel-zones.md to run multiple deep-refactors in separate worktrees on independent zones