refactor

Diagnose codebase anti-patterns, propose architectural targets, and execute test-backed migrations.

Updated Aug 27, 2026
One-click install
npx skills add https://github.com/Pyl-Tech/stream-coding --skill refactor-pyl-tech
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: refactor
Source: https://github.com/Pyl-Tech/stream-coding/tree/main/.agents/skills/refactor
Command: npx skills add https://github.com/Pyl-Tech/stream-coding --skill refactor-pyl-tech

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill includes references (resource) components.

What problem does it solve?

This Skill helps you refactor an existing codebase when the architecture feels tangled or outdated, so you can extract modules, invert dependencies, and migrate to a healthier structure without breaking behavior.

Core Features & Use Cases

  • Diagnose structural issues first: produces a DIAGNOSE REPORT with named anti-patterns, hotspots, and a clear structural root cause before proposing changes.
  • Choose an explicit architectural target: proposes 2–3 concrete refactoring targets (patterns, boundaries, dependency direction) and requires user confirmation via a refactoring gate.
  • Execute atomic, test-backed migrations: creates a MIGRATION PLAN of small steps with TDD/testing requirements, runs tests and build per step, and updates the spec to prevent drift.
  • Differentiate refactoring from cleanup: focuses on architectural redesign (not dead-code removal) and can also improve outcomes after reverse-spec.

Quick Start

Tell your AI agent to “Use /refactor to redesign my codebase architecture: diagnose the current anti-patterns, propose a target with an ADR, request my confirmation, then produce an atomic migration plan with tests before moving any code.”

Frequently Asked Questions about refactor

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

FAQPage Schema
How do I refactor messy code to reduce coupling and improve testability?

To refactor messy code and reduce coupling, you extract modules, invert dependencies, and migrate to a healthier architectural structure. This process uses a diagnose, target, plan, and execute workflow to prevent behavior regressions while improving testability.

What is the best way to restructure code architecture without breaking existing behavior?

The best way to restructure code architecture without breaking behavior is using a test-driven migration plan. You execute atomic steps with TDD requirements, running tests and builds after each step while updating specifications to prevent spec drift and regressions.

How do I diagnose structural anti-patterns before migrating to a clean architecture?

You diagnose structural anti-patterns by generating a diagnose report that names anti-patterns, identifies hotspots, and determines a clear structural root cause. This diagnosis happen before proposing concrete refactoring targets and architectural boundaries.

Can I use dependency inversion and module extraction for architectural redesign?

Yes, dependency inversion and module extraction are core techniques for architectural redesign. They allow you to invert dependency directions and extract modules to untangle outdated codebases, differentiating structural refactoring from simple dead-code removal.

Does refactoring with an ADR and confirmation gate prevent spec drift?

Yes, using an architecture decision record and a confirmation gate prevents spec drift by requiring explicit user agreement on proposed targets before execution. This ensures all atomic migration steps align with the confirmed architectural boundaries.

When should I not use an architectural refactoring workflow for my codebase?

You should not use an architectural refactoring workflow for simple dead-code removal or minor cleanup. This process focuses on structural redesign, dependency inversion, and module extraction rather than routine maintenance tasks.