refactor

Restructure code without changing external behavior using contract-first baselines and adversarial subagent review.

1|Updated Sep 11, 2026
One-click install
npx skills add https://github.com/lldwb/lldwb-claude-skills --skill refactor-lldwb
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: refactor
Source: https://github.com/lldwb/lldwb-claude-skills/tree/main/skills/refactor
Command: npx skills add https://github.com/lldwb/lldwb-claude-skills --skill refactor-lldwb

SYSTEM DOCUMENTATION & REQUIREMENTS

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

What problem does it solve? Structural refactoring often introduces silent regressions because there is no proof that external behavior stayed identical. This Skill enforces a disciplined workflow—contract first, test baseline before changes, independent adversarial review, and compile-review-test loops—so every refactoring is verifiable against a frozen list of immutable items. ## Core Features & Use Cases - Contract-First SSOT: Freezes target structure, scope units, immutable items (routes, signatures, return types, annotations), and verification commands into one contract file confirmed by the user before any code changes. - Test Baseline & Contract Snapshots: Builds a rerunnable baseline from existing tests, generated contract-level tests, or a degraded fallback using contract-snapshot.py to diff public signatures, routes, and annotations before and after. - Separation of Change and Review: Modification subagents execute changes while independent read-only subagents perform adversarial method-by-method mapping reviews, with a compile-review-test loop capped at 3 rounds. - Use Case: Extract business logic from 12 Controller classes into a service layer while keeping every route, signature, and response byte-identical, then receive a graded review report and regression test evidence. ## Quick Start Ask the agent to refactor the order module by moving business logic from controllers into a service layer without changing any external behavior.

Frequently Asked Questions about refactor

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

FAQPage Schema
How do I refactor code without changing external behavior?

Define a contract freezing immutable items like routes, method signatures, and return types, then build a rerunnable test baseline before changing code. After changes, run regression tests and diff contract snapshots to prove behavior stayed identical.

How to verify a refactoring did not introduce regressions?

Run the same contract-level tests before and after the change and compare failure sets—equal or smaller means no behavior broke. Additionally diff contract snapshots of public signatures, routes, and annotations to catch silent contract changes.

What is a contract-level test in refactoring?

A contract-level test interacts only through external interfaces like HTTP endpoints or public method signatures, never asserting internal calls or mocking internal dependencies. This keeps tests valid across internal restructuring so they remain a trustworthy baseline.

When should I use refactoring versus code optimization?

Use refactoring for structural changes like layer extraction, module splits, or implementation migration where behavior must stay identical. Use small-scope optimization for readability improvements, duplicate code extraction, or local performance tweaks that do not alter structure.

What happens if a project has no test infrastructure for refactoring?

The workflow degrades to contract snapshots: a Python script mechanically captures public signatures, routes, and annotations before and after, then diffs them. This only guards the contract surface, not behavior, and that limitation must be recorded in the report.