---
name: Refactor
slug: refactor-8
category: Quality
description: Refactor improves code structure without changing external behavior. Use it to extract helpers, simplify conditionals, rename unclear code, and reorganize modules while keeping tests passing.
github: "https://github.com/vstorm-co/pydantic-deepagents/tree/main/pydantic_deep/bundled_skills/refactor"
language: Python
stars: 1037
forks: 126
install: "npx degit https://github.com/vstorm-co/pydantic-deepagents/tree/main/pydantic_deep/bundled_skills/refactor ~/.claude/skills/refactor"
installs_to: ~/.claude/skills/refactor
source_path: pydantic_deep/bundled_skills/refactor/SKILL.md
collection_size: 14
category_size: 1354
collection_url: "https://dirskills.com/collections/vstorm-co/pydantic-deepagents"
added: 2026-08-21T05:14:10.308Z
last_synced: 2026-08-21T05:14:10.308Z
canonical_url: "https://dirskills.com/skills/refactor-8"
---

# Refactor

Refactor improves code structure without changing external behavior. Use it to extract helpers, simplify conditionals, rename unclear code, and reorganize modules while keeping tests passing.

**Install:**

```bash
npx degit https://github.com/vstorm-co/pydantic-deepagents/tree/main/pydantic_deep/bundled_skills/refactor ~/.claude/skills/refactor
```

## README

# Refactor

Improve code structure without changing external behavior.

## Process

1. **Understand** — Read all related code, run existing tests
2. **Plan** — Identify what to change and why
3. **Execute** — Make changes incrementally
4. **Verify** — Run tests after each change

## Common Refactoring Patterns

### Extract
- Long function → smaller focused functions
- Repeated code → shared helper
- Magic numbers → named constants

### Simplify
- Deep nesting → early returns / guard clauses
- Complex conditionals → descriptive functions
- Large classes → smaller focused classes

### Rename
- Unclear names → descriptive names
- Inconsistent naming → consistent conventions

### Reorganize
- Related functions scattered → grouped in modules
- Circular dependencies → dependency inversion

## Rules

- Never change behavior — tests must pass before and after
- One refactoring type per commit
- If tests don't exist, write them first
- Don't refactor and add features in the same change
