بنقرة واحدة
refactor
Analyze codebase for technical debt and plan targeted refactoring
التثبيت باستخدام Codex أو Claude انسخ هذا Prompt والصقه في Codex أو Claude أو مساعد آخر ليراجع صفحة Skill ويثبّتها لك.
القائمة
Analyze codebase for technical debt and plan targeted refactoring
التثبيت باستخدام Codex أو Claude انسخ هذا Prompt والصقه في Codex أو Claude أو مساعد آخر ليراجع صفحة Skill ويثبّتها لك.
استنادا إلى تصنيف SOC المهني
Create Architecture Decision Record
Design API contracts with OpenAPI specifications
Assess architecture decisions tradeoffs and edge cases
Design database schemas with migrations and repository interfaces
Break requests into parallel tasks for team execution
Audit dependencies for vulnerabilities and plan upgrades
| name | refactor |
| description | Analyze codebase for technical debt and plan targeted refactoring |
| allowed-tools | Read, Write, Glob, Grep, Bash |
Structured workflow for identifying refactoring opportunities, assessing impact, and executing safe refactors that preserve behavior. Produces a refactoring plan with before/after examples and generates task files for large refactors.
Scan the codebase for common refactoring signals:
| Signal | Detection Method |
|---|---|
| Code duplication | Search for repeated patterns across files (similar function signatures, copy-paste blocks) |
| High complexity | Functions exceeding 60 lines, deeply nested conditionals (>3 levels), high cyclomatic complexity |
| Code smells | Long parameter lists (>4 params), god objects, feature envy, primitive obsession |
| Naming issues | Inconsistent naming conventions, misleading names, abbreviations without context |
| Dead code | Unused exports, unreachable branches, commented-out code blocks |
| Tight coupling | Concrete type dependencies where interfaces should be used, circular imports |
| Missing abstractions | Repeated patterns that could be extracted into shared utilities or interfaces |
For each opportunity found, record:
Output: Refactoring opportunity inventory sorted by severity then effort.
For each candidate refactoring, assess:
Impact Matrix:
| Refactoring | Files Affected | Test Coverage | Risk | Priority |
|-------------|---------------|---------------|------|----------|
| Extract X | 3 | 85% | Low | High |
| Rename Y | 12 | 40% | Med | Medium |
Rules:
For each approved refactoring, document:
## Refactoring: {Description}
### Motivation
Why this refactoring is needed (not just "code is messy" -- concrete impact on development).
### Before
{Actual code snippet showing the current state}
### After
{Code snippet showing the target state}
### Steps
1. {Concrete step with file paths}
2. {Next step}
3. ...
### Behavior Preservation
- [ ] All existing tests pass before starting
- [ ] No test modifications needed (tests validate behavior, not implementation)
- [ ] All existing tests pass after refactoring
- [ ] No new warnings or lint errors introduced
### Rollback
If the refactoring introduces issues: `git revert {commit}`. Each refactoring is a single commit.
Present the plan to the user for approval before proceeding.
For each approved refactoring item:
Rules:
If a refactoring is too large for a single session (Large effort, >10 files affected):
docs/spec/.llm/tasks/backlog/ using the task template## Dependencies: to enforce ordering where neededdocs/spec/.llm/STRATEGY.md with the refactoring planAfter completing refactoring:
docs/spec/.llm/PROGRESS.md with:
.claude/rules/| Pattern | When to Apply | Example |
|---|---|---|
| Extract Function | Duplicated logic, long functions | Pull repeated validation into validateInput() |
| Extract Interface | Testing difficulty, tight coupling | Create Repository interface from concrete PgRepo |
| Rename | Misleading names, inconsistent conventions | data -> userProfiles, handleStuff -> processPayment |
| Move | Feature envy, wrong package/module | Move FormatCurrency() from user to billing package |
| Inline | Over-abstraction, single-use wrappers | Remove wrapper that just delegates to one function |
| Replace Conditional with Polymorphism | Long switch/if-else chains | Strategy pattern for payment processors |
| Introduce Parameter Object | Functions with >4 parameters | Group related params into a struct/type |
| Anti-Pattern | Why It's Bad |
|---|---|
| Refactoring without tests | No way to verify behavior preservation |
| "While I'm here" refactoring | Scope creep makes reviews harder and increases risk |
| Renaming in a large codebase without tooling | Partial renames cause build failures |
| Refactoring and adding features in the same commit | Impossible to isolate regressions |
| Refactoring code you don't understand | Read and understand first, then refactor |
$ARGUMENTS