What does this skill do?

The Safe Code Refactoring Skill orchestrates code restructuring by improving its internal structure without altering its external behavior. It verifies that existing tests pass, plans the changes in incremental steps, executes the refactoring with continuous test coverage, and confirms a commit with the prefix refactor:, whose diff is strictly neutral with respect to behavior.

Removing Modules
Isolate HTTP clients, databases, or business logic into separate components without breaking the system.
Removing Dead Code
Eliminate duplication, unused dependencies, and dead code using tools such as knip or depcheck.
Renaming and Clarity
Reduce nesting and rename variables or functions to improve code readability.
Architectural Improvement
Restructure the overall architecture without introducing new features, ensuring complete security.

Usage examples

📦 HTTP Client Extraction
Extract the NWS HTTP client from poller.py while keeping the tests passing, and confirm the commit with the prefix "refactor":
🧹 Cleaning of facilities
Remove dead code and unused dependencies in the payments module using knip and depcheck
✏️ Reduce nesting
Refactor the `processOrder` function to reduce nesting and rename ambiguous variables
🏗️ Isolate business logic
Isolate the tax calculation logic into a separate component without altering the system's behavior

Features

Preliminary Test Verification Confirm that the tests exist and are passing before touching the code; add unit tests if the coverage is low.
Control Gates It pauses execution at Gate 1 (planning) and Gate 2 (pre-commit), awaiting explicit validation from the user.
Incremental refactoring Make changes in small steps, running the tests after each modification to ensure they still pass.
Guaranteed neutral commit The final commit with the prefix "refactor:" contains a diff that is strictly neutral with respect to the system's behavior.
Delegation to Specialized Agents You can delegate specific tasks, such as cleaning up dependencies, to tools like refactor-cleaner (knip / depcheck).

Frequently asked questions

The skill detects whether coverage is low and suggests adding characterization tests first before proceeding with the refactoring.
At two checkpoints: Gate 1 to approve the refactoring plan and Gate 2 to confirm the commit before executing it.
No. The resulting diff must be strictly neutral in terms of behavior; the commit is prefixed with "refactor:".
Yes. The skill can delegate tasks to agents such as "refactor-cleaner," which use tools like "knip" or "depcheck" to perform safe removals.
Secure Code Refactoring — Safe Restructuring with Claude AI

¿Prefieres escuchar el contenido? Genera la narración de audio con un clic.