From tdd-dev
Perform safe refactoring protected by existing tests: **$ARGUMENTS**
How this command is triggered — by the user, by Claude, or both
Slash command
/tdd-dev:tdd-refactorThe summary Claude sees in its command listing — used to decide when to auto-load this command
# TDD Safe Refactor Perform safe refactoring protected by existing tests: **$ARGUMENTS** ## Parse Arguments Extract from arguments: - **Target**: What to refactor (required) - can be: - File path: `src/utils.ts` - Symbol name: `calculateTotal` - Description: `extract validation logic` - **--strict / --standard / --relaxed**: Override strictness mode (optional) - **--file <path>**: Target specific file (optional, overrides target parsing) - **--plan**: Force planning mode (require approval before refactoring) - **--skip-plan**: Skip planning entirely, execute directly ## Target Res...
Perform safe refactoring protected by existing tests: $ARGUMENTS
Extract from arguments:
src/utils.tscalculateTotalextract validation logicResolve the refactor target:
If looks like a file path (contains / or .):
If looks like a symbol (single word, camelCase, PascalCase):
If descriptive text:
Determine planning behavior based on flags:
--skip-plan flag: Skip planning, proceed directly to refactoring--plan flag: Force planning before refactoringIf planning is enabled (via --plan flag or user choice):
Critical: Refactoring requires GREEN state to begin.
Pre-Refactor Check:
Tests: X passed, 0 failed
Status: GREEN ✓ (safe to refactor)
Relevant tests covering target:
- [test 1]
- [test 2]
- [test 3]
If tests are failing:
Cannot refactor - tests are failing.
Failing tests:
- [test names]
Fix failing tests first, then retry refactor.
Use /tdd-dev:bug to fix issues with TDD.
Analyze the target code for improvements:
Code smells to address:
Proposed changes:
Present analysis:
Refactoring Analysis: [target]
Current Issues:
1. [issue]: [description]
2. [issue]: [description]
Proposed Refactorings:
1. [refactoring]: [benefit]
2. [refactoring]: [benefit]
Proceed with refactoring? (Each step verified by tests)
For each proposed refactoring:
Refactoring Step [N]: [description]
Change: [what was modified]
Tests: X passed, 0 failed
Status: GREEN ✓ (refactoring safe)
Apply as appropriate:
If any test fails after a change:
Refactoring REVERTED: [step description]
Reason: Test failure after change
Failing test: [test name]
Options:
1. Try smaller refactoring step
2. Skip this refactoring
3. Investigate test coupling
During refactoring:
Refactoring: [target]
Step [N]/[total]: [transformation]
Before: [brief description]
After: [brief description]
Tests: PASS ✓
When refactoring is complete:
Refactoring Complete: [target]
Changes Applied:
1. [change 1]
2. [change 2]
3. [change 3]
Files Modified: [list]
Tests: X passed, 0 failed
Final Status: GREEN ✓
Code quality improved while maintaining all behavior.
If behavior change is needed:
Note: Requested change appears to modify behavior, not just structure.
This requires a test change. Use:
- /tdd-dev:feature for new behavior
- /tdd-dev:bug for fixing incorrect behavior
Continue with structure-only refactoring? (y/n)
If target code lacks test coverage:
Warning: Limited test coverage for [target]
Existing tests may not catch regressions.
Options:
1. Add tests first (recommended)
2. Proceed carefully with manual verification
3. Abort refactoring
Recommendation: Use /tdd-dev:feature to add test coverage first.
Begin safe refactoring process.
npx claudepluginhub hculap/better-code --plugin tdd-dev/refactor-guidedPerforms safe incremental refactoring on target files directories or descriptions verifying tests at each step with git commits and reverts.
/refactorSystematically refactors target code area: identifies smells like long functions and duplicates, verifies/adds tests, plans atomic steps, executes with verification, preserves behavior.
/sc-refactorPlans refactoring opportunities in code or executes specific behavior-preserving refactors like extract/rename/simplify, verifying with tests before/after.
/refactorRefactors code or file via structured workflow (analyze quality/smells, plan changes, add tests, refactor incrementally, verify with tests/report). Outputs analysis/plan/logs. Also supports component and performance modes.
/refactorSafely refactors codebases using patterns like extract, inline, move, rename; runs impact analysis, verifies test coverage, applies atomic git commits with post-change verification and metrics report.
/tdd-refactorRefactors code safely using TDD — runs tests, detects code smells, applies design patterns and SOLID principles, optimizes performance, and verifies all tests remain green.