Refactor Planner
Skill9 starsChanged 8 months agoMITView on GitHub
Creates a safe, step-by-step plan to refactor messy code without breaking existing behavior.
1 other project uses a version of this.
Adopted by
Most recently taken up by
- Da-loong/agent-skill-ostheir own version, first seen Jul 2, 2026
Other versions1 project uses a version of this.
Word for word · 0
None found.
Edited · 0
None found.
Wrote their own version · 1
- Da-loong/agent-skill-os★ 1same name
How matches are found. Word for word: the exact same text. Edited: shares passages with this file (“99% same” means 99% of its five-word phrases also appear here; 10% or more counts). Their own version: similar meaning, or, weakest, the same name. We can’t tell which project had it first. Projects are counted among the 200 most-starred candidates, and mentions are links to the repository we found, up to 50 per site, so both counts are a floor.
In this repository61 other files it gives its agents.
- Accessibility Audit HelperSkill
- Agent Context File WriterSkill
- Agent Evaluation Framework BuilderSkill
- AI Feature Spec WriterSkill
- API Documentation GeneratorSkill
- REST API Endpoint DesignerSkill
- Architecture ExplainerSkill
- Article RepurposerSkill
- Auth Flow PlannerSkill
- Blog Outline GeneratorSkill
- Breaking Change DetectorSkill
- Bug Root Cause AnalyzerSkill
- Caching Strategy AdvisorSkill
- Changelog CuratorSkill
- Code Review ChecklistSkill
- Database Schema ReviewerSkill
- Docker Compose GeneratorSkill
- Documentation Gap FinderSkill
- Edge Case DiscoverySkill
- Error Log SummarizerSkill
- FAQ GeneratorSkill
- Flaky Test AnalyzerSkill
- Form UX OptimizerSkill
- Git Commit WriterSkill
- Hallucination Risk ReviewerSkill
- Hybrid Search ArchitectSkill
- Incident Postmortem WriterSkill
- Issue to PR PlannerSkill
- Landing Page Copy ImproverSkill
- LangGraph State Machine DesignerSkill
- LLM Cost OptimizerSkill
- LLM Tracing and Observability SetupSkill
- MCP Integration AssistantSkill
- MCP Server BuilderSkill
- Migration Guide WriterSkill
- Newsletter Summary WriterSkill
- Observability ChecklistSkill
- Playwright Test BuilderSkill
- PR Description WriterSkill
- Prompt Injection Defense AuditorSkill
- Prompt RefinerSkill
- Prompt Version Control WorkflowSkill
- RAG Chunking Strategy AdvisorSkill
- RAG Workflow PlannerSkill
- React Component ReviewerSkill
- README WriterSkill
- Release Notes GeneratorSkill
- Responsive Layout ReviewerSkill
- SDK Quickstart WriterSkill
- SEO Content OptimizerSkill
- SEO Metadata GeneratorSkill
- Social Post Thread WriterSkill
- Sprint Summary GeneratorSkill
- SQL Query OptimizerSkill
- Stack Trace AnalyzerSkill
- Technical Blog Post WriterSkill
- Tech Debt AuditorSkill
- Troubleshooting Guide BuilderSkill
- Unit Test ImproverSkill
- Unit Test WriterSkill
- The first 60 shown.
The file
We split this skill into the rules it gives an agent
6 rules. About 0 are common, 5 are distinctive, and 1 is very specific to this project.
≈0
Common · estimate
Many files like this have a rule of this kind.
≈5
Distinctive · estimate
This author's own choices. Worth a look.
1
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Distinctive: line 18
Use this when you have messy, hard-to-understand code that works but needs cleaning up before you can safely add features.
- Very specific: line 34
Add the "Prompt / Instructions" section below to your .cursorrules file, or paste it directly into the Cursor AI pane before sharing the …
- Distinctive: line 42
When asked to plan a refactor, follow these steps precisely:
- Distinctive: line 44
Read the code thoroughly: If a file path is given, read the full file.
- Distinctive: line 46
Identify code smells: Look for:
- Distinctive: line 70
Leave the code in a working state after it is applied
≈ “Common” is an estimate: at least 1 in 5 of the 213,895 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
Refactor Planner
What this skill does
This skill directs the agent to analyze a block of code (or an entire module) and produce an ordered, safe refactoring plan. Rather than rewriting everything at once, it breaks the work into small, reversible steps — each one leaving the tests green and the behavior unchanged. It identifies code smells, maps dependencies, flags high-risk areas, and sequences the changes so you can ship incrementally without introducing regressions.
Use this when you have messy, hard-to-understand code that works but needs cleaning up before you can safely add features.
How to use
Claude Code / Cline
Copy this file to .agents/skills/refactor-planner/SKILL.md in your project root.
Then ask the agent:
- "Use the Refactor Planner skill on
src/utils/dataProcessor.ts." - "Plan a safe refactor of this function using the Refactor Planner skill."
Paste in the code you want refactored, or point to a file path.
Cursor
Add the "Prompt / Instructions" section below to your .cursorrules file, or paste it directly into the Cursor AI pane before sharing the code you want refactored.
Codex
Paste the target code into the chat along with the instructions from the section below. For large files, include the full file plus any files that import from it so Codex can map dependencies.
The Prompt / Instructions for the Agent
When asked to plan a refactor, follow these steps precisely:
- Read the code thoroughly. If a file path is given, read the full file. Also read any files that import from it or that it imports from, so you understand the dependency graph.
- Identify code smells. Look for:
- Functions longer than 40 lines
- Deeply nested conditionals (more than 3 levels)
- Duplicated logic (copy-paste code)
- Magic numbers and hardcoded strings
- God objects or functions that do too many things
- Inconsistent naming conventions
- Mutable shared state
- Missing or misleading comments
- Dead code (unreachable or unused)
- Map dependencies. For each problematic section, note:
- What calls it (callers)
- What it calls (callees)
- What data it reads or mutates
- Whether it has test coverage
- Assess risk for each change. Label every planned step as:
- Low risk — pure rename, extract with no logic change, add a comment
- Medium risk — restructure logic that has test coverage
- High risk — change with no tests, touches shared state, or modifies a public API
- Generate the ordered refactoring plan. Each step must:
- Be small enough to do in a single commit
- Leave the code in a working state after it is applied
- Be described clearly so a developer can execute it manually
- Reference the specific function, class, or line range it affects
- Come with a one-line "how to verify this step didn't break anything"
- Format the output as follows:
## Code Smells Found
- [Smell type]: [Description] — [Location]
...
## Dependency Map
- `functionName` is called by: X, Y, Z
- `functionName` depends on: A, B
...
## Refactoring Plan
### Step 1 — [Title] [Risk: Low/Medium/High]
**What:** [What to change]
**Why:** [Which smell this addresses]
**How:** [Concrete action, e.g., "Extract lines 45–67 into a new function called `validateInput`"]
**Verify:** [How to confirm nothing broke, e.g., "Run `npm test` — all existing tests should pass"]
### Step 2 — ...
...
## High-Risk Flags
[List any steps that need special attention, tests to write first, or API surface changes that require coordination]- Do not rewrite the code yet. The output is a plan only. If the user then asks you to execute a specific step, do it one step at a time.
Example
Input to Agent:
"Use the Refactor Planner skill on this function:
function process(data: any) { let result = []; for (let i = 0; i < data.length; i++) { if (data[i].type === 'A') { if (data[i].value > 100) { if (data[i].active) { result.push({ id: data[i].id, score: data[i].value * 1.5 }); } } } else if (data[i].type === 'B') { if (data[i].value > 50) { result.push({ id: data[i].id, score: data[i].value * 1.2 }); } } } return result; } ```"
Output from Agent:
Code Smells Found
- Deep nesting: Triple-nested conditionals make the logic hard to follow — lines 3–13
- Magic numbers:
100,1.5,50,1.2have no named meaning — lines 5, 8, 12, 13- Loose typing:
data: anyloses all type safety — line 1Refactoring Plan
Step 1 — Name the magic numbers [Risk: Low]
What: Extract
100,1.5,50,1.2into named constants at the top of the file. Why: Eliminates magic numbers, makes thresholds searchable. How: Addconst TYPE_A_THRESHOLD = 100,const TYPE_A_MULTIPLIER = 1.5, etc. Verify: Run existing tests — output should be identical.Step 2 — Add types [Risk: Low]
What: Define an
Iteminterface and replaceany. Why: Prevents silent bugs from misshapen input. How:interface Item { id: string; type: 'A' | 'B'; value: number; active?: boolean }Verify: TypeScript should compile with no new errors.Step 3 — Extract per-type handlers [Risk: Medium]
What: Move the type A and type B branches into
processTypeA(item)andprocessTypeB(item). Why: Eliminates deep nesting, makes each branch independently testable. How: Extract the innerifblocks into separate functions that return{ id, score } | null. Verify: Run tests; add a unit test for each new function before extracting.
Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

