Skip to main content
skill CX Codex

refactor · fradser — Claude Code skill: what it does, how to install

Runs automated code refactoring on specified files, directories, or recent git modifications.

MIT 113 installs ★ 597 updated 2026-10-09

Install into Claude Code · Skills CLI (Vercel) All methods and platforms ↓
npx skills add FradSer/dotclaude --skill refactor -a claude-code
Open on GitHub

What refactor does

The skill resolves target files using explicit directory paths or semantic code searches via Grep. When invoked without arguments, it defaults to uncommitted edits discovered through git diff --name-only. Folders like node_modules/, .git/, dist/, and build artifacts are excluded automatically.

Under the hood, it triggers the refactor:code-simplifier agent along with the refactor:best-practices rule set. The agent retains external interfaces and runtime behavior while eliminating obsolete routines and simplifying control flow.

Because changes apply immediately without a confirmation prompt, keeping a clean git working tree before invoking the skill is essential. Once finished, the skill prints an categorized summary of edits along with an explicit rollback command such as git restore --worktree --staged <files>.

What it helps with

  • simplify recently modified files before staging a commit
  • strip dead routines and legacy patterns from a specific file
  • refactor matching code locations located through semantic search
  • clean up directory structure while preserving public interfaces

Example prompts for the agent

  • /refactor src/services/auth.ts
  • /refactor
  • /refactor handleUserSession

How to install refactor

1Skills CLI (Vercel)

npx skills add FradSer/dotclaude --skill refactor -a claude-code

2Manually: put the files in place

~/.claude/skills/refactor/SKILL.md

Copy the whole skill folder; for one project use .claude/skills/refactor/

Step by step, with commands for each platform: How to install skills in Claude Code: five ways

Questions about refactor

How to install refactor in Claude Code?

Run npx skills add FradSer/dotclaude --skill refactor -a claude-code in your terminal.

What happens when /refactor is executed with no arguments?

It checks git diff --name-only to identify recently changed files. If no pending modifications exist, the skill exits immediately.

Can refactor handle entire repositories at once?

No, the skill restricts itself to explicitly provided files, search matches, or recent diffs; project-wide updates require /refactor-project.

Source text

SKILL.md · MIT
---
name: refactor
description: Executes automated refactoring for specific files, directories, or semantic queries. This skill should be used when the user asks to refactor specific files or directories, simplify recently changed code, clean up dead code in a limited scope, or invokes "/refactor".
argument-hint: "[files-or-directories-or-semantic-query]"
allowed-tools: ["Task", "Read", "Bash(git:*)", "Grep", "Glob"]
user-invocable: true
---

# Refactor Command

Execute automated refactoring for $ARGUMENTS using `refactor:code-simplifier` agent.

## Pre-operation Checks
**Goal**: Ensure scope resolution is deterministic before launching the agent.

**Actions**:
1. Run `git rev-parse --is-inside-work-tree` and continue even if false when explicit paths are provided
2. Normalize arguments by trimming whitespace and preserving quoted path segments
3. Treat an empty argument list as "recent changes" mode

## Phase 1: Determine Target Scope
**Goal**: Identify files to refactor based on arguments or session context.

**Actions**:
1. If arguments provided: verify as file/directory paths using Glob
2. If paths exist: use them directly as refactoring scope
3. If paths don't exist: treat arguments as semantic query, search codebase with Grep
4. If no arguments: run `git diff --name-only` to find recently modified code files
5. If no recent changes found: inform user and exit without refactoring

CRITICAL: Never include `node_modules/`, `.git/`, `dist/`, `build/`, lock files, or compiled artifacts in refactoring scope — use Grep `--glob` exclusions to enforce.

See `references/scope-determination.md` for search strategies and edge cases.

## Phase 2: Launch Refactoring Agent
**Goal**: Execute `refactor:code-simplifier` agent with aggressive mode enabled.

**Actions**:
1. Launch `refactor:code-simplifier` agent with target scope and aggressive mode flag
2. Pass scope determination method (paths, semantic query, or session context)
3. Agent auto-loads `refactor:best-practices` skill and applies language-specific patterns

See `references/agent-configuration.md` for detailed Task parameters.

