refactor-phase

Refactor Python code by removing dead code and verifying tests remain green.

Updated Aug 23, 2026
One-click install
npx skills add https://github.com/foolishimp/ai_sdlc_method --skill refactor-phase
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: refactor-phase
Source: https://github.com/foolishimp/ai_sdlc_method/tree/main/plugins/code-skills/skills/tdd/refactor-phase
Command: npx skills add https://github.com/foolishimp/ai_sdlc_method --skill refactor-phase

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

After making tests pass in TDD's GREEN phase, code often needs quality improvements and technical debt removal before being production-ready, a step frequently skipped or done poorly.

Core Features & Use Cases

  • Automated Refactoring: Improves code quality (type hints, naming, docstrings) and simplifies complex logic.
  • Tech Debt Pruning: Actively deletes unused imports, removes dead code, and eliminates commented-out blocks, enforcing "No Legacy Baggage."
  • Safety Checks: Runs all tests after each change, with automatic rollback on failure, ensuring code remains functional and stable.
  • Use Case: After implementing a feature and making tests pass, invoke this skill to automatically clean up the code, remove any unused elements, simplify complex parts, and ensure all tests still pass before committing.

Quick Start

Refactor the 'login()' function in 'src/auth/login.py' to improve code quality and remove any detected technical debt, verifying tests pass.

Frequently Asked Questions about refactor-phase

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

FAQPage Schema
How do I remove technical debt and clean up code after tests pass?

Technical debt removal during the refactor phase involves eliminating unused imports, deleting dead code and comments, simplifying complex logic, and adding type hints and docstrings. This skill automates those improvements for Python codebases in TDD workflows, running tests after each change to ensure nothing breaks before you commit.

What's the best way to refactor Python code while keeping tests green?

Refactoring with test safety means making quality improvements—extracting shared functionality, improving naming, adding documentation—while automatically running all tests after each change. If any test fails, changes rollback immediately, ensuring your code remains functional throughout the refactor phase.

Can I automate removal of unused imports and dead code in Python?

Yes, automated refactoring removes unused imports, commented-out blocks, and unreachable code from Python files while verifying all tests still pass. This eliminates manual review overhead and enforces consistent code hygiene across your codebase before committing.

When should I refactor code in the TDD workflow?

Refactoring happens in TDD's REFACTOR phase, after tests are green. This is when you clean up implementation details, remove duplication, simplify complex sections, and eliminate baggage without changing behavior—preparing code for production before the next cycle begins.

Does this work for large Python codebases with many test dependencies?

This skill applies to Python codebases of any size within TDD workflows. It runs your full test suite after each refactoring change, so it scales to projects with extensive test coverage and dependencies, automatically rolling back if tests fail.