refactor
This Claude Code skill restructures existing code to enhance clarity and maintainability while preserving its external behavior. Use it when codebase readability has degraded through accumulated changes, when extracting repeated logic into reusable functions, when simplifying complex conditionals or deeply nested structures, or when renaming variables for consistency. The skill enforces test-driven refactoring by requiring tests to pass before and after modifications, preventing behavioral changes during restructuring.
git clone --depth 1 https://github.com/vstorm-co/pydantic-deepagents /tmp/refactor && cp -r /tmp/refactor/pydantic_deep/bundled_skills/refactor ~/.claude/skills/refactorSKILL.md
# 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
Building, compiling, and resolving dependency issues across languages
Systematic code review for bugs, security, style, and performance
Working with diverse data formats: binary, text, structured, and custom
Systematic exploration of unknown environments before starting work
Git operations: commits, branches, PRs, and conflict resolution
Writing efficient code that handles large data and tight constraints
Create new reusable skills from conversation context
Systematic approach to diagnosing and fixing errors