## Phase 3: Summary
**Goal**: Report comprehensive summary of changes.

**Actions**:
1. Report total files refactored and changes categorized by improvement type
2. List best practices applied and legacy code removed
3. Suggest tests to run and provide rollback command tailored to actual scope (for example: `git restore --worktree --staged <files>`)

See `references/output-requirements.md` for detailed summary format.

## Requirements

- Execute immediately without user confirmation
- Refactor ALL matching files when semantic search returns multiple results
- Direct users to `/refactor-project` for project-wide scope
- Preserve behavior and public interfaces unless user explicitly requests a behavior change

© FradSer · MIT · FradSer/dotclaude

Similar skills

All skills for Code review and refactoring →

refactor by other authors comes first.

refactor official github The refactor skill reshapes existing code without changing its external behavior. Use it for gradual cleanup of large functions, duplication, weak types, and code smells. CX Codex +1 22,321installs refactor parcadei refactor is a Claude Code skill that guides code changes through analysis, planning, implementation, review, and test validation. It activates for refactoring requests that should preserve existing behavior. CX Codex +1 625installs refactor smallnest refactor restructures code safely based on Martin Fowler's catalog without altering external behavior. Fixes code smells through small, verifiable steps. CX Codex +1 538installs refactor boshu2 refactor — a Claude Code skill for restructuring code without changing observable behavior. Runs on requests to clean up, extract functions, remove dead code, or simplify logic. CX Codex +1 123installs refactor pproenca A skill with 43 refactoring rules drawn from Martin Fowler's catalog and Clean Code. Useful when you want the agent to restructure code by a fixed set of rules instead of guessing. CX Codex +1 661installs refactor-cleaner sangrokjung refactor-cleaner — a subagent that hunts down code nobody calls: unused files, exports and npm packages. Each hit gets a reference search before anything is deleted. CX Codex ★ 880repo stars deslop prathamdby A skill for Claude Code, Codex, and Cursor that strips code slop from a git diff while keeping behavior identical. Cleans up staged or working tree edits. CX Codex +1 736installs antfu-simplify Anthony Fu antfu-simplify — a skill for Claude Code and Codex that cuts working tree diffs down to minimal working code through systematic ablation. CX Codex +1 312installs code-refactor-review jnsahaj The code-refactor-review skill examines diffs and PRs for reuse, clear boundaries, and fit with the surrounding codebase. Use it when a refactor needs a close review. CX Codex +1 181installs refactor-guided CloudAI-X refactor-guided guides structural refactoring in small steps and runs tests after each change. It keeps feature work separate from code restructuring. CX Codex +1 ★ 1,424repo stars refactor-specialist NYCU-Chung refactor-specialist is a Claude Code subagent for restructuring code across files. It handles broad renames, file moves, module extraction, and directory changes. CX Codex ★ 267repo stars

From the same set16

The whole set →
plugin-best-practices plugin-best-practices validates Claude Code plugin structure, manifests, and architecture against framework standards. Ensures your plugin meets requirements before marketplace submission. CX Codex +1 121installs commit This skill creates atomic conventional commits through git-agent. Use it when a short intent should become a focused Git commit. CX Codex +1 121installs optimize-plugin optimize-plugin validates Claude plugin structure, runs Python sanity checks, and fixes issues via a subagent. Useful when auditing or refactoring plugin manifests and components. CX Codex +1 117installs create-prd The create-prd skill turns product ideas into a structured PRD through a guided interview, then saves it as Markdown or creates a Feishu document. CX Codex +1 117installs create-issues create-issues automates GitHub issue creation with TDD principles, proper labeling, and auto-closing keywords. Detects repository templates, applies conventions, and links issues to epics or related tasks. CX Codex +1 116installs best-practices best-practices enforces language-specific standards and framework rules for TypeScript, Python, Go, Swift, and React. CX Codex +1 115installs resolve-issues resolve-issues — a skill for Claude Code handles GitHub issues with an isolated worktree and TDD. It then hands PR creation to the project’s quality and review workflow. CX Codex +1 112installs create-pr The create-pr skill opens GitHub pull requests after quality and security checks, then hands them to CI monitoring and reviewer-comment triage. CX Codex +1 109installs

Project sponsors

Companies that keep this analytics open