You need to change or refactor code with little or no test coverage
The code is hard to understand, risky, or tightly coupled
You want to add tests to legacy code safely
You need to introduce seams for dependency injection or testability
Rescue Approach
Characterization Tests: Write tests that capture current behavior before changing anything.
Introduce Seams: Add interfaces, delegates, or factories to break dependencies and enable testing.
Peel and Slicing Technique: Gradually peel away or slice off small, testable pieces of logic from the legacy code. Move these into new, well-tested methods or classes, leaving the original code smaller and easier to understand. Repeat until the legacy code is fully replaced or manageable.
Incremental Refactoring: Make one small, safe change at a time; verify tests after each.
Safe Commits: Commit after every passing test and refactor step.
Risk Management: Avoid large rewrites; prefer gradual improvement.
Rescue Patterns
Characterization Test Example:
[Fact]
public void ShouldBehaveAsBefore_WhenInputIsX()
{
// Arrange: set up legacy object
// Act: call legacy method
// Assert: verify current (even if odd) behavior
}
Seam Introduction: Use interfaces or delegates to inject dependencies.
Peel and Slicing Example: Identify a small, self-contained piece of logic in a large method. Extract it into a new method or class, write tests for it, and replace the original code with a call to the new method. Repeat this process to gradually reduce legacy complexity.
Sprout Method/Class: Add new code alongside old, then migrate usage.
Wrap & Delegate: Use adapter or wrapper to intercept and test legacy logic.
Example Prompts
"/legacy-code-rescue [file.cs] Add characterization tests before refactoring."
"/legacy-code-rescue [method] How do I introduce a seam for DI?"
"/legacy-code-rescue [class] What’s the safest way to start refactoring?"
Update as new rescue patterns or project-specific strategies emerge.
Ensure examples and checklists match current best practices.
Converted and distributed by TomeVault — claim your Tome and manage your conversions.
1---2name: jason-kerney-workmood-legacy-code-rescue3description: Legacy Code Rescue Skill4---56# Legacy Code Rescue Skill78## When to Use This Skill910Use this skill when:11- You need to change or refactor code with little or no test coverage12- The code is hard to understand, risky, or tightly coupled13- You want to add tests to legacy code safely14- You need to introduce seams for dependency injection or testability1516---171819## Rescue Approach2021- **Characterization Tests**: Write tests that capture current behavior before changing anything.22- **Introduce Seams**: Add interfaces, delegates, or factories to break dependencies and enable testing.23- **Peel and Slicing Technique**: Gradually peel away or slice off small, testable pieces of logic from the legacy code. Move these into new, well-tested methods or classes, leaving the original code smaller and easier to understand. Repeat until the legacy code is fully replaced or manageable.24- **Incremental Refactoring**: Make one small, safe change at a time; verify tests after each.25- **Safe Commits**: Commit after every passing test and refactor step.26- **Risk Management**: Avoid large rewrites; prefer gradual improvement.2728---293031## Rescue Patterns3233- **Characterization Test Example**:34 ```csharp35 [Fact]36 public void ShouldBehaveAsBefore_WhenInputIsX()37 {38 // Arrange: set up legacy object39 // Act: call legacy method40 // Assert: verify current (even if odd) behavior41 }42 ```43- **Seam Introduction**: Use interfaces or delegates to inject dependencies.44- **Peel and Slicing Example**: Identify a small, self-contained piece of logic in a large method. Extract it into a new method or class, write tests for it, and replace the original code with a call to the new method. Repeat this process to gradually reduce legacy complexity.45- **Sprout Method/Class**: Add new code alongside old, then migrate usage.46- **Wrap & Delegate**: Use adapter or wrapper to intercept and test legacy logic.4748---4950## Example Prompts5152- "/legacy-code-rescue [file.cs] Add characterization tests before refactoring."53- "/legacy-code-rescue [method] How do I introduce a seam for DI?"54- "/legacy-code-rescue [class] What’s the safest way to start refactoring?"5556---5758## Verification Steps5960- Build: `dotnet build --framework net9.0-windows10.0.19041.0`61- Test: `dotnet test` (ensure new and old behavior is covered)62- Commit: After every passing test and refactor step6364---6566## Resources6768- [Refactoring Skill](../refactoring/SKILL.md)69- [TDD Skill](../tdd/SKILL.md)70- [Code Smells Detection](../code-smells-detection/SKILL.md)71- [Working Effectively with Legacy Code (Feathers)](https://www.goodreads.com/book/show/44919.Working_Effectively_with_Legacy_Code)7273---7475## Maintenance7677- Update as new rescue patterns or project-specific strategies emerge.78- Ensure examples and checklists match current best practices.7980---81> Converted and distributed by [TomeVault](https://tomevault.io/claim/jason-kerney) — claim your Tome and manage your conversions.82<!-- tomevault:4.0:skill_md:2026-04-15 -->
Run npx skillmds@latest add tomevault-io/jason-kerney-workmood-legacy-code-rescue in your terminal (requires Node.js), paste this page's agent-chat prompt into Claude, Cursor, or any MCP-connected agent, or download the SKILL.md file and copy it into your agent's skills directory.
Legacy Code Rescue Skill It is listed under Coding & Dev Tools on SkillMD.
This skill has not completed SkillMD's automated safety review yet. Independent scanners report: SkillSpector: CAUTION, Skill Scanner: PASS. SkillMD never runs a skill's scripts for you; review the SKILL.md before installing.
This skill is tagged as working with Claude Code, Claude.ai, OpenAI Codex. SKILL.md is an open format, so most agents that read a skills directory can load it too.
Yes. Installing skills from SkillMD is free, and the skill stays under its author's original license.
tomevault-io (@tomevault-io) published this skill. Their other Agent Skills are listed on their SkillMD profile.