refactor

Generate characterization tests before refactoring code files or modules.

24|3|Updated Feb 22, 2026
One-click install
npx skills add https://github.com/Borda/.home --skill refactor-borda
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: refactor
Source: https://github.com/Borda/.home/tree/main/.claude/skills/refactor
Command: npx skills add https://github.com/Borda/.home --skill refactor-borda

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill includes scripts (resource) and references (resource) components.

What problem does it solve?

This Skill ensures code safety and stability during refactoring by enforcing a test-first approach, preventing regressions and improving code quality.

Core Features & Use Cases

  • Test Coverage Audit: Automatically checks for existing tests and generates characterization tests if coverage is insufficient.
  • Safe Refactoring: Applies code changes incrementally, verifying each step with the test suite.
  • Use Case: You have a complex Python module that needs to be optimized for performance. Use this Skill to ensure all its current behaviors are documented with tests before you start optimizing, and then refactor with confidence.

Quick Start

Use the refactor skill to improve the code quality of the file 'src/utils.py' with the goal of simplifying error handling.

Frequently Asked Questions about refactor

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

FAQPage Schema
How do I safely refactor Python code without causing regressions?

Test-first refactoring prevents regressions by auditing existing test coverage and generating characterization tests for uncovered logic before applying any structural or API improvements to your code.

What is the best way to improve code quality in a complex Python module?

Improving code quality in a complex Python module is best handled by enforcing a test-first refactoring workflow, which documents all current behaviors with characterization tests first, and then incrementally applies logic improvements while verifying each step against the test suite.

How do I generate characterization tests for uncovered code before refactoring?

You generate characterization tests for uncovered code by running an automated test coverage audit that identifies missing tests and creates them to document current input/output behaviors, ensuring a safe baseline before any logic changes are applied.

Can I refactor multiple files or an entire directory at once using a test-first approach?

Yes, test-first refactoring can orchestrate code improvements across single files, entire directories, or modules by systematically ensuring test coverage exists and verifying consistency across all targeted code before applying structural changes.

Do I need existing test coverage to start refactoring?

You do not need existing test coverage to start refactoring, because this approach automatically checks for tests and generates characterization tests for uncovered code to establish a behavioral baseline before applying any logic improvements.