Skills code-refactoring
📦

code-refactoring

Safe

Refactor Code with Confidence

This skill helps developers simplify complex code while preserving behavior. It provides step-by-step refactoring patterns like Extract Method, DRY principle, and SOLID design to improve code clarity and reduce technical debt.

Supports: Claude Codex Code(CC)
🥉 72 Bronze
1

Download the skill ZIP

2

Upload in Claude

Go to Settings → Capabilities → Skills → Upload skill

3

Toggle on and start using

Test it

Using "code-refactoring". Refactor this function: function processOrder(order) { /* 100 lines of mixed validation, calculation, inventory check, and order creation */ }

Expected outcome:

## Refactoring Plan

### Original Function: processOrder (100 lines)

### Changes Made:
1. **Extracted validateOrder()** - Handles input validation
2. **Extracted calculateTotal()** - Computes order total with tax and shipping
3. **Extracted checkInventory()** - Validates stock availability
4. **Extracted createOrder()** - Creates the order in database

### New Structure:
```typescript
async function processOrder(order: Order) {
validateOrder(order);
const total = calculateTotal(order);
await checkInventory(order);
return await createOrder(order, total);
}
```

### Behavior Preserved:
- [x] Same validation rules
- [x] Same total calculation
- [x] Same inventory checking
- [x] Same order creation

Using "code-refactoring". These two functions have duplicated logic: getActiveUsers() and getActivePremiumUsers()

Expected outcome:

## Duplication Found

### Before (Duplicated):
```typescript
async function getActiveUsers() {
return await db.user.findMany({
where: { status: 'active', deletedAt: null },
select: { id: true, name: true, email: true }
});
}

async function getActivePremiumUsers() {
return await db.user.findMany({
where: { status: 'active', deletedAt: null, plan: 'premium' },
select: { id: true, name: true, email: true }
});
}
```

### After (DRY):
```typescript
async function getActiveUsers(filter: UserFilter = {}) {
return await db.user.findMany({
where: { status: 'active', deletedAt: null, ...filter },
select: { id: true, name: true, email: true }
});
}

// Usage: getActiveUsers() or getActiveUsers({ plan: 'premium' })
```

Using "code-refactoring". This class violates Single Responsibility. How should I refactor it?

Expected outcome:

## SOLID Analysis

### Original: User class with 3 responsibilities
- Data storage (save to DB)
- Email sending
- Report generation

### Refactored Structure:

| Class | Responsibility |
|-------|----------------|
| User | Data container |
| UserRepository | Database operations |
| EmailService | Communication |
| UserReportGenerator | Reporting |

### Benefits:
- Each class has one reason to change
- Easier to test in isolation
- Flexible to swap implementations
- Better collaboration in teams

Security Audit

Safe
v1 • 3/7/2026

Static analysis flagged 48 potential issues including external_commands, network, filesystem, and cryptographic patterns. Manual review confirms all findings are false positives. The skill is documentation-only (SKILL.md contains code examples for teaching refactoring techniques). No actual shell execution, network requests, filesystem operations, or cryptographic code exists in this skill. Risk level: SAFE.

2
Files scanned
511
Lines analyzed
4
findings
1
Total audits
Medium Risk Issues (1)
False Positive: Ruby/Shell Backtick Execution Detection
Static analyzer flagged 36 instances of 'external_commands' at various SKILL.md lines. These are FALSE POSITIVES - the skill contains TypeScript code examples using template literals (backticks) for teaching refactoring patterns. No actual shell execution occurs.
Low Risk Issues (3)
False Positive: Hardcoded URLs Detection
Static analyzer flagged 3 URLs in SKILL.md. These are FALSE POSITIVES - they are reference links to external books and resources in the documentation section (lines 471-473), not network requests made by the skill.
False Positive: Path Traversal Sequence Detection
Static analyzer flagged 3 path traversal sequences. These are FALSE POSITIVES - the paths '..//code-review/SKILL.md' and '..//backend/testing/SKILL.md' are relative links to related skills in the documentation (lines 483-484).
False Positive: Weak Cryptographic Algorithm Detection
Static analyzer flagged 6 instances of weak cryptographic algorithms. These are FALSE POSITIVES - no cryptographic code or algorithms exist in this skill. The detections appear to be misidentifications of other patterns.
Audited by: claude

Quality Score

38
Architecture
100
Maintainability
87
Content
41
Community
94
Security
91
Spec Compliance

What You Can Build

Simplify Long Functions

A developer has a 200-line function that does too much. Use Extract Method to break it into smaller, focused functions with clear names.

Remove Duplicated Logic

A codebase has the same validation logic repeated in multiple places. Apply DRY principle to extract common logic into reusable functions.

Improve Object-Oriented Design

A class has multiple responsibilities causing tight coupling. Apply SOLID principles to separate concerns into well-defined classes.

Try These Prompts

Basic Refactoring Request
Refactor this function to be more maintainable. Apply the Extract Method pattern to break it into smaller, focused functions:
Remove Duplication
Find and remove duplicated code in this codebase. Apply the DRY principle by extracting common logic into reusable functions:
Apply SOLID Principles
Review this class and suggest how to apply SOLID principles. Identify which principles are violated and how to fix them:
Behavior-Preserving Refactoring
I want to refactor this code. First, help me understand its current behavior (inputs, outputs, side effects). Then propose refactoring changes that preserve behavior, and tell me how to validate the changes:

Best Practices

  • Write tests before refactoring to establish behavior baseline
  • Make small, incremental changes - one refactoring at a time
  • Run tests after each change to verify behavior is preserved
  • Use clear, descriptive names for extracted functions and variables
  • Commit after each successful refactoring for easy rollback

Avoid

  • Refactoring and adding new features simultaneously - separates concerns properly
  • Skipping tests because 'the change is simple' - always verify behavior
  • Creating abstraction layers that add complexity without clear benefit
  • Refactoring code you do not understand - analyze behavior first
  • Ignoring performance implications of abstraction - profile when needed

Frequently Asked Questions

What is Extract Method refactoring?
Extract Method is a technique where you take a long function and break it into smaller, focused functions. Each new function has a clear name that describes what it does. This improves readability and makes code easier to test and maintain.
How do I refactor without breaking functionality?
Always write or run tests before refactoring to establish a baseline. Make small, incremental changes. Run tests after each change. Verify that inputs produce the same outputs before and after refactoring.
When should I apply SOLID principles?
Apply SOLID principles when you notice code that is difficult to change, test, or extend. Look for classes that have too many responsibilities, code that needs modification for multiple reasons, or logic that is hard to test in isolation.
What is the DRY principle?
DRY stands for Do Not Repeat Yourself. It means avoiding duplicated logic in your codebase. When you find repeated code, extract the common logic into a single reusable function or module.
How do I know if my refactoring is complete?
Refactoring is complete when: all tests pass, the code is easier to understand, each function has a single responsibility, there is no duplication, and the code follows consistent patterns.
Can this skill automatically refactor my code?
No, this skill provides guidance, patterns, and examples for manual refactoring. It helps you understand what to do and how to do it safely, but you must apply the changes yourself and verify with tests.

Developer Details

File structure

📄 SKILL.md

📄 SKILL.toon