Refactor Operations
Comprehensive refactoring skill covering safe transformation patterns, code smell detection, dead code elimination, and test-driven refactoring methodology.
Refactoring Decision Tree
What kind of refactoring do you need?
│
├─ Extracting code into a new unit
│ ├─ A block of statements with a clear purpose
│ │ └─ Extract Function/Method
│ │ Identify inputs (params) and outputs (return value)
│ │
│ ├─ A UI element with its own state or props
│ │ └─ Extract Component (React, Vue, Svelte)
│ │ Move JSX/template + related state into new file
│ │
│ ├─ Reusable stateful logic (not UI)
│ │ └─ Extract Hook / Composable
│ │ React: useCustomHook, Vue: useComposable
│ │
│ ├─ A file has grown beyond 300-500 lines
│ │ └─ Extract Module
│ │ Split by responsibility, create barrel exports
│ │ Watch for circular dependencies
│ │
│ ├─ A class does too many things (SRP violation)
│ │ └─ Extract Class / Service
│ │ One responsibility per class, use dependency injection
│ │
│ └─ Magic numbers, hardcoded strings, env-specific values
│ └─ Extract Configuration
│ Constants file, env vars, feature flags
│
├─ Renaming for clarity
│ ├─ Variable, function, or method
│ │ └─ Rename Symbol
│ │ Update all references (IDE rename or ast-grep)
│ │
│ ├─ File or directory
│ │ └─ Rename File + Update Imports
│ │ git mv to preserve history, update all import paths
│ │
│ └─ Module or package
│ └─ Rename Module + Update All Consumers
│ Search for all import/require references
│ Consider re-exporting from old name temporarily
│
├─ Moving code to a better location
│ ├─ Function/class to a different file
│ │ └─ Move + Re-export from Original
│ │ Leave re-export for one release cycle
│ │
│ ├─ Files to a different directory
│ │ └─ Restructure + Update All Paths
│ │ Use IDE refactoring or find-and-replace
│ │
│ └─ Reorganize entire directory structure
│ └─ Incremental Migration
│ Move one module at a time, keep tests green
│
├─ Simplifying existing code
│ ├─ Function is too simple to justify its own name
│ │ └─ Inline Function
│ │ Replace call sites with the body
│ │
│ ├─ Variable used only once, right after assignment
│ │ └─ Inline Variable
│ │ Replace variable with expression
│ │
│ ├─ Deep nesting (> 3 levels)
│ │ └─ Guard Clauses + Early Returns
│ │ Invert conditions, return early
│ │
│ └─ Complex conditionals
│ └─ Decompose Conditional
│ Extract each branch into named function
│
└─ Removing dead code
├─ Unused imports
│ └─ Lint + Auto-fix (eslint, ruff, goimports)
│
├─ Unreachable code branches
│ └─ Static analysis + manual review
│
├─ Orphaned files (no imports point to them)
│ └─ Dependency graph analysis (knip, ts-prune, vulture)
│
└─ Unused exports
└─ ts-prune, knip, or manual grep for import references
Safety Checklist
Run through this checklist before starting any refactoring:
Pre-Refactoring
[ ] All tests pass (full suite, not just related tests)
[ ] Working tree is clean (git status shows no uncommitted changes)
[ ] On a dedicated branch (not main/master)
[ ] CI is green on the base branch
[ ] You understand what the code does (read it, don't assume)
[ ] Characterization tests exist for untested code you will change
During Refactoring
[ ] Each commit compiles and all tests pass
[ ] Commits are small and focused (one refactoring per commit)
[ ] No behavior changes mixed with structural changes
[ ] Running tests after every change (use --watch mode)
Post-Refactoring
[ ] Full test suite passes
[ ] No new warnings from linter or type checker
[ ] Code review requested (refactoring PRs need fresh eyes)
[ ] Performance benchmarks unchanged (if applicable)
[ ] Documentation updated (if public API changed)
Extract Patterns Quick Reference
| Pattern |
When to Use |
Key Considerations |
| Extract Function |
Block of code has a clear single purpose, used or could be reused |
Name should describe WHAT, not HOW. Pure functions preferred. |
| Extract Component |
UI element has own state, props, or rendering logic |
Props interface should be minimal. Avoid prop drilling. |
| Extract Hook/Composable |
Stateful logic shared across components |
Must start with use. Return stable references. |
| Extract Module |
File exceeds 300-500 lines, has multiple responsibilities |
One module = one responsibility. Barrel exports for public API. |
| Extract Class/Service |
Object handles too many concerns |
Dependency injection over hard-coded dependencies. |
| Extract Configuration |
Magic numbers, environment-specific values, feature flags |
Type-safe config objects over loose constants. |
Rename Patterns Quick Reference
| What to Rename |
Method |
Pitfalls |
| Variable/function |
IDE rename (F2) or ast-grep |
String references (logs, error messages) not caught by IDE |
| Class/type |
IDE rename + update file name to match |
Serialized data may reference old name (JSON, DB) |
| File |
git mv old new + update all imports |
Import paths in test files, storybook, config files often missed |
| Directory |
git mv + bulk import update |
Barrel re-exports, path aliases in tsconfig/webpack |
| Package/module |
Rename + re-export from old name |
External consumers need deprecation period |
Move/Restructure Quick Reference
| Scenario |
Strategy |
Safety Net |
| Single file move |
git mv + update imports + re-export from old path |
rg 'old/path' to find all references |
| Multiple related files |
Move together, update barrel exports |
Run type checker after each move |
| Directory restructure |
Incremental: one directory per PR |
Keep old paths working via re-exports |
| Monorepo package split |
Extract to new package, update all consumers |
Version the new package, pin consumers |
Dead Code Detection Workflow
Step 1: Automated Detection
│
├─ TypeScript/JavaScript
│ ├─ knip (comprehensive: files, deps, exports)
│ │ └─ npx knip --reporter compact
│ ├─ ts-prune (unused exports)
│ │ └─ npx ts-prune
│ └─ eslint (unused vars/imports)
│ └─ eslint --rule 'no-unused-vars: error'
│
├─ Python
│ ├─ vulture (dead code finder)
│ │ └─ vulture src/ --min-confidence 80
│ ├─ ruff (unused imports)
│ │ └─ ruff check --select F401
│ └─ coverage.py (unreachable branches)
│ └─ coverage run && coverage report --show-missing
│
├─ Go
│ └─ staticcheck / golangci-lint
│ └─ golangci-lint run --enable unused,deadcode
│
├─ Rust
│ └─ Compiler warnings (dead_code, unused_imports)
│ └─ cargo build 2>&1 | rg 'warning.*unused'
│
Step 2: Manual Verification
│ ├─ Check if "unused" code is used via reflection/dynamic import
│ ├─ Check if exports are part of public API consumed externally
│ ├─ Check if code is used in scripts, tests, or tooling not in the scan
│ └─ Check if code is behind a feature flag or A/B test
│
Step 3: Remove with Confidence
│ ├─ Remove in small batches, not all at once
│ ├─ One commit per logical group of dead code
│ └─ Keep git history -- you can always recover
Code Smell Detection
| Smell |
Heuristic |
Refactoring |
| Long function |
> 20 lines or > 5 levels of indentation |
Extract Function, Decompose Conditional |
| God object |
Class with > 10 methods or > 500 lines |
Extract Class, Split by responsibility |
| Feature envy |
Method uses another object's data more than its own |
Move Method to the class whose data it uses |
| Duplicate code |
Same logic in 2+ places (> 5 similar lines) |
Extract Function, Extract Module |
| Deep nesting |
> 3 levels of if/for/while nesting |
Guard Clauses, Early Returns, Extract Function |
| Primitive obsession |
Using strings/numbers where a type would be safer |
Value Objects, Branded Types, Enums |
| Shotgun surgery |
One change requires editing 5+ files |
Move related code together, Extract Module |
| Dead code |
Unreachable branches, unused exports/imports |
Delete it (git has history) |
| Data clumps |
Same group of parameters passed together repeatedly |
Extract Parameter Object or Config Object |
| Long parameter list |
Function takes > 4 parameters |
Extract Parameter Object, Builder Pattern |
Test-Driven Refactoring Methodology
Refactoring Untested Code
│
├─ Step 1: Write Characterization Tests
│ │ Capture CURRENT behavior, even if it seems wrong
│ │ These tests document what the code actually does
│ └─ Goal: safety net, not correctness proof
│
├─ Step 2: Verify Coverage
│ │ Run coverage tool, ensure all paths you will touch are covered
│ └─ Add more tests if coverage is insufficient
│
├─ Step 3: Refactor in Small Steps
│ │ One transformation at a time
│ │ Run tests after EVERY change
│ └─ If tests fail, undo and try smaller step
│
├─ Step 4: Improve Tests
│ │ Now that code is cleaner, write better tests
│ │ Replace characterization tests with intention-revealing tests
│ └─ Add edge cases discovered during refactoring
│
└─ Step 5: Commit and Review
│ Separate commits: tests first, then refactoring
└─ Reviewers can verify tests pass on old code too
Tool Reference
| Tool |
Language |
Use Case |
Command |
| ast-grep |
Multi |
Structural search and replace |
sg -p 'console.log($$$)' -r '' -l js |
| jscodeshift |
JS/TS |
Large-scale AST-based codemods |
jscodeshift -t transform.js src/ |
| eslint --fix |
JS/TS |
Auto-fix lint violations |
eslint --fix 'src/**/*.ts' |
| ruff |
Python |
Fast linting and auto-fix |
ruff check --fix src/ |
| goimports |
Go |
Organize imports |
goimports -w . |
| clippy |
Rust |
Lint and suggest improvements |
cargo clippy --fix |
| knip |
JS/TS |
Find unused files, deps, exports |
npx knip |
| ts-prune |
TS |
Find unused exports |
npx ts-prune |
| vulture |
Python |
Find dead code |
vulture src/ --min-confidence 80 |
| rope |
Python |
Refactoring library |
Python API for rename, extract, move |
| IDE rename |
All |
Rename with reference updates |
F2 in VS Code, Shift+F6 in JetBrains |
| sd |
All |
Find and replace in files |
sd 'oldName' 'newName' src/**/*.ts |
Common Gotchas
| Gotcha |
Why It Happens |
Prevention |
| Refactoring and behavior change in same commit |
Tempting to "fix while you're in there" |
Separate commits: refactor first, then change behavior |
| Breaking public API during internal refactor |
Renamed/moved exports consumed by external code |
Re-export from old path, deprecation warnings |
| Circular dependencies after extracting modules |
New module imports from original, original imports from new |
Dependency graph check after each extraction |
| Tests pass but runtime breaks |
Tests mock the refactored code, hiding the break |
Integration tests alongside unit tests |
| git history lost after file move |
Used cp + rm instead of git mv |
Always git mv, verify with git log --follow |
| Renaming misses string references |
IDE rename only catches code references, not configs/docs |
rg 'oldName' across entire repo after rename |
| Over-abstracting (premature DRY) |
Extracting after seeing only 2 occurrences |
Rule of three: wait for 3 duplicates before extracting |
| Extracting coupled code |
New function has 8 parameters because code is entangled |
Refactor coupling first, then extract |
| Dead code removal breaks reflection/plugins |
Dynamic imports, dependency injection, decorators |
Grep for string references, check plugin registries |
| Performance regression after extraction |
Extra function calls, lost inlining, cache misses |
Benchmark before and after for hot paths |
| Merge conflicts from large refactoring PR |
Long-lived branch diverges from main |
Small PRs, merge main frequently, or use stacked PRs |
| Type errors after moving files |
Path aliases, tsconfig paths, barrel exports not updated |
Run type checker after every file move |
Reference Files
| File |
Contents |
Lines |
references/extract-patterns.md |
Extract function, component, hook, module, class, configuration -- with before/after examples in multiple languages |
~700 |
references/code-smells.md |
Code smell catalog with detection heuristics, tools by language, complexity metrics |
~650 |
references/safe-methodology.md |
Test-driven refactoring, strangler fig, parallel change, branch by abstraction, feature flags, rollback |
~550 |
See Also
| Skill |
When to Combine |
testing-ops |
Write characterization tests before refactoring, test strategy for refactored code |
structural-search |
Use ast-grep for structural find-and-replace across codebase |
debug-ops |
When refactoring exposes hidden bugs or introduces regressions |
code-stats |
Measure complexity before and after refactoring to quantify improvement |
migrate-ops |
Large-scale migrations that require systematic refactoring |
git-ops |
Branch strategy for refactoring PRs, stacked PRs, bisect to find regressions |
1---2name: refactor-ops3description: "Safe refactoring patterns - extract, rename, restructure with test-driven methodology and dead code detection. Use for: refactor, refactoring, extract function, extract component, rename, move file, restructure, dead code, unused imports, code smell, duplicate code, long function, god object, feature envy, DRY, technical debt, cleanup, simplify, decompose, inline, pull up, push down, strangler fig, parallel change."4license: MIT5allowed-tools: "Read Edit Write Bash Glob Grep Agent"6metadata:7 author: claude-mods8 related-skills: testing-ops, structural-search, debug-ops, code-stats, migrate-ops9---1011# Refactor Operations1213Comprehensive refactoring skill covering safe transformation patterns, code smell detection, dead code elimination, and test-driven refactoring methodology.1415## Refactoring Decision Tree1617```18What kind of refactoring do you need?19│20├─ Extracting code into a new unit21│ ├─ A block of statements with a clear purpose22│ │ └─ Extract Function/Method23│ │ Identify inputs (params) and outputs (return value)24│ │25│ ├─ A UI element with its own state or props26│ │ └─ Extract Component (React, Vue, Svelte)27│ │ Move JSX/template + related state into new file28│ │29│ ├─ Reusable stateful logic (not UI)30│ │ └─ Extract Hook / Composable31│ │ React: useCustomHook, Vue: useComposable32│ │33│ ├─ A file has grown beyond 300-500 lines34│ │ └─ Extract Module35│ │ Split by responsibility, create barrel exports36│ │ Watch for circular dependencies37│ │38│ ├─ A class does too many things (SRP violation)39│ │ └─ Extract Class / Service40│ │ One responsibility per class, use dependency injection41│ │42│ └─ Magic numbers, hardcoded strings, env-specific values43│ └─ Extract Configuration44│ Constants file, env vars, feature flags45│46├─ Renaming for clarity47│ ├─ Variable, function, or method48│ │ └─ Rename Symbol49│ │ Update all references (IDE rename or ast-grep)50│ │51│ ├─ File or directory52│ │ └─ Rename File + Update Imports53│ │ git mv to preserve history, update all import paths54│ │55│ └─ Module or package56│ └─ Rename Module + Update All Consumers57│ Search for all import/require references58│ Consider re-exporting from old name temporarily59│60├─ Moving code to a better location61│ ├─ Function/class to a different file62│ │ └─ Move + Re-export from Original63│ │ Leave re-export for one release cycle64│ │65│ ├─ Files to a different directory66│ │ └─ Restructure + Update All Paths67│ │ Use IDE refactoring or find-and-replace68│ │69│ └─ Reorganize entire directory structure70│ └─ Incremental Migration71│ Move one module at a time, keep tests green72│73├─ Simplifying existing code74│ ├─ Function is too simple to justify its own name75│ │ └─ Inline Function76│ │ Replace call sites with the body77│ │78│ ├─ Variable used only once, right after assignment79│ │ └─ Inline Variable80│ │ Replace variable with expression81│ │82│ ├─ Deep nesting (> 3 levels)83│ │ └─ Guard Clauses + Early Returns84│ │ Invert conditions, return early85│ │86│ └─ Complex conditionals87│ └─ Decompose Conditional88│ Extract each branch into named function89│90└─ Removing dead code91 ├─ Unused imports92 │ └─ Lint + Auto-fix (eslint, ruff, goimports)93 │94 ├─ Unreachable code branches95 │ └─ Static analysis + manual review96 │97 ├─ Orphaned files (no imports point to them)98 │ └─ Dependency graph analysis (knip, ts-prune, vulture)99 │100 └─ Unused exports101 └─ ts-prune, knip, or manual grep for import references102```103104## Safety Checklist105106Run through this checklist before starting any refactoring:107108```109Pre-Refactoring110[ ] All tests pass (full suite, not just related tests)111[ ] Working tree is clean (git status shows no uncommitted changes)112[ ] On a dedicated branch (not main/master)113[ ] CI is green on the base branch114[ ] You understand what the code does (read it, don't assume)115[ ] Characterization tests exist for untested code you will change116117During Refactoring118[ ] Each commit compiles and all tests pass119[ ] Commits are small and focused (one refactoring per commit)120[ ] No behavior changes mixed with structural changes121[ ] Running tests after every change (use --watch mode)122123Post-Refactoring124[ ] Full test suite passes125[ ] No new warnings from linter or type checker126[ ] Code review requested (refactoring PRs need fresh eyes)127[ ] Performance benchmarks unchanged (if applicable)128[ ] Documentation updated (if public API changed)129```130131## Extract Patterns Quick Reference132133| Pattern | When to Use | Key Considerations |134|---------|-------------|-------------------|135| **Extract Function** | Block of code has a clear single purpose, used or could be reused | Name should describe WHAT, not HOW. Pure functions preferred. |136| **Extract Component** | UI element has own state, props, or rendering logic | Props interface should be minimal. Avoid prop drilling. |137| **Extract Hook/Composable** | Stateful logic shared across components | Must start with `use`. Return stable references. |138| **Extract Module** | File exceeds 300-500 lines, has multiple responsibilities | One module = one responsibility. Barrel exports for public API. |139| **Extract Class/Service** | Object handles too many concerns | Dependency injection over hard-coded dependencies. |140| **Extract Configuration** | Magic numbers, environment-specific values, feature flags | Type-safe config objects over loose constants. |141142## Rename Patterns Quick Reference143144| What to Rename | Method | Pitfalls |145|----------------|--------|----------|146| **Variable/function** | IDE rename (F2) or `ast-grep` | String references (logs, error messages) not caught by IDE |147| **Class/type** | IDE rename + update file name to match | Serialized data may reference old name (JSON, DB) |148| **File** | `git mv old new` + update all imports | Import paths in test files, storybook, config files often missed |149| **Directory** | `git mv` + bulk import update | Barrel re-exports, path aliases in tsconfig/webpack |150| **Package/module** | Rename + re-export from old name | External consumers need deprecation period |151152## Move/Restructure Quick Reference153154| Scenario | Strategy | Safety Net |155|----------|----------|------------|156| **Single file move** | `git mv` + update imports + re-export from old path | `rg 'old/path'` to find all references |157| **Multiple related files** | Move together, update barrel exports | Run type checker after each move |158| **Directory restructure** | Incremental: one directory per PR | Keep old paths working via re-exports |159| **Monorepo package split** | Extract to new package, update all consumers | Version the new package, pin consumers |160161## Dead Code Detection Workflow162163```164Step 1: Automated Detection165│166├─ TypeScript/JavaScript167│ ├─ knip (comprehensive: files, deps, exports)168│ │ └─ npx knip --reporter compact169│ ├─ ts-prune (unused exports)170│ │ └─ npx ts-prune171│ └─ eslint (unused vars/imports)172│ └─ eslint --rule 'no-unused-vars: error'173│174├─ Python175│ ├─ vulture (dead code finder)176│ │ └─ vulture src/ --min-confidence 80177│ ├─ ruff (unused imports)178│ │ └─ ruff check --select F401179│ └─ coverage.py (unreachable branches)180│ └─ coverage run && coverage report --show-missing181│182├─ Go183│ └─ staticcheck / golangci-lint184│ └─ golangci-lint run --enable unused,deadcode185│186├─ Rust187│ └─ Compiler warnings (dead_code, unused_imports)188│ └─ cargo build 2>&1 | rg 'warning.*unused'189│190Step 2: Manual Verification191│ ├─ Check if "unused" code is used via reflection/dynamic import192│ ├─ Check if exports are part of public API consumed externally193│ ├─ Check if code is used in scripts, tests, or tooling not in the scan194│ └─ Check if code is behind a feature flag or A/B test195│196Step 3: Remove with Confidence197│ ├─ Remove in small batches, not all at once198│ ├─ One commit per logical group of dead code199│ └─ Keep git history -- you can always recover200```201202## Code Smell Detection203204| Smell | Heuristic | Refactoring |205|-------|-----------|-------------|206| **Long function** | > 20 lines or > 5 levels of indentation | Extract Function, Decompose Conditional |207| **God object** | Class with > 10 methods or > 500 lines | Extract Class, Split by responsibility |208| **Feature envy** | Method uses another object's data more than its own | Move Method to the class whose data it uses |209| **Duplicate code** | Same logic in 2+ places (> 5 similar lines) | Extract Function, Extract Module |210| **Deep nesting** | > 3 levels of if/for/while nesting | Guard Clauses, Early Returns, Extract Function |211| **Primitive obsession** | Using strings/numbers where a type would be safer | Value Objects, Branded Types, Enums |212| **Shotgun surgery** | One change requires editing 5+ files | Move related code together, Extract Module |213| **Dead code** | Unreachable branches, unused exports/imports | Delete it (git has history) |214| **Data clumps** | Same group of parameters passed together repeatedly | Extract Parameter Object or Config Object |215| **Long parameter list** | Function takes > 4 parameters | Extract Parameter Object, Builder Pattern |216217## Test-Driven Refactoring Methodology218219```220Refactoring Untested Code221│222├─ Step 1: Write Characterization Tests223│ │ Capture CURRENT behavior, even if it seems wrong224│ │ These tests document what the code actually does225│ └─ Goal: safety net, not correctness proof226│227├─ Step 2: Verify Coverage228│ │ Run coverage tool, ensure all paths you will touch are covered229│ └─ Add more tests if coverage is insufficient230│231├─ Step 3: Refactor in Small Steps232│ │ One transformation at a time233│ │ Run tests after EVERY change234│ └─ If tests fail, undo and try smaller step235│236├─ Step 4: Improve Tests237│ │ Now that code is cleaner, write better tests238│ │ Replace characterization tests with intention-revealing tests239│ └─ Add edge cases discovered during refactoring240│241└─ Step 5: Commit and Review242 │ Separate commits: tests first, then refactoring243 └─ Reviewers can verify tests pass on old code too244```245246## Tool Reference247248| Tool | Language | Use Case | Command |249|------|----------|----------|---------|250| **ast-grep** | Multi | Structural search and replace | `sg -p 'console.log($$$)' -r '' -l js` |251| **jscodeshift** | JS/TS | Large-scale AST-based codemods | `jscodeshift -t transform.js src/` |252| **eslint --fix** | JS/TS | Auto-fix lint violations | `eslint --fix 'src/**/*.ts'` |253| **ruff** | Python | Fast linting and auto-fix | `ruff check --fix src/` |254| **goimports** | Go | Organize imports | `goimports -w .` |255| **clippy** | Rust | Lint and suggest improvements | `cargo clippy --fix` |256| **knip** | JS/TS | Find unused files, deps, exports | `npx knip` |257| **ts-prune** | TS | Find unused exports | `npx ts-prune` |258| **vulture** | Python | Find dead code | `vulture src/ --min-confidence 80` |259| **rope** | Python | Refactoring library | Python API for rename, extract, move |260| **IDE rename** | All | Rename with reference updates | F2 in VS Code, Shift+F6 in JetBrains |261| **sd** | All | Find and replace in files | `sd 'oldName' 'newName' src/**/*.ts` |262263## Common Gotchas264265| Gotcha | Why It Happens | Prevention |266|--------|---------------|------------|267| Refactoring and behavior change in same commit | Tempting to "fix while you're in there" | Separate commits: refactor first, then change behavior |268| Breaking public API during internal refactor | Renamed/moved exports consumed by external code | Re-export from old path, deprecation warnings |269| Circular dependencies after extracting modules | New module imports from original, original imports from new | Dependency graph check after each extraction |270| Tests pass but runtime breaks | Tests mock the refactored code, hiding the break | Integration tests alongside unit tests |271| git history lost after file move | Used `cp` + `rm` instead of `git mv` | Always `git mv`, verify with `git log --follow` |272| Renaming misses string references | IDE rename only catches code references, not configs/docs | `rg 'oldName'` across entire repo after rename |273| Over-abstracting (premature DRY) | Extracting after seeing only 2 occurrences | Rule of three: wait for 3 duplicates before extracting |274| Extracting coupled code | New function has 8 parameters because code is entangled | Refactor coupling first, then extract |275| Dead code removal breaks reflection/plugins | Dynamic imports, dependency injection, decorators | Grep for string references, check plugin registries |276| Performance regression after extraction | Extra function calls, lost inlining, cache misses | Benchmark before and after for hot paths |277| Merge conflicts from large refactoring PR | Long-lived branch diverges from main | Small PRs, merge main frequently, or use stacked PRs |278| Type errors after moving files | Path aliases, tsconfig paths, barrel exports not updated | Run type checker after every file move |279280## Reference Files281282| File | Contents | Lines |283|------|----------|-------|284| `references/extract-patterns.md` | Extract function, component, hook, module, class, configuration -- with before/after examples in multiple languages | ~700 |285| `references/code-smells.md` | Code smell catalog with detection heuristics, tools by language, complexity metrics | ~650 |286| `references/safe-methodology.md` | Test-driven refactoring, strangler fig, parallel change, branch by abstraction, feature flags, rollback | ~550 |287288## See Also289290| Skill | When to Combine |291|-------|----------------|292| `testing-ops` | Write characterization tests before refactoring, test strategy for refactored code |293| `structural-search` | Use ast-grep for structural find-and-replace across codebase |294| `debug-ops` | When refactoring exposes hidden bugs or introduces regressions |295| `code-stats` | Measure complexity before and after refactoring to quantify improvement |296| `migrate-ops` | Large-scale migrations that require systematic refactoring |297| `git-ops` | Branch strategy for refactoring PRs, stacked PRs, bisect to find regressions |