# Refactor

> Refactor is an open-source agent skill for developer tools. Finds where refactoring pays off from git churn and bug history, then applies it safely. It is available on Claude Code.

- **Kind:** Skill
- **Pricing:** Open source
- **Platforms:** Claude Code
- **Website:** https://github.com/duthaho/skillhub/tree/main/.claude/skills/refactor
- **Repository:** https://github.com/duthaho/skillhub
- **GitHub stars:** 9
- **License:** MIT
- **Skill name:** refactor
- **Collection:** https://github.com/duthaho/skillhub
- **Categories:** [developer tools](https://ai-powered.com/categories/developer-tools)
- **Listing updated:** 2026-12-04

## About

Refactor works in two modes. A survey pass ranks candidate areas of the codebase using evidence such as frequently edited complex files, a recurring bug log and planned upcoming work, then gives each candidate a verdict of refactor, prep, leave or watch. Leaving code alone is the default, and design patterns must be justified by a concrete problem in the codebase rather than by general best practice. Results are saved as a brief and tracked in a debt register so later surveys start from what has changed.

Execution mode takes one approved target and changes it in small named moves, such as extracting a function or renaming across call sites. The skill checks for a passing test suite before starting, writes characterization tests when an area has none, and reverts any step that turns the suite red rather than patching forward. Bugs found along the way are logged for separate fixing so the diff keeps its behavior intact.

The skill expects a git repository and a runnable test suite, and it uses git history to measure churn. It can also read an optional bug log and planning notes kept in the project's output folder.

## When your agent uses it

> Evidence-driven refactoring — where does structural improvement actually pay off, then make that change without changing behavior. Survey mode diagnoses by evidence, not aesthetics — git churn × complexity hotspots, the recurring-bug log, upcoming work — and verdicts each candidate REFACTOR/PREP/LEAVE/WATCH, where LEAVE is the default and "the textbook recommends it" is never a reason. Execute mode takes one approved candidate in small behavior-preserving moves, suite green after each. Keeps a debt register in out/refactor/tracker.md so repeat surveys open with what changed. Use for "clean up this module", "improve the architecture", "pay down tech debt" — e.g. "/refactor", "/refactor <target>". For new behavior use feature; for something broken use bugfix.

## What it can access

From a static check of the files on GitHub; nothing was run.

- [Instructions only, no scripts](https://github.com/duthaho/skillhub/tree/HEAD/.claude/skills/refactor)
- [License: MIT](https://github.com/duthaho/skillhub/tree/HEAD/.claude/skills/refactor)

## Features

- **Evidence-based candidate survey:** Ranks code areas by git churn combined with complexity to find where structural work will actually pay off.
- **Verdict per candidate:** Labels each candidate as refactor, prep, leave or watch, with leave as the default outcome.
- **Pattern justification gate:** Requires any proposed design pattern to address a named problem with a file location and evidence.
- **Small behavior-preserving moves:** Applies refactors as named steps, running the test suite and checkpoint committing after each.
- **Characterization tests first:** Pins current behavior with tests around untested code before restructuring it.
- **Persistent debt register:** Keeps a tracker of verdicts so repeat surveys show what has changed since the last one.

## Good for

- Find the modules in this repo where cleanup would actually reduce future work
- Refactor a specific module without changing its behavior
- Pay down technical debt in a frequently edited file
- Prepare a messy area so an upcoming feature is easier to add
- Plan a large rename across the codebase in safe stages

## Install

### Claude Code

This skill ships in the `coding-loop` plugin. In Claude Code, add the marketplace and install the plugin (it may include other skills too):

```sh
/plugin marketplace add duthaho/skillhub
/plugin install coding-loop@skillhub
```

Or copy only this skill to `~/.claude/skills/refactor`:

```sh
tmp=$(mktemp -d) &&
git clone --depth 1 https://github.com/duthaho/skillhub.git "$tmp" &&
mkdir -p ~/.claude/skills &&
rm -rf ~/.claude/skills/refactor &&
cp -R "$tmp/.claude/skills/refactor" ~/.claude/skills/refactor &&
rm -rf "$tmp"
```

For one project only, put the folder in `.claude/skills/refactor` inside it instead.

### Codex

Copy the skill folder to `~/.agents/skills/refactor` to use it in every repository:

```sh
tmp=$(mktemp -d) &&
git clone --depth 1 https://github.com/duthaho/skillhub.git "$tmp" &&
mkdir -p ~/.agents/skills &&
rm -rf ~/.agents/skills/refactor &&
cp -R "$tmp/.claude/skills/refactor" ~/.agents/skills/refactor &&
rm -rf "$tmp"
```

For one repository only, put the folder in `.agents/skills/refactor` inside it instead.

### Cursor

Copy the skill folder to `~/.cursor/skills/refactor` to use it in every project:

```sh
tmp=$(mktemp -d) &&
git clone --depth 1 https://github.com/duthaho/skillhub.git "$tmp" &&
mkdir -p ~/.cursor/skills &&
rm -rf ~/.cursor/skills/refactor &&
cp -R "$tmp/.claude/skills/refactor" ~/.cursor/skills/refactor &&
rm -rf "$tmp"
```

For one project only, put the folder in `.cursor/skills/refactor` inside it instead.

### Gemini CLI

Run in a terminal (add `--scope workspace` to install it for the current workspace only):

```sh
gemini skills install https://github.com/duthaho/skillhub.git --path .claude/skills/refactor
```

Or copy the folder to `~/.gemini/skills/refactor` yourself.

### VS Code

For GitHub Copilot in VS Code, copy the skill folder to `~/.copilot/skills/refactor`:

```sh
tmp=$(mktemp -d) &&
git clone --depth 1 https://github.com/duthaho/skillhub.git "$tmp" &&
mkdir -p ~/.copilot/skills &&
rm -rf ~/.copilot/skills/refactor &&
cp -R "$tmp/.claude/skills/refactor" ~/.copilot/skills/refactor &&
rm -rf "$tmp"
```

For one project only, put the folder in `.github/skills/refactor` inside it instead.

### Other agents

Get the folder:

```sh
git clone --depth 1 https://github.com/duthaho/skillhub.git
```

Then copy `skillhub/.claude/skills/refactor` into your agent's skills folder as `refactor`. Agents that support SKILL.md read one folder per skill.

## FAQ

### What does the skill need to run?

It needs a test suite the agent can run to confirm behavior is preserved, and git history for the churn analysis.

### Does Refactor change code when I run the survey?

No. The survey only produces a brief and updates the tracker. Code changes happen only in execute mode on a target you choose.

### What happens if a refactoring step breaks a test?

The step is reverted and rethought or split into smaller moves instead of being patched until the tests pass.

### Does it fix bugs it finds during a refactor?

No. Bugs are logged for a separate fix so the refactor keeps existing behavior.

### How do I install Refactor in Claude Code?

Copy the skill folder from GitHub to ~/.claude/skills/refactor to use it in all your projects, or to .claude/skills/refactor in one project. Or install the coding-loop plugin, which includes it: /plugin marketplace add duthaho/skillhub, then /plugin install coding-loop@skillhub.

### Does Refactor run scripts?

No. It is instructions only, with no scripts. This comes from a static check of the files on GitHub; nothing was run. Read the files before you install it.

### Which AI agents can use Refactor?

Claude Code. It reads skills in the SKILL.md format; the install steps on this page show where to put the folder.

### What are the best alternatives to Refactor?

The closest alternatives to Refactor are Refactoring guide, Refactor, Refactor, Refactor seams and Improve architecture.

## Where this comes from

- Description: from the skill's own SKILL.md.

## Alternatives

- [Refactoring guide](https://ai-powered.com/skills/refactoring-guide): Refactoring guide is an open-source agent skill for developer tools.
- [Refactor](https://ai-powered.com/skills/refactor-zerotechdebt): Refactor is an open-source agent skill for developer tools.
- [Refactor](https://ai-powered.com/skills/refactor-kzytateishi): Refactor is an open-source agent skill for developer tools.
- [Refactor seams](https://ai-powered.com/skills/refactor-seams): Refactor seams is an open-source agent skill for developer tools.
- [Improve architecture](https://ai-powered.com/skills/improve-architecture): Improve architecture is an open-source agent skill for developer tools.
- [Refine](https://ai-powered.com/skills/refine): Refine is an open-source agent skill for developer tools.
- [Improve arch](https://ai-powered.com/skills/improve-arch): Improve arch is an open-source agent skill for developer tools.
- [Refactor plan](https://ai-powered.com/skills/refactor-plan): Refactor plan is an open-source agent skill for developer tools.

---
Source: https://ai-powered.com/skills/refactor-duthaho
