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
npx skills add FradSer/dotclaude --skill refactor -a claude-codeWhat 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-code2Manually: put the files in place
~/.claude/skills/refactor/SKILL.mdCopy the whole skill folder; for one project use .claude/skills/refactor/
1Skills CLI (Vercel)
npx skills add FradSer/dotclaude --skill refactor -a codex2Manually: put the files in place
.agents/skills/refactor/SKILL.mdFor all projects use ~/.agents/skills/
1Skills CLI (Vercel)
npx skills add FradSer/dotclaude --skill refactor -a cursor2Manually: put the files in place
.cursor/skills/refactor/SKILL.mdCursor also reads .agents/skills/ and .claude/skills/
1GitHub CLI
gh skill install FradSer/dotclaude refactor/skills/refactor2Manually: put the files in place
.github/skills/refactor/SKILL.md1Skills CLI (Vercel)
npx skills add FradSer/dotclaude --skill refactor -a gemini-cli2Platform CLI
gemini skills install https://github.com/FradSer/dotclaude --path refactor/skills/refactorManually: put the files in place
.devin/skills/refactor/SKILL.mdThe legacy .windsurf/skills/ path still works
Skills CLI (Vercel)
npx skills add FradSer/dotclaude --skill refactor -a opencodeClaude.ai
Zip the folder and upload it in Settings → Capabilities → Skills
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.