changing-legacy-code
Skill1 starsChanged 13 days agoMITView on GitHub
Use when modifying existing code that has few or no tests, unclear behavior, old dependencies or tangled structure, or code written before agentic development
In this repository36 other files it gives its agents.
- skills/writing-skills/references/agents.mdAGENTS.md
- templates/CLAUDE.mdCLAUDE.md
- backend-servicesSkill
- brainstormingSkill
- choosing-a-stackSkill
- ci-quality-gatesSkill
- database-changesSkill
- desktop-developmentSkill
- dispatching-parallel-agentsSkill
- docsSkill
- executing-plansSkill
- finishSkill
- git-workflowSkill
- implementSkill
- kit-initSkill
- mobile-developmentSkill
- new-taskSkill
- observabilitySkill
- onboarding-existing-codebaseSkill
- payments-and-moneySkill
- pos-systemsSkill
- publishing-documentsSkill
- receiving-code-reviewSkill
- requesting-code-reviewSkill
- security-reviewSkill
- systematic-debuggingSkill
- test-driven-developmentSkill
- ui-motionSkill
- updating-dependenciesSkill
- using-skillsSkill
- verification-before-completionSkill
- verifySkill
- web-frontendSkill
- writing-documentationSkill
- writing-plansSkill
- writing-skillsSkill
The file
We split this skill into the rules it gives an agent
7 rules. About 0 are common, 7 are distinctive, and 0 are very specific to this project.
≈0
Common · estimate
Many files like this have a rule of this kind.
≈7
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 15
No reformatting, reordering or renaming outside the change.
- Distinctive: line 16
Don't upgrade dependencies unless the task needs it.
- Distinctive: line 17
Delete only what your own change orphaned.
- Distinctive: line 20
Leave generated, vendored and migration history alone: Add new migrations; never edit applied ones.
- Distinctive: line 30
Keep these refactors tiny, behavior-preserving, and committed separately from the behavior change.
- Distinctive: line 32
Sprout: put new logic in a new, tested function or class and call it from the old code.
- Distinctive: line 33
Wrap: add behavior before or after an existing call without editing its insides.
≈ “Common” is an estimate: at least 1 in 5 of the 408,460 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
Changing legacy code
Legacy code is code without a safety net. Its current behavior, including its quirks, is what users depend on. Change it the way a careful senior engineer would: pin the behavior first, change as little as possible, and leave it a bit easier to test.
Rules
- Follow the house style, even if you would do it differently: its patterns, naming, framework version and error handling. Don't introduce a new paradigm in one corner.
- Keep the diff minimal.
- No reformatting, reordering or renaming outside the change.
- Don't upgrade dependencies unless the task needs it.
- Delete only what your own change orphaned.
- Report other dead code; don't delete it.
- Treat surprises as possible requirements. An odd branch may be a customer contract, a legal rule or a device workaround. Check
git log -L/git blame, linked issues and tests, and ask before "fixing" behavior nobody asked about. - Leave generated, vendored and migration history alone. Add new migrations; never edit applied ones.
Process
- Understand the change point: callers, data flow, side effects (DB, files, network, devices), and configuration and feature flags.
- Pin current behavior with characterization tests. Call the code with realistic inputs and assert whatever it does today, even if it looks wrong, so that any change shows up. Cover the paths you will touch plus their edges. Name them
*.char.test.*(or the stack's equivalent): they are the one kind of test whose expected values come from running the code, they pass on first run by design, and they don't count as tests of new behavior. - Find or create a seam where a test can control dependencies:
- pass the dependency as a parameter or constructor argument;
- wrap a static or global in a small interface;
- extract the pure logic from the I/O. Keep these refactors tiny, behavior-preserving, and committed separately from the behavior change.
- Make the change with TDD (test-driven-development): a new failing test for the new behavior, then minimal code.
- Sprout: put new logic in a new, tested function or class and call it from the old code.
- Wrap: add behavior before or after an existing call without editing its insides.
- Verify with the characterization tests and the full suite. Where coverage of the affected flow stays thin, add a manual run of it as well (it adds to the tests, it doesn't replace them) and say explicitly what could not be covered.
Larger rewrites: strangler fig
Don't rewrite in place. Put a facade or route in front of the old component and move one capability at a time behind it (a feature flag or traffic split). Compare old and new outputs in shadow mode when you can, and remove the old path only after the new one has proven itself. Get the user's approval for the plan. This is architectural work (brainstorming).
Red flags
| Thought | Reality |
| "This is ugly, let me clean it up while I'm here" | That's out of scope. Mention it; don't do it. |
| "No tests exist, so TDD doesn't apply" | Pin the behavior first. That is TDD for legacy code. |
| "This branch looks like a bug" | It may be a requirement. Ask. |
| "Upgrading the framework will make this easier" | That's a separate, planned task. |
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.

