agentleFS
smileynetsmileynet/code-spice/skills/code-pruning/SKILL.md

code-pruning

Skill0 starsChanged 9 months agoMITView on GitHub

Dead code detection strategies, safe removal processes, dependency pruning, and bloat metrics for systematically reducing codebase dead weight. Use when evaluating codebase health during architecture-audit, performing cleanup during cook, reviewing unused dependencies, removing commented-out code, or measuring code bloat.

The file

Files
SKILL.md

Code Pruning

Pruning Checklist

  • Static analysis tools run for all project languages
  • SCARF phases followed (Survey → Classify → Announce → Remove → Follow-up)
  • Each removal verified by test suite
  • Dependency manifest audited for unused packages
  • Commented-out code deleted (version control remembers)
  • Bloat metrics captured before and after

Detection Approaches

ApproachHow It WorksConfidenceLimitation
Static analysisParse AST, trace referencesHigh for unused exports/functionsMisses dynamic dispatch, reflection
Dynamic analysisRuntime instrumentation, coverageHigh for executed pathsMisses rarely-used paths (disaster recovery, seasonal)
Combined (SCARF)Static + dynamic + team reviewHighestRequires team coordination
Manual reviewHuman inspection, git blameVariableDoesn't scale; subjective

SCARF Pattern (from Meta)

PhaseActionCheckpoint
SurveyRun static analysis tools; identify candidatesCandidate list generated
ClassifyCategorize each: dead, dormant, speculative, deprecatedEach candidate classified
AnnounceDeprecation warnings; notify stakeholdersTeam aware of pending removals
RemoveDelete with tests verifying no breakageAll tests pass after removal
Follow-upMonitor production for regressions; verify no side effectsNo production issues after 1 week

For smaller teams: Compress Announce into a PR description or commit message. The key phases are Survey, Classify, and Remove-with-tests.

Language-Specific Tools (current as of Feb 2026)

LanguageToolNotes
JS/TSKnipSupersedes ts-prune; handles re-exports, dependencies, and unused files
JS/TSdepcheckFocused on unused npm dependencies
PythonVultureAST-based dead code detection; configure --min-confidence 80
PythonautoflakeRemoves unused imports and variables
JavaPMDStatic analysis rules for unused code
GodeadcodeOfficial Go team tool (1.22+); superior to unused
MultiSonarQubeCross-language; includes unused code rules

Safe Removal Process (6 Steps)

  1. Identify — Run static analysis; flag zero-reference code
  2. Verify with dynamic data — Check code coverage, production logs, feature flags
  3. Deprecate — Add deprecation warnings; set removal date
  4. Delete — Remove code in atomic, single-concern commits
  5. Test — Full test suite passes; no integration regressions
  6. Audit — Post-removal monitoring for 1 week; check error rates

Dependency Pruning

Common False Positives

False PositiveHow to Verify
Peer dependencyCheck if required by another installed package
CLI toolCheck npm scripts, Makefile, CI config
Plugin/loaderCheck config files (webpack, babel, pytest, etc.)
Type-only importCheck .d.ts files and type annotations

Bloat Metrics

IndicatorHealthyWarningCritical
Unreachable code ratio<5%5-15%>15%
Unused dependency count0-23-5>5
Commented-out code blocks01-5>5
Single-implementation interfaces<33-10>10

Decision Tables

"How confident am I that this code is dead?"

EvidenceConfidenceAction
Zero static references + zero runtime coverageHighDelete (with tests)
Zero static refs but in error/recovery pathMediumVerify with team before deleting
Referenced only by testsMediumDelete code and tests together
Referenced by commented-out code onlyHighDelete both
Dynamic dispatch possible (reflection, eval)LowInstrument before deleting

"Should I prune this dependency?"

SignalAction
Zero imports in source codeRemove (check for false positives first)
Only in devDependencies, not used in scriptsRemove
Imported but functionality is unusedReplace with lighter alternative or remove
Peer dependency of another packageKeep — removing breaks the dependent
Last updated >2 years, no maintained forkPlan migration to maintained alternative

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.