find_unused_files – Smart Dead Code Detection
Expert identification of genuinely unused files with conservative risk assessment and dependency analysis
Perfect For
Legacy Codebase Cleanup
Safely identify orphaned files in inherited projects without risking production system stability.
Bundle Size Optimisation
Reduce JavaScript bundle sizes by identifying genuinely unused modules and components with minimal false positive risk.
Technical Debt Reduction
Systematic cleanup approach with phased removal plans and confidence scoring for each recommendation.
Pre-Refactoring Analysis
Identify safe cleanup opportunities before major architectural changes to simplify the refactoring process.
Repository Maintenance
Regular housekeeping to prevent accumulation of dead code and maintain clean development environments.
Quick Start
local-llm:find_unused_files with:
- projectPath: "C:/my-project/src"
- entryPoints: ["index.ts", "main.ts", "app.ts"]
- analyzeComments: true
Conservative analysis for production systems:
local-llm:find_unused_files with:
- projectPath: "C:/production-app"
- entryPoints: ["index.js", "server.js"]
- excludePatterns: ["*.test.js", "*.spec.js", "*.d.ts"]
Analysis Output
Risk-Categorised Results
- Definitely Safe to Remove: Files with no references and high confidence scoring (95%+ certainty)
- Likely Safe: Files with minimal or commented-out references requiring verification
- Requires Investigation: Files with potential dynamic imports or complex dependency patterns
Dependency Analysis
- Import Chain Tracing: Complete dependency graph analysis from specified entry points
- Dynamic Import Detection: Identifies potential runtime-loaded modules to prevent false positives
- Configuration File Analysis: Checks build tool configurations for referenced assets
Executive Summary
- Cleanup Potential: Total files and estimated disk space recovery
- Confidence Metrics: Statistical confidence for each removal category
- Phased Removal Plan: Step-by-step cleanup approach with verification checkpoints
Analysis Example
Project Structure
src/
├── components/
│ ├── UserCard.tsx (referenced)
│ ├── OldUserCard.tsx (unused)
│ └── LegacyModal.tsx (commented import)
├── utils/
│ ├── helpers.ts (referenced)
│ └── oldHelpers.ts (unused)
└── index.ts
Analysis Results
- Definitely Safe (2 files, 15KB): OldUserCard.tsx, oldHelpers.ts
- Requires Investigation (1 file): LegacyModal.tsx – found in commented import
- Confidence Score: 98% for safe removal recommendations
- Estimated Cleanup: 15KB disk space, 2 fewer files to maintain
Parameters
Parameter | Type | Description | Example |
---|---|---|---|
projectPath | string | Root directory for analysis | “C:/project/src” |
entryPoints | array | Main entry files for dependency tracing | [“index.ts”, “main.ts”] |
analyzeComments | boolean | Check commented-out imports | true |
includeDevArtifacts | boolean | Flag development-only files | false |
excludePatterns | array | File patterns to exclude from analysis | [“*.test.ts”, “*.spec.ts”] |
Entry Points Strategy
- Web Applications: Include index.js/ts, main.js/ts, and any route entry points
- Node.js APIs: Include server.js, app.js, and any worker process entry points
- Libraries: Include all public API entry points and index files
Advanced Configuration
Multi-Entry Analysis: For complex applications with multiple entry points, specify all potential starting points to ensure comprehensive analysis.
// Full web application analysis
local-llm:find_unused_files with:
- projectPath: "C:/web-app/src"
- entryPoints: ["index.tsx", "serviceWorker.ts", "admin/index.tsx"]
- analyzeComments: true
- includeDevArtifacts: false
// Library cleanup with test exclusion
local-llm:find_unused_files with:
- projectPath: "C:/my-library/src"
- entryPoints: ["index.ts", "browser.ts", "node.ts"]
- excludePatterns: ["*.test.ts", "*.spec.ts", "__tests__/**"]
Safe Cleanup Workflow:
- Run find_unused_files analysis with conservative settings
- Review “Definitely Safe” files and create backup branch
- Remove safe files and run complete test suite
- Investigate “Requires Investigation” files manually
- Use count_files to verify cleanup results
Pro Tips
Conservative Approach: The analysis errs on the side of caution to prevent breaking production systems. Always verify recommendations in development environment first.
Version Control Safety: Create a dedicated cleanup branch before removing any files, enabling easy rollback if issues are discovered.
Build Process Verification: After cleanup, run complete build and test processes to ensure no dynamic dependencies were missed.
Related Functions
- count_files – Before and after project structure comparison
- analyze_dependencies – Comprehensive dependency relationship analysis
- security_audit – Security review before removing potentially sensitive files
- analyze_project_structure – Post-cleanup architectural assessment