Skip to main content
skill CX Codex

refactoring-patterns · proffesor-for-testing — Claude Code skill: what it does, how to install

Skill for Claude Code, Codex, Cursor, GitHub Copilot, Gemini CLI and OpenCode that applies refactoring patterns. Runs when you need to improve code structure without changing behavior.

MIT 140 installs ★ 533 updated 2026-10-25

Install into Claude Code · Skills CLI (Vercel) All methods and platforms ↓
npx skills add proffesor-for-testing/agentic-qe --skill refactoring-patterns -a claude-code
Open on GitHub

What refactoring-patterns does

The skill works in cycles: run tests, make one change, run tests again, commit. Built-in code smell table — long method over 20 lines, large class, duplication — maps each smell to a pattern: Extract Method, Extract Class, Replace Loop with Pipeline. For example, nested loops become .filter().map().reduce(), a conditional with more than three clauses becomes a named function. The skill integrates with sub-agents qe-quality-analyzer, qe-test-generator and qe-test-executor: the first detects smells in src/services/, the second adds tests, the third verifies behavior stays unchanged.

Built-in rule of three: first time — write code, second time — tolerate duplication, third time — refactor. Licensed under MIT. Refactoring without tests is forbidden: the skill refuses if npm test fails.

To install in Claude Code, run two commands — npx skills add proffesor-for-testing/agentic-qe --skill refactoring-patterns -a claude-code, the file goes into ~/.claude/skills/refactoring-patterns/SKILL.md. In Cursor — same command with -a cursor flag, file in .cursor/skills/. In GitHub Copilot — gh skill install proffesor-for-testing/agentic-qe refactoring-patterns.

What it helps with

  • split a 50-line function into five short methods
  • replace six function arguments with a parameter object
  • remove code duplication across three places with Extract Method
  • rewrite nested loops as a pipeline with filter and map
  • extract magic numbers into named constants

Example prompts for the agent

  • Find code smells in src/services/ and suggest refactorings
  • Break down the processOrder method into several single-responsibility functions
  • Replace the conditional if (order.total > 1000 && customer.isPremium) with a named function

How to install refactoring-patterns

1Skills CLI (Vercel)

npx skills add proffesor-for-testing/agentic-qe --skill refactoring-patterns -a claude-code

2Manually: put the files in place

~/.claude/skills/refactoring-patterns/SKILL.md

Copy the whole skill folder; for one project use .claude/skills/refactoring-patterns/

Step by step, with commands for each platform: How to install skills in Claude Code: five ways

Questions about refactoring-patterns

How to install refactoring-patterns in Claude Code?

Run npx skills add proffesor-for-testing/agentic-qe --skill refactoring-patterns -a claude-code, the skill file will appear in ~/.claude/skills/refactoring-patterns/SKILL.md.

What does the refactoring-patterns skill do?

Applies refactoring patterns — Extract Method, Replace Loop with Pipeline, Decompose Conditional — in a cycle: tests, change, tests again, commit. Works with sub-agents to detect code smells and verify behavior stays the same.

Can I refactor without tests using this skill?

No. The skill requires npm test to pass before refactoring and after every change. Without green tests, refactoring will not start — this is part of the built-in safety cycle.

Source text

SKILL.md · MIT
---
name: refactoring-patterns
description: "Apply safe refactoring patterns to improve code structure without changing behavior. Use when cleaning up code, reducing technical debt, or improving maintainability."
category: development-practices
priority: medium
tokenEstimate: 1000
agents: [qe-code-reviewer, qe-quality-analyzer, qe-test-refactorer]
implementation_status: optimized
optimization_version: 1.0
last_optimized: 2025-12-03
dependencies: []
quick_reference_card: true
tags: [refactoring, code-quality, technical-debt, maintainability, clean-code]
trust_tier: 2
validation:
  schema_path: schemas/output.json
  validator_path: scripts/validate-config.json
---

# Refactoring Patterns

