/refactor

> Restructure code for clarity and maintainability without changing behavior.

170 stars

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

$curl -o ~/.claude/skills/refactor/SKILL.md --create-dirs "https://raw.githubusercontent.com/Miosa-osa/canopy/main/library/skills/development/refactor/SKILL.md"

Manual Installation

  1. Download SKILL.md from GitHub
  2. Place it in .claude/skills/refactor/SKILL.md inside your project
  3. Restart your AI agent — it will auto-discover the skill

How /refactor Compares

Feature / Agent/refactorStandard Approach
Platform SupportNot specifiedLimited / Varies
Context Awareness High Baseline
Installation ComplexityUnknownN/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

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
```