Skip to content
| Marketplace
Sign in
Visual Studio Code>Linters>Import & Dead Code OptimizerNew to Visual Studio Code? Get it now.
Import & Dead Code Optimizer

Import & Dead Code Optimizer

Saurav Pandey

|
6 installs
| (0) | Free
AST-powered unused import removal, dead code detection, namespace import optimization, and dependency cleanup for TypeScript/JavaScript projects.
Installation
Launch VS Code Quick Open (Ctrl+P), paste the following command, and press enter.
Copied to clipboard
More Info

Import & Dead Code Optimizer

A VS Code extension that uses real AST analysis (powered by ts-morph) to find and remove unused code in TypeScript/JavaScript projects — safely.

Features

Feature Auto-fixable Description
Unused imports ✅ Detects and removes import specifiers not referenced in the file
Namespace → named ✅ Converts import * as X to import { a, b } when only specific members are used
Type-only imports ✅ Converts import { X } to import type { X } when X is only used as a type
Unused functions ✅ Finds non-exported functions with zero references
Unused classes ✅ Finds non-exported classes with zero references
Unused variables ✅ Finds non-exported variables with zero references
Unused types/interfaces ✅ Finds non-exported type aliases and interfaces with zero references
Unused exports ⚠️ Detects exported symbols not imported by any other file (manual review)
Unreferenced files ⚠️ Detects files not imported anywhere in the project (manual review)
Unused dependencies ⚠️ Detects npm packages in package.json not imported in source (manual review)

Commands

Open the Command Palette (Cmd+Shift+P / Ctrl+Shift+P) and search for:

Command Description
Import Optimizer: Analyze Workspace Full project analysis — scans every file
Import Optimizer: Analyze Current File Analyze only the active editor file
Import Optimizer: Fix All Issues in Current File Apply all safe auto-fixes in the current file
Import Optimizer: Fix All Safe Issues in Workspace Apply all safe auto-fixes across the whole project
Import Optimizer: Clear Diagnostics Clear all analysis results

How It Works

AST-First Approach

Every analysis is done via the TypeScript Compiler API (through ts-morph). No regex guessing, no string matching. The extension:

  1. Loads the project using tsconfig.json (or auto-discovers files)
  2. Builds a file dependency graph from import/export declarations
  3. Builds a symbol usage graph (references per identifier)
  4. Identifies candidates: unused imports, functions, classes, variables, types, exports
  5. Runs safety validation before marking anything as fixable
  6. Presents results as diagnostics (squiggly lines), quick fixes, and a tree view

Safety Validation

Before marking any symbol for removal, the extension checks for:

  • Dynamic imports: require(variable), import(expr)
  • eval() usage: If eval is present, all symbols are preserved
  • Decorators: Decorated classes/methods are preserved (NestJS, Angular, etc.)
  • Reflect API: If Reflect metadata is used, decorated symbols are kept
  • Side-effect imports: import "polyfill", CSS imports, etc. are preserved
  • Framework conventions: Next.js pages/routes, NestJS modules/services, Angular components, test files, config files, index files
  • Global assignments: window.X, globalThis.Y

If uncertain → the symbol is kept. Conservative by design.

Settings

Setting Default Description
importOptimizer.analyzeOnSave false Automatically analyze on file save
importOptimizer.autoFixOnSave false Auto-fix unused imports on save
importOptimizer.ignorePaths ["**/node_modules/**", ...] Glob patterns to ignore
importOptimizer.preserveSideEffectImports true Keep side-effect imports
importOptimizer.convertToTypeImports true Convert type-only imports to import type
importOptimizer.optimizeNamespaceImports true Narrow import * to named imports
importOptimizer.detectUnusedExports true Find exports not imported elsewhere
importOptimizer.detectUnusedDependencies true Find unused npm dependencies
importOptimizer.detectUnreferencedFiles true Find files not imported anywhere
importOptimizer.safetyLevel "strict" strict / moderate / aggressive

UI

  • Diagnostics: Issues show as squiggly underlines with Unnecessary tag (faded text)
  • Quick Fixes: Lightbulb actions appear on hover — click to fix
  • Tree View: "Import Optimizer" panel in the Explorer sidebar shows all findings grouped by category
  • Status Bar: Click the "⟡ Import Optimizer" item in the status bar to trigger analysis

Getting Started

# Clone and install
git clone <repo>
cd import-optimizer
npm install

# Compile
npm run compile

# Press F5 in VS Code to launch the Extension Development Host

Architecture

src/
├── extension.ts                    # VS Code entry point
├── types.ts                        # Shared type definitions
├── utils.ts                        # Configuration, patterns, helpers
├── analyzer/
│   ├── projectAnalyzer.ts          # Main orchestrator
│   ├── importAnalyzer.ts           # Per-file import analysis
│   ├── symbolAnalyzer.ts           # Per-file symbol usage analysis
│   ├── exportAnalyzer.ts           # Cross-file export analysis
│   ├── fileReferenceAnalyzer.ts    # File dependency graph
│   ├── dependencyAnalyzer.ts       # npm dependency analysis
│   └── safetyValidator.ts          # Dynamic usage / safety checks
├── providers/
│   ├── diagnosticsProvider.ts      # Squiggly lines in editor
│   ├── codeActionProvider.ts       # Quick fix lightbulbs
│   └── treeViewProvider.ts         # Results panel tree view
└── commands/
    └── commands.ts                 # Command handlers

License

MIT

  • Contact us
  • Jobs
  • Privacy
  • Manage cookies
  • Terms of use
  • Trademarks
© 2026 Microsoft