<default_to_action>
When refactoring:
1. ENSURE tests pass (never refactor without tests)
2. MAKE small change (one refactoring at a time)
3. RUN tests (must stay green)
4. COMMIT (save progress)
5. REPEAT

**Safe Refactoring Cycle:**
```bash
npm test               # Green ✅
# Make ONE small change
npm test               # Still green ✅
git commit -m "refactor: extract calculateTotal"
# Repeat
```

**Code Smells → Refactoring:**
| Smell | Refactoring |
|-------|-------------|
| Long method (>20 lines) | Extract Method |
| Large class | Extract Class |
| Long parameter list (>3) | Introduce Parameter Object |
| Duplicated code | Extract Method/Class |
| Complex conditional | Decompose Conditional |
| Magic numbers | Named Constants |
| Nested loops | Replace Loop with Pipeline |

**NEVER REFACTOR:**
- Without tests (write tests first)
- When deadline is tomorrow
- Code you don't understand
- Code that works and won't be touched
</default_to_action>

## Quick Reference Card

### Common Refactorings

| Pattern | Before | After |
|---------|--------|-------|
| **Extract Method** | 50-line function | 5 small functions |
| **Extract Class** | Class doing 5 things | 5 single-purpose classes |
| **Parameter Object** | `fn(a,b,c,d,e,f)` | `fn(options)` |
| **Replace Conditional** | `if (type === 'a') {...}` | Polymorphism |
| **Pipeline** | Nested loops | `.filter().map().reduce()` |

### The Rule of Three

1. First time → Just do it
2. Second time → Wince and duplicate
3. Third time → **Refactor**

---

## Key Patterns

### Extract Method
```javascript
// Before: Long method
function processOrder(order) {
  // 50 lines of validation, calculation, saving, emailing...
}

// After: Clear responsibilities
function processOrder(order) {
  validateOrder(order);
  const pricing = calculatePricing(order);
  const saved = saveOrder(order, pricing);
  sendConfirmationEmail(saved);
  return saved;
}
```

### Replace Loop with Pipeline
```javascript
// Before
let results = [];
for (let item of items) {
  if (item.inStock) {
    results.push(item.name.toUpperCase());
  }
}

// After
const results = items
  .filter(item => item.inStock)
  .map(item => item.name.toUpperCase());
```

### Decompose Conditional
```javascript
// Before
if (order.total > 1000 && customer.isPremium && allInStock(order)) {
  return 'FREE_SHIPPING';
}

// After
function isEligibleForFreeShipping(order, customer) {
  return isLargeOrder(order) &&
         isPremiumCustomer(customer) &&
         allInStock(order);
}
```

---

## Refactoring Anti-Patterns

| ❌ Anti-Pattern | Problem | ✅ Better |
|-----------------|---------|-----------|
| Without tests | No safety net | Write tests first |
| Big bang | Rewrite everything | Small incremental steps |
| For perfection | Endless tweaking | Good enough, move on |
| Premature abstraction | Pattern not clear yet | Wait for Rule of Three |
| During feature work | Mixed changes | Separate commits |

---

## Agent Integration

```typescript
// Detect code smells
const smells = await Task("Detect Code Smells", {
  source: 'src/services/',
  patterns: ['long-method', 'large-class', 'duplicate-code']
}, "qe-quality-analyzer");

// Safe refactoring with test verification
await Task("Verify Refactoring", {
  beforeCommit: 'abc123',
  afterCommit: 'def456',
  expectSameBehavior: true
}, "qe-test-executor");
```

---

## Agent Coordination Hints

### Memory Namespace
```
aqe/refactoring/
├── smells/*          - Detected code smells
├── suggestions/*     - Refactoring recommendations
├── verifications/*   - Behavior preservation checks
└── history/*         - Refactoring log
```

