legacy-refactoring-strategy
Skill0 starsChanged 5 months agoMITView on GitHub
Plans safe, incremental refactors of legacy or poorly-tested systems without halting delivery. Use when untangling a big ball of mud, breaking up a monolith, removing a deprecated dependency, or when changes keep causing regressions in code no one fully understands.
We split this skill into the rules it gives an agent
3 rules. About 0 are common, 3 are distinctive, and 0 are very specific to this project.
≈0
Common · estimate
Many files like this have a rule of this kind.
≈3
Distinctive · estimate
This author's own choices. Worth a look.
0
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Distinctive: line 18
Never refactor and change behavior in the same commit.
- Distinctive: line 19
Prefer strangler fig: route a slice of traffic/calls through the new path, expand coverage, delete the old path last.
- Distinctive: line 20
Use branch by abstraction for in-process dependencies you can't replace atomically: introduce an abstraction, build the new impl behind it, …
≈ “Common” is an estimate: at least 1 in 5 of the 308,232 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
Legacy Refactoring Strategy
You cannot refactor what you cannot characterize. Legacy code is code without a behavioral spec; the first job is to discover the spec, not improve the code.
Establish ground truth before touching anything
- Characterization tests: pin current behavior (including bugs) with tests at the highest stable seam available. These are a regression net, not correctness assertions.
- Seam map: find the points where you can intercept behavior (interfaces, function boundaries, network calls) without editing tangled internals.
- Blast radius: trace what depends on the target. Static refs lie under reflection, config-driven dispatch, and serialization — grep is necessary but not sufficient.
Sequencing: make the change easy, then make the easy change
- Never refactor and change behavior in the same commit. Separate "structure-only, behavior-identical" steps from "behavior change" steps so review and
git bisectstay meaningful. - Prefer strangler fig: route a slice of traffic/calls through the new path, expand coverage, delete the old path last.
- Use branch by abstraction for in-process dependencies you can't replace atomically: introduce an abstraction, build the new impl behind it, flip, remove.
Adversarial validation
- What behavior do callers depend on that isn't in the spec — undocumented ordering, timing, error text, log lines parsed downstream, side effects on shared state?
- What happens at the cutover boundary when old and new code run concurrently on the same data?
- Does the "dead" code path actually run? Add telemetry before deleting; "obviously unused" code often has a quarterly cron caller.
- Can you roll back instantly if the new path misbehaves in production, or is the migration one-way?
Non-obvious risks
- The bug-for-bug behavior may be load-bearing: downstream systems may rely on the legacy quirk. Preserve it explicitly or migrate consumers first.
- Improving error handling can change which errors surface, breaking callers that swallowed specific failures.
- Performance characteristics are part of the contract; a "cleaner" abstraction that adds allocations or N+1 queries is a regression.
Output structure
Deliver: a dependency/seam map, the characterization-test plan, an ordered sequence of behavior-preserving steps each independently shippable and reversible, the cutover/rollback mechanism, and the telemetry that proves old paths are dead before deletion.
In this repository29 other files it gives its agents.
- adversarial-code-reviewSkill
- api-contract-designSkill
- attack-surface-mappingSkill
- authn-authz-design-reviewSkill
- benchmark-designSkill
- capacity-scalability-planningSkill
- concurrency-race-analysisSkill
- data-consistency-modelingSkill
- data-exfiltration-analysisSkill
- distributed-consensus-designSkill
- error-handling-architectureSkill
- event-driven-architectureSkill
- experiment-designSkill
- hypothesis-falsificationSkill
- incident-rca-postmortemSkill
- literature-synthesisSkill
- metrics-designSkill
- multi-layer-caching-strategySkill
- mvp-scope-cuttingSkill
- performance-profilingSkill
- rate-limiting-designSkill
- requirements-disambiguationSkill
- secrets-management-auditSkill
- statistical-validity-analysisSkill
- supply-chain-risk-analysisSkill
- system-decomposition-synthesisSkill
- threat-modelingSkill
- tradeoff-decision-frameworkSkill
- user-failure-mode-mappingSkill
Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
Reviews can't be read right now.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

