refactoring-code

Refactors code while preserving behavior through a five-phase process.

5|Updated Mar 16, 2019
One-click install
npx skills add https://github.com/third774/dotfiles --skill refactoring-code
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: refactoring-code
Source: https://github.com/third774/dotfiles/tree/main/opencode/skill/refactoring-code
Command: npx skills add https://github.com/third774/dotfiles --skill refactoring-code

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

This Skill outlines a rigorous refactoring methodology to improve code quality while preserving behavior, with the Five-Phase process.

Core Features & Use Cases

  • Five-Phase Process: Understand, Verify, Identify Issues, Plan, Execute & Verify.
  • Behavior Preservation: Tests verify behavior, not implementation.
  • Edge Case Handling: Document edge cases and idempotency.

Quick Start

Start with Phase 1: Understand Current Behavior and proceed through the steps with tests.

Frequently Asked Questions about refactoring-code

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

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

Refactoring preserves behavior by using behavior-driven tests that verify outcomes rather than implementation details. The Five-Phase process—Understand, Verify, Identify Issues, Plan, Execute & Verify—ensures changes improve structure while maintaining observable behavior across your codebase.

What's the best way to reduce code duplication and complexity?

Reduce duplication by identifying reusable patterns and extracting them systematically. The Five-Phase refactoring methodology guides you through understanding current behavior, verifying with tests, planning structural changes, and executing while keeping behavior-driven tests passing to confirm improvements.

When should I refactor versus rewriting code from scratch?

Refactor when you need to improve structure and reduce complexity while preserving existing behavior and functionality. Rewriting discards behavior guarantees. Use refactoring for codebases with duplication and structural issues where behavior-driven tests can verify that changes don't alter observable outcomes.

How do I handle edge cases and idempotency during refactoring?

Document edge cases and idempotency requirements upfront during the Understand phase. Behavior-driven tests across modules verify these cases remain handled correctly after structural changes, ensuring edge case handling and idempotent operations persist through all refactoring phases.

Do I need tests before starting refactoring?

Yes. The Five-Phase process requires a Verify phase with behavior-driven tests before refactoring begins. These tests establish a baseline of expected behavior and serve as verification throughout execution, confirming that structural improvements don't alter observable functionality.