dead-code-cleaner
Skill0 starsChanged 8 months agoMITView on GitHub
Use when finishing a task, after completing edits, or when code feels cluttered with unused imports, unreferenced functions, commented-out blocks, orphaned files, or duplicate utilities. Reduces the 41% code churn rate caused by AI agents leaving obsolete artifacts behind.
In this repository2 other files it gives its agents.
- loop-breakerSkill
- scope-guardSkill
The file
We split this skill into the rules it gives an agent
8 rules. About 0 are common, 7 are distinctive, and 1 is 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.
1
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Distinctive: line 14
Every dead line forces the next developer to ask: "Is this important?
- Distinctive: line 20
After completing a task, sweep all modified and newly created files for:
- Distinctive: line 32
Unused imports: Search the file for any reference to the imported name.
- Very specific: line 33
Unreferenced functions: Search the entire project, not just the current file.
- Distinctive: line 35
Orphaned files: Verify no imports, requires, or references point to the file.
- Distinctive: line 40
Remove one category at a time.
- Distinctive: line 41
Do NOT remove code that is outside the scope of your current task unless it was created or modified as part of this task.
- Distinctive: line 42
If unsure whether something is dead, leave it and flag it for the user.
≈ “Common” is an estimate: at least 1 in 5 of the 350,495 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
Dead Code Cleaner: If It Serves No Purpose, It Must Go
AI agents leave debris. Unused imports, orphaned functions, commented-out blocks, duplicate utilities -- dead code that inflates churn to 41%. This skill runs a cleanup pass after every task.
The Iron Law
Code that serves no purpose is not neutral -- it is a lie that the next reader must investigate.
Every dead line forces the next developer to ask: "Is this important? Is it used somewhere I can't see? Was it left here intentionally?" That wasted investigation multiplies across every future reader.
The Process
Step 1 -- Scan for the Five Categories
After completing a task, sweep all modified and newly created files for:
- Unused imports -- Modules imported but never referenced in the file
- Unreferenced functions/variables -- Declared but never called or accessed
- Commented-out code -- Not comments explaining why, but old code preserved "just in case"
- Orphaned files -- Files created during development (scratch files, old versions, temp utilities) that are not imported or referenced anywhere
- Duplicate utilities -- Functions that do the same thing as an existing utility, often created because the agent did not discover the original
Step 2 -- Verify Before Removing
For each candidate, confirm it is truly dead:
- Unused imports: Search the file for any reference to the imported name. Check for side-effect imports (CSS modules, polyfills, init scripts) that are intentionally reference-free.
- Unreferenced functions: Search the entire project, not just the current file. Check for dynamic references (
getattr, bracket notation, reflection). Check for exports consumed elsewhere. - Commented-out code: Distinguish code from documentation.
// Calculate the hash using SHA-256is a comment.// const result = oldApi.fetch(url)is dead code. - Orphaned files: Verify no imports, requires, or references point to the file. Check build configs, test configs, and scripts.
- Duplicates: Confirm identical behavior before removing. Keep the version with better naming, tests, or documentation. Update all callers to use the surviving version.
Step 3 -- Remove With Precision
- Remove one category at a time. Verify the build and tests still pass after each category.
- Do NOT remove code that is outside the scope of your current task unless it was created or modified as part of this task.
- If unsure whether something is dead, leave it and flag it for the user.
Step 4 -- Report What Was Cleaned
After cleanup, summarize:
- What was removed and why
- What was flagged as suspicious but left (with reasoning)
- Any duplicates found that may warrant consolidation in a future task
Red Flags -- Common Dead Code Patterns
| Pattern | Category |
import { helper } from './utils' but helper never appears below | Unused import |
function oldHandler() { ... } with zero call sites | Unreferenced function |
// const config = loadLegacyConfig() | Commented-out code |
temp_solution.ts or utils_backup.js in project | Orphaned file |
formatDate() in helpers.ts AND formatDateString() in utils.ts doing the same thing | Duplicate utility |
TODO: remove after migration still present months later | Stale dead code |
| Variable assigned but never read | Unreferenced variable |
Entire else branch that returns the same value as the if branch | Redundant logic |
Flowchart
digraph dead_code_cleaner {
rankdir=TB
node [shape=box style=rounded]
done [label="Task completed"]
scan [label="Step 1: Scan modified/created files\nfor 5 dead code categories"]
found [label="Dead code\ncandidates found?" shape=diamond]
verify [label="Step 2: Verify each candidate\nis truly dead\n(search project-wide)"]
confirmed [label="Confirmed dead?" shape=diamond]
flag [label="Flag as suspicious\nfor user review"]
remove [label="Step 3: Remove one\ncategory at a time"]
test [label="Build + tests\nstill pass?" shape=diamond]
revert [label="Revert removal.\nFlag for user."]
more [label="More categories\nto clean?" shape=diamond]
report [label="Step 4: Report\nwhat was cleaned\nand what was flagged"]
finish [label="Present clean work"]
done -> scan
scan -> found
found -> finish [label="None"]
found -> verify [label="Yes"]
verify -> confirmed
confirmed -> remove [label="Yes"]
confirmed -> flag [label="Unsure"]
remove -> test
test -> more [label="Yes"]
test -> revert [label="No"]
revert -> more
more -> verify [label="Yes"]
more -> report [label="No"]
flag -> more
report -> finish
}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.

