Identify genuinely unused files without breaking your production code. This conservative analysis finds safe cleanup opportunities whilst protecting against false positives that could take down your application.

Quick Start

Start cleaning up your codebase with these safe, conservative prompts:

Basic Cleanup Analysis
Can you find any unused files in my project? C:/my-react-app/src
Conservative Dead Code Detection
Use houtini-lm to find unused files safely in C:/project - include commented code analysis
Enterprise Project Cleanup
Please identify unused TypeScript files in C:/enterprise-app with comprehensive analysis

Safety First

This function is intentionally conservative - it would rather miss some unused files than suggest deleting something important. Always review recommendations before deleting files.

What It Does

find_unused_files is your safety-first code cleanup assistant. Unlike aggressive tools that might suggest deleting files your application secretly depends on, this function uses sophisticated dependency analysis to identify only genuinely unused files.

Here's what makes it special:

  • Conservative by design - Avoids false positives that could break production
  • Smart dependency tracing - Follows imports, requires, and dynamic loading patterns
  • Risk categorisation - "Definitely safe" vs "Investigate further"
  • Commented code detection - Finds files that might be imported in comments
  • Confidence scoring - Every recommendation comes with a confidence level
  • Executive summary - Clear overview of cleanup potential and impact

Whether you're preparing for a refactor, cleaning up after feature removals, or just want to understand which files are actually being used, this function provides safe, actionable insights without the risk of breaking your application.

Parameters

Fine-tune your dead code detection to balance thoroughness with safety:

Parameter Type Required Default Description
projectPath string Yes -

Root directory to analyse for unused files

Example: "C:/my-project/src" for just source code
entryPoints array No ["index.ts", "main.ts"]

Entry point files for dependency tracing

Include all your main files: ["index.js", "app.js", "server.js"]
analyzeComments boolean No true

Check for commented-out imports that might indicate usage

Finds files referenced in TODO comments or commented code
includeDevArtifacts boolean No false

Flag potential development artifacts for review

Identifies test fixtures, mock data, experimental code
excludePatterns array No ["*.test.ts", "*.spec.ts"]

File patterns to exclude from unused analysis

Skip test files, config files, or known development utilities
analysisDepth string No "comprehensive"

Analysis thoroughness: "basic", "detailed", "comprehensive"

"comprehensive" provides the safest, most thorough analysis

Real-World Examples

Here's how to safely clean up different types of projects:

React Application Cleanup

React Project Analysis
houtini-lm:find_unused_files with:
- projectPath: "C:/my-react-app/src"
- entryPoints: ["index.tsx", "App.tsx", "serviceWorker.ts"]
- analyzeComments: true

Node.js API Cleanup

Backend Service Analysis
houtini-lm:find_unused_files with:
- projectPath: "C:/api-server/src"
- entryPoints: ["server.js", "app.js", "worker.js"]
- includeDevArtifacts: true
- excludePatterns: ["*.test.js", "*.spec.js", "*.mock.js"]

Enterprise Monorepo

Large Codebase Analysis
houtini-lm:find_unused_files with:
- projectPath: "C:/enterprise-monorepo/packages/core"
- entryPoints: ["index.ts", "main.ts", "public-api.ts"]
- analysisDepth: "comprehensive"
- analyzeComments: true
- includeDevArtifacts: false

Post-Refactor Cleanup

After Feature Removal
houtini-lm:find_unused_files with:
- projectPath: "C:/app/src"
- entryPoints: ["main.ts", "routes.ts", "index.ts"]
- analyzeComments: true
- includeDevArtifacts: true

Built-in Safety Features

This function is designed to protect your production code from accidental deletion:

๐Ÿ›ก๏ธ Conservative Analysis

The analysis errs on the side of caution - it would rather keep a potentially unused file than suggest deleting something that might break your application. This approach means you get safe recommendations without the anxiety of wondering if you're about to break production.

๐Ÿ“Š Risk Categorisation

  • "Definitely safe to remove" - High confidence, no dependencies found
  • "Likely unused" - Medium confidence, minimal risk
  • "Investigate further" - Potential usage patterns detected
  • "Keep for now" - Complex dependency patterns, too risky to remove

๐Ÿ” Sophisticated Detection

  • Dynamic imports - Detects runtime loading patterns
  • Commented references - Finds files mentioned in comments
  • Build-time dependencies - Identifies webpack/build tool usage
  • Configuration references - Finds files referenced in config

๐Ÿ“ˆ Confidence Scoring

