/refactor
> Restructure code for clarity and maintainability without changing behavior.
Best use case
/refactor is best used when you need a repeatable AI agent workflow instead of a one-off prompt.
> Restructure code for clarity and maintainability without changing behavior.
Teams using /refactor should expect a more consistent output, faster repeated execution, less prompt rewriting.
When to use this skill
- You want a reusable workflow that can be run more than once with consistent structure.
When not to use this skill
- You only need a quick one-off answer and do not need a reusable workflow.
- You cannot install or maintain the underlying files, dependencies, or repository context.
Installation
Claude Code / Cursor / Codex
Manual Installation
- Download SKILL.md from GitHub
- Place it in
.claude/skills/refactor/SKILL.mdinside your project - Restart your AI agent — it will auto-discover the skill
How /refactor Compares
| Feature / Agent | /refactor | Standard Approach |
|---|---|---|
| Platform Support | Not specified | Limited / Varies |
| Context Awareness | High | Baseline |
| Installation Complexity | Unknown | N/A |
Frequently Asked Questions
What does this skill do?
> Restructure code for clarity and maintainability without changing behavior.
Where can I find the source code?
You can find the source code on GitHub using the link provided at the top of the page.
Related Guides
AI Agents for Coding
Browse AI agent skills for coding, debugging, testing, refactoring, code review, and developer workflows across Claude, Cursor, and Codex.
Best AI Skills for Claude
Explore the best AI skills for Claude and Claude Code across coding, research, workflow automation, documentation, and agent operations.
Cursor vs Codex for AI Workflows
Compare Cursor and Codex for AI coding workflows, repository assistance, debugging, refactoring, and reusable developer skills.
SKILL.md Source
# /refactor > Restructure code for clarity and maintainability without changing behavior. ## Usage ``` /refactor <target> [--strategy <strategy>] [--safe] ``` ## What It Does Analyzes the target code, identifies improvement opportunities, plans a safe refactoring sequence, executes it, and verifies no behavior changes. Runs tests before and after every transformation. ## Implementation 1. **Analyze** -- read the target code, identify code smells (long functions, deep nesting, duplication, poor naming, high coupling). 2. **Plan** -- propose refactoring strategy: extract function, rename, decompose, inline, introduce pattern. 3. **Baseline** -- run tests to establish green state. If tests fail, stop. 4. **Execute** -- apply refactorings one at a time. Run tests after each. 5. **Verify** -- confirm all tests still pass, behavior unchanged. 6. **Report** -- diff summary, complexity reduction metrics, before/after. Strategies: `extract`, `rename`, `decompose`, `simplify`, `decouple`, `auto` (detect best). ## Examples ```bash # Auto-detect and refactor /refactor lib/optimal_engine/intake.ex # Extract functions from a long module /refactor lib/app.ex --strategy extract # Safe mode: smaller steps, test after every change /refactor lib/complex_module.ex --safe ```
Related Skills
/do
> The agent's primary skill. Customize this to match your agent's purpose.
/report
> Generate structured reports. Director-owned.
/primary
> Main workflow execution and routing. Director-owned.
Qualify
## Command
Prospect
## Command
Close Plan
## Command
Battlecard
## Command
Spec
## Command
Schedule
## Command
Repurpose
## Command
Ideate
## Command
Analyze
## Command