Refactor

From softspark/ai-toolkit · View interactive version

Refactor is an AI agent skill from the GitHub repository softspark/ai-toolkit. Refactors code for quality and maintainability. Triggers: refactor, clean up, restructure, improve code, modernize.

How to use this skill

Skill file

Refactor Code

$ARGUMENTS

Plan and execute code refactoring.

Usage

/refactor [target] [--pattern=<pattern>]

What This Command Does

  1. Analyzes target code
  2. Identifies refactoring opportunities
  3. Plans refactoring steps
  4. Executes with user approval

Refactoring Patterns

| Pattern | Description |

|---------|-------------|

| extract-function | Extract code block to function |

| extract-component | Extract UI component |

| rename | Rename symbol across codebase |

| move | Move code to better location |

| inline | Inline unnecessary abstraction |

| simplify | Simplify complex logic |

Safety Rules

Output Format

## Refactoring Plan: [Target]

### Current State
- **Location**: [file:line]
- **Issues**: [what's wrong]

### Proposed Changes
1. [Change 1]
2. [Change 2]

### Impact Analysis
- **Files affected**: [count]
- **Risk level**: [Low/Medium/High]

### Test Coverage
- [x] Unit tests exist
- [ ] Integration tests needed

### Rollback

git revert [commit]

Approval Required

Before executing:

Common Rationalizations

| Excuse | Why It's Wrong |

|--------|----------------|

| "It works, don't touch it" | Working code that's hard to maintain slows every future change |

| "We'll refactor it later" | Later never comes — refactor when the pain is fresh and context is loaded |

| "It's too risky to change" | That's exactly why it needs refactoring — risk compounds with complexity |

| "Just one more hack won't hurt" | Each hack makes the next one easier to justify — break the cycle now |

| "We need to rewrite from scratch" | Incremental refactoring is safer and delivers value continuously |

READ BEFORE WRITE

This command analyzes and plans first.

Execution requires explicit approval.

MANDATORY: Documentation Update

After refactoring, update documentation:

Required Updates

| Change Type | Update |

|-------------|--------|

| API changes | API documentation |

| Architecture | architecture note if significant |

| Patterns | Best practices docs |

| Breaking changes | Migration guide |

Post-Refactoring Checklist

Automated Smell Detection

Run the bundled script to find refactoring opportunities:

python3 ${CLAUDE_SKILL_DIR}/scripts/refactor-scan.py src/

Parallel Refactoring (complex cases)

If the scan reports >5 smells across multiple files, use Agent Teams:

Create an agent team for refactoring:
Keep each teammate's configured model and effort unless the user selected an override.
- Teammate 1 (code-reviewer): "Plan the refactoring strategy for [identified smells]. Document what to change and why." READ-ONLY.
- Teammate 2 (backend-specialist): "Implement the refactoring changes identified by the reviewer."
Teammate 1 completes first, then Teammate 2 acts on the plan.

Related Skills

Rules

Gotchas

When NOT to Use

Use this skill with your AI agent: Open on Skill Issue to copy, download, or add to your library. Works with Claude, ChatGPT, Gemini, Cursor, Windsurf and more.