refactor

Refactor code files while preserving behavior and keeping tests green.

Updated Mar 12, 2026
One-click install
npx skills add https://github.com/ps-carvalho/spavn-agents --skill refactor-ps-carvalho
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: refactor
Source: https://github.com/ps-carvalho/spavn-agents/tree/main/.opencode/skills/refactor
Command: npx skills add https://github.com/ps-carvalho/spavn-agents --skill refactor-ps-carvalho

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill includes references (resource) components.

What problem does it solve?

This Skill addresses the challenge of improving code structure and maintainability without introducing regressions or altering its external behavior.

Core Features & Use Cases

  • Behavior-Preserving Refactoring: Applies transformations like renaming variables, extracting methods, or simplifying logic while ensuring existing functionality remains intact.
  • Test-Driven Refactoring: Integrates with build and test commands to verify code integrity after each refactoring step.
  • Use Case: Refactor a complex function into smaller, more manageable units to improve readability and testability, ensuring all unit tests continue to pass.

Quick Start

Use the refactor skill to improve the structure of the utils.py file.

Frequently Asked Questions about refactor

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I refactor code without breaking existing functionality?

Safe code refactoring requires behavior-preserving transformations guided by a robust testing suite, running build and test commands before and after changes to ensure all tests remain green.

What is behavior-preserving refactoring and when do I need it?

Behavior-preserving refactoring improves code structure and maintainability through transformations like extracting methods or renaming variables without altering external behavior or introducing regressions.

Can I refactor a complex function into smaller units if I have existing unit tests?

Yes, test-driven refactoring uses your existing testing suite and build commands to verify code integrity after each step, ensuring unit tests continue to pass when simplifying complex logic.

Do I need design pattern analysis tools to improve code maintainability?

Integrating design pattern and code quality analysis tools guides refactoring transformations, helping you apply structural improvements that enhance readability and long-term maintainability.

What's the best way to ensure tests stay green during code refactoring?

Run pre- and post-refactoring verification using your build commands and testing suite, checking that all tests remain green throughout each behavior-preserving transformation step.

What are the limitations of test-driven refactoring for software development?

Test-driven refactoring requires a robust testing suite and build commands to function, meaning it cannot safely verify behavior-preserving transformations if adequate test coverage is absent.