### Fleet Coordination
```typescript
const refactoringFleet = await FleetManager.coordinate({
  strategy: 'refactoring',
  agents: [
    'qe-quality-analyzer',   // Identify targets
    'qe-test-generator',     // Add safety tests
    'qe-test-executor',      // Verify behavior
    'qe-test-refactorer'     // TDD refactor phase
  ],
  topology: 'sequential'
});
```

---

## Related Skills
- [tdd-london-chicago](../tdd-london-chicago/) - TDD refactor phase
- [code-review-quality](../code-review-quality/) - Review refactored code
- [xp-practices](../xp-practices/) - Collective ownership

---

## Remember

**Refactoring is NOT:**
- Adding features
- Fixing bugs
- Performance optimization
- Rewriting from scratch

**Refactoring IS:**
- Improving structure
- Making code clearer
- Reducing complexity
- Removing duplication
- **Without changing behavior**

**Always have tests. Always take small steps. Always keep tests green.**

© proffesor-for-testing · MIT · proffesor-for-testing/agentic-qe

Similar skills

All skills for Code review and refactoring →

refactoring-patterns by other authors comes first.

refactoring-patterns wondelai refactoring-patterns — a skill that improves code structure through named, behavior-preserving transformations. Use it to eliminate duplication, break apart long methods, or realign responsibilities across classes. CX Codex +1 6,900installs refactoring-expert SuperClaude-Org The refactoring-expert subagent cuts cyclomatic complexity and eliminates technical debt using SOLID principles. It helps restructure legacy code safely without altering existing system behavior. CX Codex ★ 23,950repo stars code-refactoring-tech-debt sickn33 code-refactoring-tech-debt analyzes code and git history to identify technical debt, estimate development drag, and prioritize refactoring tasks with clear trade-offs. CX Codex +1 2installs refactoring-specialist VoltAgent refactoring-specialist delivers low-risk structural refactoring that preserves existing runtime behavior while improving modularity. CX Codex ★ 6,505repo stars ub-mode unclebob The ub-mode skill for Claude Code helps developers structure code changes. It guides the development process by following the principles of "First Make it Work, Then Make it Right, Then Follow Practice." CX Codex +1 930installs technical-debt-manager davila7 technical-debt-manager scans codebases for architecture flaws and test gaps. Helps build a prioritized refactoring plan for sprint planning. CX Codex 857installs oma-refactor First Fluke oma-refactor — a skill for Claude Code and Codex restructures existing code while preserving observable behavior. Executes targeted technical debt cleanup through small test-gated transformations. CX Codex +1 ★ 1,472repo stars

From the same set73

The whole set →
database-testing database-testing is a Claude Code skill for checking database schemas, data integrity, migrations, transactions, and query performance. It applies to data persistence checks and schema changes. CX Codex +1 146installs performance-testing performance-testing is a Claude Code skill for planning load, stress, and soak tests, setting performance targets, and investigating bottlenecks in API and application results. CX Codex +1 144installs qe-test-generation qe-test-generation generates tests for new or changed code, with emphasis on contracts, invariants, and property checks. Use it to fill coverage gaps or move tests between frameworks. CX Codex +1 142installs qe-requirements-validation qe-requirements-validation is a skill that checks acceptance criteria for testability, links requirements to test cases, and generates BDD scenarios from user stories before development. CX Codex +1 141installs chaos-engineering-resilience chaos-engineering-resilience — a skill for injecting controlled failures into distributed systems, verifying recovery mechanisms, and validating resilience. Catches weaknesses before users do. CX Codex +1 138installs localization-testing The localization-testing skill checks translation coverage, locale-specific formats, RTL layouts, and Unicode handling. Use it when adding languages or preparing an international release. CX Codex +1 137installs sherlock-review sherlock-review is a skill for investigating code changes through evidence and deduction. It helps find bug root causes or verify fixes. CX Codex +1 135installs wms-testing-patterns wms-testing-patterns is a Claude Code skill with patterns for testing inventory accuracy, pick waves, EDI documents, and WMS-ERP integration. CX Codex +1 134installs

Project sponsors

Companies that keep this analytics open