agentleFS
Cody-SimsCody-Sims/agent-skills/skills/refactoring-and-dead-code-removal/SKILL.md

refactoring-and-dead-code-removal

Skill0 starsChanged 4 months agoMITView on GitHub

Refactors structure and removes proven dead code without changing observable behavior. Use when simplifying, extracting, renaming, moving, or deleting suspected unused code; requires a passing baseline and deletion evidence, not a defect fix or new behavior.

The file

We split this skill into the rules it gives an agent

8 rules. About 0 are common, 8 are distinctive, and 0 are very specific to this project.

  • ≈0

    Common · estimate

    Many files like this have a rule of this kind.

  • ≈8

    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
  1. Distinctive:

    Read applicable instructions.

    line 21
  2. Distinctive:

    Add characterization tests first where current behavior is not pinned.

    line 28
  3. Distinctive:

    Before any deletion, read dead-code evidence and establish:

    line 29
  4. Distinctive:

    Use symbol/call-graph tools plus targeted literal searches across relevant file types.

    line 36
  5. Distinctive:

    Run affected tests after each step.

    line 43
  6. Distinctive:

    Keep behavior changes separate, even if they appear convenient.

    line 45
  7. Distinctive:

    Stop on an unverified baseline, unexplained purpose, uncertain deletion evidence, or behavioral drift.

    line 53
  8. Distinctive:

    Never describe a suspected-unused symbol or an unrun check as verified.

    line 56

≈ “Common” is an estimate: at least 1 in 5 of the 364,980 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.

Keep what fits and drop the rest. Your version, ready for your agents.
Files
SKILL.md

Refactoring and Dead-Code Removal

Contract

Inputs: the structural cleanup scope, current behavior, and repository test/build commands. Preserve observable behavior exactly. Behavior changes need separate work, tests, and commits; this skill does not authorize committing.

Workflow

  1. Read applicable instructions. Run the repository test command and build before editing; record results. A red, missing, or unknown baseline blocks refactoring: resolve an authorized prerequisite or report it, not an unrelated repair. Reuse baseline evidence only while the relevant state is unchanged.
  2. Understand the code's purpose through related tests, comments, history, and linked issues. Start with the target and its consumers; widen only for an unanswered dependency. If purpose is unclear, investigate rather than delete. Add characterization tests first where current behavior is not pinned.
  3. Before any deletion, read dead-code evidence and establish:
    • Repository-wide references, including aliases, re-exports, tests, fixtures, configuration, scripts, documentation, and string-based lookups.
    • Reachability through callers, interfaces, overrides, reflection, framework entry points, and dynamic/plugin registration.
    • Whether external consumers depend on a public export. Use symbol/call-graph tools plus targeted literal searches across relevant file types. Do not infer absence from truncated output or an unused-symbol warning alone. Unknown dynamic or external use means not proven dead.
  4. Make one mechanical rename, extraction, inline, move, or proven deletion at a time; prefer automated refactoring tools. Remove dedicated tests only for proven-dead code, preserving tests of live behavior. For large/risky removals or uncertain external use, follow deprecation/version policy before removal.
  5. Run affected tests after each step. On failure, isolate or revert that step without discarding others' changes; do not continue a sweeping rewrite. Keep behavior changes separate, even if they appear convenient.
  6. Inspect the final diff for unchanged logic, defaults, outputs, public contracts, and unrelated edits. Run final affected tests/build and mandatory repository gates; after dead-code removal, the full test suite and build are required, not just focused tests. One final run may cover both obligations.

Stop and output

Stop on an unverified baseline, unexplained purpose, uncertain deletion evidence, or behavioral drift. Report baseline command/results, mechanical steps, deletion evidence or deprecation decision, final test/build results, and remaining risk. Never describe a suspected-unused symbol or an unrun check as verified.

Download now (ZIP)

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
What did you use it for? e.g. Reviewing pull requests in a Rails app

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.