Refactoring
Restructure and clean up existing code without changing behavior. Use this skill when code refactoring is requested, including extracting components, improving naming, and reducing duplication.
Best use case
Refactoring is best used when you need a repeatable AI agent workflow instead of a one-off prompt.
Restructure and clean up existing code without changing behavior. Use this skill when code refactoring is requested, including extracting components, improving naming, and reducing duplication.
Teams using Refactoring should expect a more consistent output, faster repeated execution, less prompt rewriting.
When to use this skill
- You want a reusable workflow that can be run more than once with consistent structure.
When not to use this skill
- You only need a quick one-off answer and do not need a reusable workflow.
- You cannot install or maintain the underlying files, dependencies, or repository context.
Installation
Claude Code / Cursor / Codex
Manual Installation
- Download SKILL.md from GitHub
- Place it in
.claude/skills/refactoring/SKILL.mdinside your project - Restart your AI agent — it will auto-discover the skill
How Refactoring Compares
| Feature / Agent | Refactoring | Standard Approach |
|---|---|---|
| Platform Support | Not specified | Limited / Varies |
| Context Awareness | High | Baseline |
| Installation Complexity | Unknown | N/A |
Frequently Asked Questions
What does this skill do?
Restructure and clean up existing code without changing behavior. Use this skill when code refactoring is requested, including extracting components, improving naming, and reducing duplication.
Where can I find the source code?
You can find the source code on GitHub using the link provided at the top of the page.
Related Guides
SKILL.md Source
# Skill: Refactoring ## Metadata | Field | Value | |-------|-------| | **Skill ID** | SKL-0019 | | **Version** | 1.0 | | **Owner** | fixer | | **Inputs** | Target files, STATE.md, DECISIONS.md, existing tests | | **Outputs** | Refactored files, STATE.md updated | | **Triggers** | `REFACTOR_REQUESTED` | --- ## Purpose Improve internal structure of working code without changing behavior. Behavior before and after: identical. Structure before and after: better. --- ## Procedure 1. **Check for existing tests** before refactoring: - Tests exist: confirm they pass before starting - No tests: warn user that refactoring without tests carries risk; request confirmation 2. **Define refactor scope narrowly:** - What specific improvement? - What is out of scope? - Will any public interface change? If yes: stop — that's a breaking change, not a refactor 3. **Refactor in small steps** — one improvement at a time: - Extract repeated code into functions - Rename for clarity - Break large functions into smaller ones - Remove dead code - Simplify conditionals - Consolidate duplicated logic 4. **Verify behavior unchanged** after each step: - Run existing tests; if they fail, revert and investigate - If no tests: manually verify affected behavior 5. **Update STATE.md.** --- ## Constraints - Never changes behavior — only structure - Never changes public APIs or interfaces - Always works in small verifiable steps - Always warns user when no tests exist --- ## Primary Agent fixer --- ## Definition of Done - [ ] Test status checked before starting - [ ] Refactor scope defined and limited - [ ] No public interfaces changed - [ ] All tests pass after refactoring (or behavior manually verified) - [ ] STATE.md updated ## Output Contract | Field | Value | |-------|-------| | **Artifacts** | Refactored source files (behavior unchanged) | | **State Update** | `.claude/project/STATE.md` — mark task complete, log files modified | | **Handoff Event** | `TASK_COMPLETED` (refactoring complete) |
Related Skills
Supply Chain Audit
Audit the dependency supply chain for security risks beyond what `npm audit` or `pip audit` catches. Analyzes dependency health, maintainer trust signals, typosquatting risk, and transitive dependency exposure.
SEO Audit
Audit web pages for search engine optimization: meta tags, heading hierarchy, structured data, image optimization, mobile-friendliness, and content quality. Complements SKL-0013 (Growth & Distribution) by validating what was built.
Pitch Deck
Create a structured pitch deck outline for investors, stakeholders, or partners. Covers problem, solution, market, traction, team, and ask. Natural output after PRD + Problem Stress Test validation.
Launch Checklist
Pre-launch validation covering everything deployment (SKL-0021) doesn't: analytics, error tracking, social meta, legal pages, email setup, DNS, SSL, and go-live readiness. Produces a launch readiness report with pass/fail checklist. Use this skill before going live on any project.
Insecure Defaults Detection
Detect insecure default configurations, hardcoded credentials, fail-open security patterns, and dangerous default values in application code and configuration files. Complements SKL-0015 (Security Audit) by focusing on configuration-level vulnerabilities that dependency scanners miss.
Differential Security Review
Security-focused review of code changes using git diff analysis. Identifies security implications of recent modifications — new attack surfaces, removed protections, changed auth logic, and risky refactors. Complements SKL-0016 (Code Review) with a security lens on diffs.
Copywriting
Write conversion-focused copy using proven frameworks (AIDA, PAS, BAB). Produces headlines, CTAs, landing page copy, email sequences, and micro-copy. Ensures copy matches brand voice and target audience.
Competitor Analysis
Structured competitor research: features, pricing, positioning, gaps, and differentiation strategy. Feeds into PRD Writing (SKL-0004) and Problem Stress Test (SKL-0027) with better market context.
UX Design
Design user experiences including wireframes, flows, and interaction patterns. Use this skill when UX design work is requested, including onboarding flows and interface layouts.
User Acceptance Testing
Structured QA testing with four modes: diff-aware (auto-scoped to branch changes), full (systematic exploration), quick (30-second smoke test), and regression (compare against baseline). Produces health score, structured reports, and actionable bug lists. Use this skill when UAT is requested or a feature is ready for acceptance testing.
Token Audit
Audit the current project for token waste patterns. Produces a Token Health Report with scored findings and actionable fixes. Use this skill when token usage feels high, sessions are hitting limits, or before optimizing costs.
Test Writing
Write automated tests for existing or new functionality. Use this skill when tests are requested, including unit tests, integration tests, and end-to-end tests.