Every recommendation comes with a confidence score explaining why the file was flagged and how certain the analysis is about its unused status. This helps you make informed decisions about what to delete.

Peace of Mind

This function has been designed by developers who've been burned by aggressive cleanup tools. Safety and reliability come first, aggressive cleanup comes second.

Perfect Use Cases

Here's when this function becomes invaluable:

๐Ÿงน Post-Refactor Cleanup

After removing features or refactoring large sections of code, identify the orphaned files that are no longer needed. Perfect for cleaning up after major architectural changes.

๐Ÿ“ฆ Bundle Size Optimisation

Find unused components, utilities, and modules that are bloating your bundle. Every unused file removed makes your application faster and leaner.

๐Ÿ”„ Legacy Code Migration

When modernising older codebases, identify which legacy files can be safely removed without breaking existing functionality.

๐Ÿข Team Handover Preparation

Clean up technical debt before handing a project over to another team. Remove experimental code, unused prototypes, and abandoned features.

๐Ÿ“‹ Pre-Deployment Audits

Before major releases, ensure you're not shipping unused code that could confuse future maintainers or create security vulnerabilities.

๐ŸŽฏ Technical Debt Reduction

Systematically reduce technical debt by identifying and removing files that no longer serve a purpose in your application.

Best Practices

Get the most value from your cleanup analysis whilst keeping your code safe:

๐ŸŽฏ Start with Clear Entry Points

Always specify your main entry points accurately. Include:

  • Main application files (index.js, app.js, main.ts)
  • Server entry points (server.js, api.js)
  • Worker files (worker.js, background.js)
  • Public API exports (public-api.ts, index.ts)

๐Ÿ“‹ Review Before Deleting

Never delete files without reviewing the recommendations:

  1. Start with "Definitely safe to remove" category
  2. Check each file manually to understand its purpose
  3. Look for any recent commits or changes to the file
  4. Consider if the file might be needed for future features
  5. Move files to a "unused" folder initially, delete later

๐Ÿ” Use Version Control

Always work in a branch when cleaning up unused files:

  • Create a dedicated cleanup branch
  • Make incremental commits for each file deleted
  • Test thoroughly before merging
  • Keep the original branch until you're confident

โšก Phased Approach

For large cleanups, work in phases:

  1. Phase 1: Delete obvious unused files (confidence > 90%)
  2. Phase 2: Review and remove likely unused files
  3. Phase 3: Investigate complex cases manually
  4. Phase 4: Archive rather than delete uncertain files

๐Ÿงช Test Everything

  • Run your full test suite after deletions
  • Test in development and staging environments
  • Check that builds still work correctly
  • Verify that all entry points still function

Remember

This tool provides recommendations, not absolute truths. Dynamic imports, runtime loading, and complex dependency patterns can sometimes fool even sophisticated analysis. Always verify before deleting.

Troubleshooting

Common issues and how to resolve them:

No unused files found in a project I know has dead code

The analysis is being too conservative and missing genuinely unused files.

  • Check your entry points are complete - missing entries can make files appear used
  • Review your exclude patterns - you might be excluding too much
  • Try setting analysisDepth: "basic" for a less conservative analysis
  • Use a larger model (13B+ parameters) for more sophisticated analysis
Analysis flagged files I know are being used

Some files that are definitely in use are showing up as unused.

  • Add missing entry points - these files might be loaded through routes not in your main entries
  • Check for dynamic imports or runtime loading patterns the analysis missed
  • Files used only in build processes or configs might not be detected
  • Add these files to your excludePatterns to skip them
Analysis takes too long on large projects

The dependency analysis is running very slowly on large codebases.

  • Start with analysisDepth: "basic" for faster results
  • Analyse smaller subdirectories instead of the entire project
  • Ensure your LM Studio model has sufficient memory
  • Add more specific exclude patterns to skip known safe directories
Getting too many "investigate further" recommendations

Most files are marked as "investigate further" rather than "definitely safe".

  • This is normal for complex projects - the analysis is being appropriately cautious
  • Focus on the "definitely safe" files first for quick wins
  • Manually review the "investigate further" files to understand why they're flagged
  • Consider if your project uses many dynamic loading patterns
TypeScript/JavaScript module confusion

Analysis seems confused about TypeScript imports or module resolution.

  • Ensure your entry points use the correct file extensions (.ts, .tsx, .js)
  • Check that your project structure follows standard conventions
  • The analysis works best with standard import/export patterns
  • Complex webpack aliases or module resolution might not be fully detected