From godmode
Executes large-scale code refactoring with risk assessment, patterns like extract/inline/move/rename, strangler migrations, impact analysis, and test-driven safety rules for JS/TS/Python codebases.
How this skill is triggered — by the user, by Claude, or both
Slash command
/godmode:refactorThe summary Claude sees in its skill listing — used to decide when to auto-load this skill
- `/godmode:refactor`, "refactor this", "clean up"
/godmode:refactor, "refactor this", "clean up"find . -name "*.ts" -o -name "*.js" -o -name "*.py" \
| xargs wc -l | sort -rn | head -20
grep -rn "<pattern>" --include="*.ts" --include="*.js"
Target: <file or module>
Lines: <N> | Complexity: <cyclomatic> | Coverage: <N%>
Dependents: <N files> | Risk: LOW|MEDIUM|HIGH|CRITICAL
Risk levels:
IF coverage < 60%: write characterization tests first. IF dependents > 30: use strangler pattern migration.
Extract (Function, Class, Interface, Module, Variable, Parameter), Inline (Function, Variable), Move (Function, Field), Rename (Symbol, File), Simplify (Conditional, Loop, Guard Clause), Replace (Inheritance with Composition, Conditional with Polymorphism).
grep -rl "<symbol>" --include="*.ts" --include="*.js"
Map directly affected (modified), indirectly affected (imports changed), and not affected files.
npm test 2>&1 | tail -10
npx jest --testPathPattern="<target>" 2>&1
IF coverage < 60%: STOP, write characterization tests, commit them separately, then proceed.
One transformation per commit. For each step:
"refactor: <pattern> -- <desc>"IF tests fail after transformation: revert first, then diagnose. Never debug forward.
Strangler pattern: create new alongside old, migrate dependents one at a time, each migration = separate commit, remove old code only after zero references.
IF >5 dependents: phase the migration over multiple PRs.
npm test
Compare: test count same or higher, coverage same or higher, no behavior change. Report pattern used, commits, files modified/created/deleted.
Cyclomatic: <= 10/function (eslint, radon, gocyclo)
Cognitive: <= 15/function (SonarQube, eslint sonarjs)
LOC: <= 50/function (wc -l)
Append .godmode/refactor.tsv:
timestamp target pattern tests_before tests_after coverage_before coverage_after status
KEEP if: tests pass AND complexity reduced
AND coverage maintained or increased.
DISCARD if: tests fail OR complexity unchanged
OR coverage dropped.
STOP when FIRST of:
- All targets below thresholds
(cyclomatic <= 10, cognitive <= 15)
- Test count and coverage same or higher
- Zero dead code detected
On failure: git reset --hard HEAD~1. Never pause.
| Failure | Action |
|---|---|
| Tests fail after transform | Revert, plan smaller step |
| Coverage decreases | Write tests before continuing |
| Circular dependency | Extract shared into new module |
npx claudepluginhub arbazkhan971/godmodeExecutes safe, incremental refactoring with test verification at each step. Supports target, sweep, and extract modes for files, functions, or complexity hotspots.
Safe, test-gated refactoring methodology: behavior-preserving transformations (extract, inline, rename, move, simplify, delete) enforced with full test runs before, during, and after each change.
Applies disciplined refactoring in small, verifiable steps to improve code structure without changing behavior: extract functions, rename, move code.