#What it does
The /refactor skill performs deep structural refactoring -- extracting modules, renaming across the codebase, moving responsibilities between layers, and restructuring file organization. Unlike /simplify which does a light cleanup pass, /refactor handles architectural changes that touch many files and require dependency-aware transformations.
#How to use
bash
/refactor Extract the auth logic from the API routes into a shared middlewarebash
/refactor Rename "User" to "Account" across the entire codebasebash
/refactor Split the monolithic utils.ts into domain-specific utility modules#Workflow
- Map -- Build a dependency graph of the target code. Identify every import, export, type reference, and test that touches the area being refactored
- Strategize -- Choose the refactoring pattern: Extract Module, Move Function, Rename Symbol, Inline Abstraction, Replace Inheritance with Composition, or Strangler Fig
- Transform -- Apply the refactoring in small, atomic steps. Each step preserves existing behavior -- the tests should pass after every individual change
- Update References -- Find and update every import path, type reference, config entry, and documentation reference affected by the change
- Verify -- Run the full test suite. Check that no dead imports, broken references, or orphaned files remain
- Report -- Summarize what changed: files created, modified, deleted, and renamed. Flag any manual follow-ups needed
#Supported patterns
- Extract -- Pull a function, class, or module into its own file with proper exports
- Rename -- Rename a symbol across every file, test, config, and documentation reference
- Move -- Relocate code between directories or layers while updating all imports
- Inline -- Collapse an unnecessary abstraction back into its callers
- Split -- Break a large file into focused, single-responsibility modules
- Consolidate -- Merge scattered related code into a cohesive module
#Example
bash
> /refactor Extract database queries from route handlers into repository classes
## Dependency Map
- 12 route handlers contain inline SQL queries
- 4 shared query patterns identified (CRUD for users, orders, products, sessions)
- 23 test files reference route handlers directly
## Plan
1. Create src/repositories/ directory
2. Extract UserRepository, OrderRepository, ProductRepository, SessionRepository
3. Define repository interfaces for each
4. Update route handlers to inject repositories
5. Update tests to mock repository interfaces
6. Verify: all 47 tests pass, no inline SQL remains in routes