book-legacy-code
Skill0 starsChanged 4 months agoApache-2.0View on GitHub
Working Effectively with Legacy Code techniques (characterization tests, breaking dependencies, seams) to consult when changing untested legacy code. Reference material, not a review. Use when the user asks how to safely modify legacy code or add tests around it.
In this repository11 other files it gives its agents.
- CLAUDE.mdCLAUDE.md
- commit-conventionSkill
- pr-conventionSkill
- repo-setupSkill
- architecture-reviewSkill
- code-styleSkill
- comment-reviewSkill
- review-gateSkill
- book-clean-architectureSkill
- book-philosophy-of-software-designSkill
- book-refactoringSkill
The file
Show its rules and text
We split this skill into the rules it gives an agent
18 rules. About 0 are common, 17 are distinctive, and 1 is very specific to this project.
≈0
Common · estimate
Many files like this have a rule of this kind.
≈17
Distinctive · estimate
This author's own choices. Worth a look.
1
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Distinctive: line 14
Use when changing code that is expensive to change safely because behavior is unclear, tests are weak or missing, dependencies are hidden, …
- Distinctive: line 22
Treat any area without trustworthy tests as legacy code.
- Distinctive: line 23
Before editing, state the requested behavior change and the current behavior that must remain.
- Distinctive: line 24
Follow the legacy loop: identify the change point, check existing protection, add characterization where possible, find or create a seam, …
- Distinctive: line 25
Prefer fast, focused tests around the slice being changed.
- Distinctive: line 27
Use the smallest seam that allows substitution, observation, or interception.
- Distinctive: line 29
Keep behavior changes, structural refactorings, and cleanup separate.
- Distinctive: line 30
When direct edits are risky, add behavior with sprout method, sprout class, wrap method, wrap class, or extract-and-override style moves, …
- Distinctive: line 32
Use dependency-breaking techniques according to the actual barrier: adapt narrow parameters, extract interfaces or implementers, …
- Distinctive: line 36
Leave the touched area easier to understand, test, or change.
- Distinctive: line 40
When behavior is uncertain, consumers may rely on ugly behavior, or a branch/path is hard to prove, add characterization or another …
- Distinctive: line 41
When tests require too much setup or a class cannot be instantiated cheaply, break the first real barrier: constructor work, hidden …
- Distinctive: line 42
When time, randomness, environment, thread-local state, current user/request, files, network, process exits, database writes, messages, or …
- Distinctive: line 43
When a large method or class defeats local reasoning, sketch effects, find interception or pinch points, extract pure computation first, …
- Very specific: line 44
When changing database-heavy, UI, framework, or API-boundary code, separate policy from query/mapping/persistence, handlers/callbacks, …
- Distinctive: line 45
When a seam is magical, temporary, public-for-test, subclass-only, link/preprocessor-based, or probe/sensing-variable-based, add a cleanup …
- Distinctive: line 46
When repeated edits cluster across several places, remove duplication incrementally under tests instead of launching a broad redesign.
- Distinctive: line 47
When rewrite or heroic cleanup feels tempting, choose the smallest sprout, wrap, seam, characterization, or refactoring step that makes …
≈ “Common” is an estimate: at least 1 in 5 of the 213,895 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
<!-- Vendored verbatim from ciembor/agent-rules-books (MIT License).
Source: https://github.com/ciembor/agent-rules-books/blob/main/working-effectively-with-legacy-code/working-effectively-with-legacy-code.mini.md
Third-party reference. Exempt from repo diction and prettier. -->OBEY Working Effectively with Legacy Code by Michael Feathers
When to use
Use when changing code that is expensive to change safely because behavior is unclear, tests are weak or missing, dependencies are hidden, or runtime/framework setup blocks local feedback.
Primary bias to correct
Gain control before improving design. Understand current behavior, protect what must stay, create the smallest useful seam, break the dependency that blocks feedback, make the requested change, then leave the area more testable.
Decision rules
- Treat any area without trustworthy tests as legacy code; do not start with rewrite or module-wide cleanup unless that is explicitly required or clearly safer.
- Before editing, state the requested behavior change and the current behavior that must remain; characterize uncertain or suspicious behavior instead of silently fixing it.
- Follow the legacy loop: identify the change point, check existing protection, add characterization where possible, find or create a seam, break the blocking dependency, change behavior, then refactor locally.
- Prefer fast, focused tests around the slice being changed; use broader interception or integration tests only when they are the safest first observation point.
- Choose test points by tracing effects outward from the change point through values, calls, fields, outputs, collaborators, interception points, and pinch points.
- Use the smallest seam that allows substitution, observation, or interception; make clear whether the seam is for sensing, separation, or both.
- Break dependencies deliberately: expose hidden inputs, hard outputs, hard construction, globals, statics, ambient context, and framework callbacks only where they block testing or safe change.
- Keep behavior changes, structural refactorings, and cleanup separate; verify small steps and avoid checking in exploratory restructuring used only for understanding.
- When direct edits are risky, add behavior with sprout method, sprout class, wrap method, wrap class, or extract-and-override style moves, then fold the temporary structure into better design when tests support it.
- For hard-to-test methods, split construction from use, extract side effects behind collaborators, carve pure computation first, and isolate policy from runtime, persistence, UI, or framework mechanisms.
- Use dependency-breaking techniques according to the actual barrier: adapt narrow parameters, extract interfaces or implementers, parameterize constructors or methods, encapsulate globals, introduce instance delegators, override factories/calls, or use link/preprocessing seams only when ordinary object seams are impractical.
- In large code, sketch effects and group responsibilities before moving behavior; let excessive setup, impossible observation, and repeated changes point to smaller extracted responsibilities.
- During review, treat no tests around modified logic, mixed structural and behavioral edits, broad edits in poorly understood modules, hard-coded collaborators, global/static reach-through, constructor side effects, and business logic trapped in framework entry points as legacy-change risks.
- Reject changes that expand hidden dependencies, mock around untestable structure without improving it, rename or format while leaving the real dependency knots intact, or introduce large architecture before basic seams exist.
- Leave the touched area easier to understand, test, or change; do not mistake test-only seams, wrappers, subclass tricks, or build tricks for design improvement by themselves.
Trigger rules
- When behavior is uncertain, consumers may rely on ugly behavior, or a branch/path is hard to prove, add characterization or another explicit observation path before changing semantics.
- When tests require too much setup or a class cannot be instantiated cheaply, break the first real barrier: constructor work, hidden allocation, factory call, global state, static construction, framework object, or hard parameter.
- When time, randomness, environment, thread-local state, current user/request, files, network, process exits, database writes, messages, or control-flow logging block repeatable tests, wrap or inject that boundary.
- When a large method or class defeats local reasoning, sketch effects, find interception or pinch points, extract pure computation first, and avoid editing many branches at once.
- When changing database-heavy, UI, framework, or API-boundary code, separate policy from query/mapping/persistence, handlers/callbacks, adapters, and runtime setup; keep real-boundary integration tests where they matter.
- When a seam is magical, temporary, public-for-test, subclass-only, link/preprocessor-based, or probe/sensing-variable-based, add a cleanup obligation and remove it once safer structure exists.
- When repeated edits cluster across several places, remove duplication incrementally under tests instead of launching a broad redesign.
- When rewrite or heroic cleanup feels tempting, choose the smallest sprout, wrap, seam, characterization, or refactoring step that makes today's requested change safer.
Final checklist
- Untested or weakly tested area treated as legacy risk?
- Behavior delta and behavior-to-preserve stated?
- Uncertain current behavior characterized or explicitly observed?
- Tests close enough and fast enough to diagnose the change?
- Smallest useful seam chosen, with sensing vs separation clear?
- Blocking dependency reduced without expanding hidden dependencies?
- Behavior change, refactoring, and cleanup kept separate?
- Temporary seam or dependency-breaking trick has a cleanup path?
- Touched area is more understandable, testable, or changeable?
Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
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.

