/refactor
Refactor: $ARGUMENTS
$ npx -y skills add vignesh2027/claude-best-practice --agent claude-codeHow it fires
How this command gets triggered: by you, by Claude, or both.
- Fires itselfClaude auto-loads it when your prompt matches the work.
- You can call itInvoke it directly when you want it.
- Slash command
/refactor
Context preview
What this command does when you run it.
Refactor: $ARGUMENTS
Command definition
refactor.md/refactor — Safe Refactoring Workflow
Refactor: $ARGUMENTS
Pre-Refactor Safety Check
Before touching anything:
1. **Confirm tests exist** — run them, they must pass
npm test
If tests don't exist or don't pass, STOP and report before proceeding.
2. **Snapshot behavior** — note what the code currently does at a high level
3. **Identify dependencies** — what calls this? What does this call?
Refactoring Rules
- Make ONE type of change at a time (rename OR restructure OR extract, not all together)
- Run tests after each change
- Commit at each stable point
- Do NOT fix bugs or add features during refactor (separate work)
Change Types (in safe order)
Level 1: Rename Only
Rename files, functions, variables for clarity.
Old: getUserData() New: fetchUserProfile()
Level 2: Extract
Extract repeated logic into shared functions.
Before: same 10 lines in 3 places After: one shared utility function
Level 3: Restructure
Move code between files, reorganize module boundaries.
Level 4: Rewrite
Full rewrite of logic — requires most test coverage.
Post-Refactor Verification
1. All tests still pass 2. No behavior change (output identical for same inputs) 3. Complexity reduced (fewer lines, cleaner structure) 4. No dead code introduced
Report: lines removed, complexity reduced, test status.
The most comprehensive, production-ready guide to mastering Claude Code From vibe coding → agentic engineering → autonomous AI development teams Built for engineers who treat Claude Code as infrastructure, not a toy.
Repo: vignesh2027/claude-best-practice

