Refactoring Patterns

Systematic refactoring techniques, code smell elimination, pattern extraction, and legacy modernization

492 stars 68 forksSoftware Development

Install

skills CLI (Claude Code, Cursor, Codex and more)
npx skills add cosmicstack-labs/mercury-agent-skills --skill refactoring-patterns
Manual install
git clone --depth 1 https://github.com/cosmicstack-labs/mercury-agent-skills.git /tmp/mercury-agent-skills
mkdir -p ~/.claude/skills
cp -r /tmp/mercury-agent-skills/categories/development/refactoring-patterns ~/.claude/skills/refactoring-patterns

Personal skills live in ~/.claude/skills. Use .claude/skills in a project folder to share a skill with your team.

From the SKILL.md

# Refactoring Patterns

Systematically improve code without changing its behavior.

## The Refactoring Workflow

1. **Identify** a code smell or pain point
2. **Ensure** you have tests (write them first if not)
3. **Apply** one refactoring at a time
4. **Test** after each change (green = continue, red = revert)
5. **Commit** — small, focused, descriptive
6. **Repeat**

## Extract Method
**When**: A method does multiple things or is too long.
**How**: Find a cohesive block → extract to new method → call it.

```javascript
// Before
function processOrder(order) {
  const total = order.items.reduce((sum, i) => sum + i.price, 0);
  const tax = total * 0.08;
  const discount = order.coupon ? total * 0.1 : 0;
  return total + tax - discount;
}

// After
function processOrder(order) {
  const subtotal = calculateSubtotal(order);
  const tax = calculateTax(subtotal);
  const discount = calculateDiscount(order, subtotal);
  return subtotal + tax - discount;
}
```

## Replace Conditional with Polymorphism
**When**: Switch/if-else chains based on type grow too long.

```javascript
// Before
function calculateShipping(order) {
  if (order.type === 'standard') return order.weight * 0.5;
  if (order.type === 'express') return order.weight * 1.5 + 5;
  if (order.type === 'overnight') return order.weight * 3 + 15;
}

// After
class StandardShipping {
  calculate(weight) { return weight * 0.5; }
}
class ExpressShipping {
  calculate(weight) { return weight * 1.5 + 5; }
}
```
Read the full skill on GitHub

Details

Skill name
refactoring-patterns
Path
categories/development/refactoring-patterns/SKILL.md
License
MIT
Repo updated
25 August 2026

FAQ

What does the Refactoring Patterns skill do?

Systematic refactoring techniques, code smell elimination, pattern extraction, and legacy modernization

How do I install the Refactoring Patterns skill?

skills CLI (Claude Code, Cursor, Codex and more): npx skills add cosmicstack-labs/mercury-agent-skills --skill refactoring-patterns. Skills go in ~/.claude/skills (personal) or .claude/skills (project), and Claude loads them automatically when a task matches the description.

Is Refactoring Patterns popular?

It lives in cosmicstack-labs/mercury-agent-skills, which has 492 GitHub stars and 68 forks.

Related skills

Accessibility

492

cosmicstack-labs/mercury-agent-skills

Achieve and maintain WCAG compliance through inclusive design practices, proper ARIA usage, and comprehensive testing methodologies.

Frontend & Design68

Accessibility Testing

492

cosmicstack-labs/mercury-agent-skills

WCAG 2.1/2.2 audit, axe, Lighthouse, manual testing, screen reader testing, and remediation

Testing & QA68

Agent Audit Logging

492

cosmicstack-labs/mercury-agent-skills

Implement comprehensive audit logging and reporting for multi-agent systems. Covers event capture, structured logging, traceability, compliance reporting, forensic analysis, and real-time monitoring dashboards for agent actions and decisions.

AI, LLMs & Agents68

Secure Coding

492

cosmicstack-labs/mercury-agent-skills

Comprehensive secure coding practices covering input validation, authentication, authorization, cryptography, secrets management, and error handling. Provides actionable code examples and checklists for building security into every stage of development.

Software Development68

Readwise CLI

329

readwiseio/readwise-skills

How to use the Readwise CLI — access highlights, documents, and your entire reading library from the command line

Software Development14

Time Blocking Scheduler

492

cosmicstack-labs/mercury-agent-skills

A structured time management coach that designs deep work schedules, energy-aligned routines, and priority-focused blocks for freelancers, solopreneurs, and creative professionals who need to protect their focus from the chaos of unstructured days.

Software Development68

Browse the most popular Claude skills, all software development skills, or write your own with the skills generator.