Agent skill
refactor
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".
Install this agent skill to your Project
npx add-skill https://github.com/FradSer/dotclaude/tree/main/refactor/skills/refactor
SKILL.md
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:
- Run
git rev-parse --is-inside-work-treeand continue even if false when explicit paths are provided - Normalize arguments by trimming whitespace and preserving quoted path segments
- 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:
- If arguments provided: verify as file/directory paths using Glob
- If paths exist: use them directly as refactoring scope
- If paths don't exist: treat arguments as semantic query, search codebase with Grep
- If no arguments: run
git diff --name-onlyto find recently modified code files - If no recent changes found: inform user and exit without refactoring
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:
- Launch
refactor:code-simplifieragent with target scope and aggressive mode flag - Pass scope determination method (paths, semantic query, or session context)
- Agent auto-loads
refactor:best-practicesskill and applies language-specific patterns
See references/agent-configuration.md for detailed Task parameters.
Phase 3: Summary
Goal: Report comprehensive summary of changes.
Actions:
- Report total files refactored and changes categorized by improvement type
- List best practices applied and legacy code removed
- 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-projectfor project-wide scope - Preserve behavior and public interfaces unless user explicitly requests a behavior change
Recommended Agent Skills
Expand your agent's capabilities with these related and highly-rated skills.
optimize-plugin
This skill should be used when the user asks to "validate a plugin", "optimize plugin", "check plugin quality", "review plugin structure", or "run plugin optimizer".
plugin-best-practices
This skill should be used when the user asks to "validate plugin structure", "review manifest files", "check frontmatter compliance", "verify tool invocation patterns", "explain plugin component types", or needs Claude Code plugin architectural guidance.
init-config
Generates a CLAUDE.md file with AI-driven environment detection and advanced configuration options. This skill should be used when the user asks to "initialize config", "setup claude config", "create CLAUDE.md", or needs help configuring project instructions.
start-feature
Starts working on a new feature branch using git-flow. This skill should be used when the user asks to "start a feature", "create feature branch", "begin new feature", "git flow feature start", or wants to start a new feature.
finish-feature
Finalizes and merges a feature branch into develop using git-flow. This skill should be used when the user asks to "finish a feature", "merge feature branch", "complete feature", "git flow feature finish", or wants to finalize a feature branch.
finish-hotfix
Finalizes a hotfix and merges it into main and develop using git-flow. This skill should be used when the user asks to "finish a hotfix", "merge hotfix branch", "complete hotfix", "git flow hotfix finish", or wants to finalize a hotfix.
Didn't find tool you were looking for?