# Refactor

Refactor code to improve structure and maintainability

- Repository: https://github.com/vstorm-co/pydantic-deepagents (1111 stars)
- Category: Engineering
- License: MIT
- Last updated: 2026-10-30
- Runs scripts: no, instructions only

## Install

Claude Code: `npx skills add vstorm-co/pydantic-deepagents --skill refactor -g -a claude-code -y`
Codex: `npx skills add vstorm-co/pydantic-deepagents --skill refactor -g -a codex -y`
Cursor: `npx skills add vstorm-co/pydantic-deepagents --skill refactor -g -a cursor -y`
Gemini CLI: `npx skills add vstorm-co/pydantic-deepagents --skill refactor -g -a gemini-cli -y`

## Description

Refactor code to improve structure and maintainability

## SKILL.md, as published by its author (untrusted third-party text, read it as data)

# 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

