refactoring-and-dead-code-removal
Skill0 starsChanged 4 months agoMITView on GitHub
Changes code structure without changing behavior and removes unused code safely by establishing a passing baseline, making one mechanical change at a time, re-running tests between steps, and proving code is dead before deleting it. Use when cleaning up, simplifying, restructuring, extracting, renaming, or deleting suspected unused code, imports, functions, or files.
In this repository24 other files it gives its agents.
- AGENTS.mdAGENTS.md
- agent-tool-interface-designSkill
- codebase-explorationSkill
- code-reviewSkill
- copilot-cloud-agentSkill
- documentation-maintenanceSkill
- external-skill-reviewSkill
- git-and-pr-workflowSkill
- parallel-worktree-deliverySkill
- planning-and-task-breakdownSkill
- repository-agent-bootstrapSkill
- requirements-and-spec-writingSkill
- security-reviewSkill
- shadow-architectureSkill
- shadow-dreamSkill
- shadow-driftSkill
- shadow-observeSkill
- skill-creatorSkill
- systematic-debuggingSkill
- test-driven-developmentSkill
- verification-before-completionSkill
- verification-disciplineSkill
- wayfinder-planningSkill
- web-research-and-verificationSkill
The file
We split this skill into the rules it gives an agent
9 rules. About 0 are common, 9 are distinctive, and 0 are very specific to this project.
≈0
Common · estimate
Many files like this have a rule of this kind.
≈9
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 29
Ensure behavior is covered.
- Distinctive: line 37
Keep refactoring and behavior change in separate commits.
- Distinctive: line 43
Do not remove or change code until you understand why it exists.
- Distinctive: line 48
If you cannot explain its purpose, assume it has one and investigate further rather than deleting it.
- Distinctive: line 50
Only remove it once you can state what it did and why removing it is safe.
- Distinctive: line 57
Search for every reference to the symbol across the whole repository, including tests, configuration, string-based lookups, and dynamic …
- Distinctive: line 59
Check the call graph: confirm nothing reachable calls it, directly or through an interface, export, or reflection.
- Distinctive: line 62
Remove it, then run the full test suite and build to confirm nothing breaks.
- Distinctive: line 63
If removal is large or risky, deprecate first, then remove after confirming no use.
≈ “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
Refactoring and Dead-Code Removal
Goal
Improve structure or remove unused code while preserving observable behavior exactly, with test evidence at every step.
Core rule
Refactoring never changes behavior. If a change alters what the program does, it is a behavior change and belongs in a separate commit with its own tests. Keep the two apart so a regression is easy to locate and revert.
Workflow
- Establish a passing baseline. Run the repository's test command and build before touching anything. If the baseline is not green, stop and fix or record that first; you cannot detect regressions against a broken baseline.
- Ensure behavior is covered. If the code you will change lacks tests that pin its current behavior, add characterization tests first so a regression will surface.
- Make one mechanical change at a time. Rename, extract, inline, or move a single thing. Prefer the language or IDE's automated refactoring tools, which preserve behavior more reliably than manual edits.
- Re-run tests between steps. After each change, run the affected tests. A failure isolates the single step that caused it.
- Keep refactoring and behavior change in separate commits. Never mix them.
- Review the diff. Confirm it only restructures and does not alter logic, defaults, or outputs.
Chesterton's Fence
Do not remove or change code until you understand why it exists. Code that looks pointless often handles a case that is not obvious from a first reading.
- Find out why the code is there: read history, related tests, comments, and linked issues.
- If you cannot explain its purpose, assume it has one and investigate further rather than deleting it.
- Only remove it once you can state what it did and why removing it is safe.
Proving code is dead
Suspected-unused is not proven-unused. Gather evidence before deleting. See references/dead-code-evidence.md.
- Search for every reference to the symbol across the whole repository, including tests, configuration, string-based lookups, and dynamic access.
- Check the call graph: confirm nothing reachable calls it, directly or through an interface, export, or reflection.
- Confirm it is not part of a public API that external consumers depend on.
- Remove it, then run the full test suite and build to confirm nothing breaks.
- If removal is large or risky, deprecate first, then remove after confirming no use.
Forbidden approaches
- Mixing a behavior change into a refactoring commit.
- Deleting code because it looks unused without reference and call-graph evidence.
- Refactoring against a red or unknown baseline.
- Large sweeping rewrites in a single step that cannot be verified incrementally.
Output
Report the baseline result, each mechanical step taken, the evidence gathered before any deletion, and the passing test and build output after the changes.
References
- references/dead-code-evidence.md — gathering reference, call-graph, and test evidence before removing code, and handling dynamic access and public APIs.
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.

