refactor: Claude Code Skill & Agent Tool
An open-source skill by github (opens in a new tab), published in the github/awesome-copilot (opens in a new tab) repository on GitHub. Surgical refactoring that improves maintainability without changing behavior: extract functions, rename variables, break up god functions, tighten types and remove code smells step by step.
Install refactor
Requires Node.jsnpx skills add github/awesome-copilot --skill refactorRun this command in your project terminal to install this skill for Claude Code.
What this skill does
refactor is a skill for surgical code refactoring: it improves the structure, readability and maintainability of existing code without changing what the code does. It is meant for gradual improvement — cleaning up a module before adding a feature, or paying down debt one file at a time — rather than rewriting a project from scratch.
The skill teaches your agent golden rules that keep refactoring safe: behavior is preserved, changes are made in small steps with tests run after each one, a commit marks every safe state, and refactoring is never mixed with feature work. It also states when not to refactor, for example code that has no tests to prove nothing broke.
At its core is a catalog of common code smells with before-and-after fixes: long functions, duplicated logic, god objects, long parameter lists, feature envy, primitive obsession, magic numbers and strings, deeply nested conditionals, dead code and inappropriate intimacy between modules. For each, the agent applies a named technique — extract method, introduce a domain type, guard clauses and early returns, named constants. Use it with Claude Code to modernize legacy code while your test suite proves nothing broke.
Key Capabilities
- Golden rules: preserve behavior, take small steps, test after each change
- Catalog of ten code smells with before-and-after fixes
- Extract method, guard clauses, named constants and domain types
- Improves type safety and removes dead and duplicated code
- Says when not to refactor, and keeps refactors apart from feature changes
How to use with Claude Code & AI Agents
Install the skill
Run the command above at the root of your project. The CLI asks which agents to set up — Claude Code, Cursor and other supported agents — and adds refactor to the project, so teammates who pull the repository get it too. Add-gto install it for your user account across every project.Open a new agent session
Start a fresh Claude Code session in that project so the agent loads the new skill. This skill needs no extra tool or API key.Ask in plain words
Describe the task, for example:“Refactor processOrder into smaller functions without changing its behavior.”The agent matches your request to the skill's description and follows its SKILL.md instructions step by step. Read them on GitHub before using the skill on a system that matters.