dead-code-eliminator
npx machina-cli add skill a5c-ai/babysitter/dead-code-eliminator --openclawDead Code Eliminator Skill
Identifies and safely removes dead code, unused functions, unreachable code paths, and orphaned files from codebases to reduce complexity and maintenance burden.
Purpose
Enable safe dead code removal for:
- Codebase simplification
- Migration preparation
- Technical debt reduction
- Build size optimization
- Maintenance cost reduction
Capabilities
1. Unused Function Detection
- Find uncalled functions
- Identify unused exports
- Detect unreferenced methods
- Map call graphs
2. Unreachable Code Identification
- Analyze control flow
- Find code after returns
- Detect impossible conditions
- Identify dead branches
3. Unused Variable Detection
- Find unread variables
- Identify write-only variables
- Detect unused parameters
- Flag shadowed variables
4. Orphan File Detection
- Find unimported modules
- Identify orphaned assets
- Detect unused configuration
- Map file dependencies
5. Safe Removal Verification
- Verify no runtime references
- Check dynamic imports
- Validate reflection usage
- Test after removal
6. Impact Analysis
- Estimate removal scope
- Calculate size reduction
- Assess risk level
- Document dependencies
Tool Integrations
| Tool | Language | Integration Method |
|---|---|---|
| ts-prune | TypeScript | CLI |
| unimported | JavaScript | CLI |
| deadcode | Python | CLI |
| UCDetector | Java | Eclipse Plugin |
| unused | Rust | CLI |
| deadcode | Go | CLI |
| webpack-bundle-analyzer | JavaScript | CLI |
Output Schema
{
"analysisId": "string",
"timestamp": "ISO8601",
"deadCode": {
"functions": [
{
"file": "string",
"name": "string",
"line": "number",
"confidence": "high|medium|low",
"reason": "string"
}
],
"variables": [],
"files": [],
"unreachable": []
},
"impact": {
"filesAffected": "number",
"linesRemovable": "number",
"estimatedSizeReduction": "string"
},
"risks": [],
"recommendations": []
}
Integration with Migration Processes
- code-refactoring: Pre-refactoring cleanup
- legacy-decommissioning: Feature removal
- monolith-to-microservices: Service extraction prep
Related Skills
static-code-analyzer: Combined analysiscode-smell-detector: Related smell detection
Related Agents
legacy-decommissioning-specialist: Uses for cleanupcode-transformation-executor: Executes removal
Source
git clone https://github.com/a5c-ai/babysitter/blob/main/plugins/babysitter/skills/babysit/process/specializations/code-migration-modernization/skills/dead-code-eliminator/SKILL.mdView on GitHub Overview
Dead Code Eliminator identifies dead, unused, and unreachable code and removes it to reduce complexity and maintenance burden. It targets codebase simplification, migration preparation, technical debt reduction, and build size optimization.
How This Skill Works
It analyzes codebases to detect unused functions, unreferenced variables, and unreachable code paths, then maps call graphs and dependency relationships. It also identifies orphan files and performs safe removal verification, including checks for dynamic imports and reflection usage, followed by impact analysis.
When to Use It
- Before a major refactor or migration to simplify the codebase
- During legacy-decommissioning to remove deprecated modules and assets
- Prior to bundling or packaging to reduce build size
- During debt reduction and maintenance cost initiatives
- When preparing for monolith-to-microservices or service extraction
Quick Start
- Step 1: Run the dead-code-eliminator scan on the repository
- Step 2: Review high-confidence findings (functions, branches, and files) and confirm safety
- Step 3: Remove confirmed items, then run tests and rebuild to verify
Best Practices
- Run detection in a dedicated branch and preserve originals via version control
- Cross-validate findings against runtime behavior and dynamic imports
- Prioritize high-confidence candidates and verify call graphs
- Always run the full test suite and perform manual checks after removal
- Document removed code and update dependencies and references
Example Use Cases
- Removed unreferenced utility functions in a TypeScript project
- Eliminated unreachable branches after feature flags were retired in a JS app
- Pruned unused exports and unread variables in a Python library
- Detected and removed orphaned modules in a Go service
- Cleaned up unused assets and configuration after a migration