I built this because I got really irritated dealing with codebases that grew too large and accumulated tons of dead code. When you're working on a big project, it's hard to know which exports are actually being used and which ones are just sitting there taking up space.
npm install -g ghost-hunterOr run it directly:
npx ghost-hunterRun it in your project directory:
ghost-hunterIt automatically reads your tsconfig.json to understand your project structure.
ghost-hunter --project ./packages/core/tsconfig.jsonFor CI/CD integration or programmatic consumption:
ghost-hunter --format jsonGhost-Hunter finds unused:
- Named exports (
export const,export function,export class) - Default exports (
export default) - Type exports (
export interface,export type) - Enum exports (
export enum)
🔍 Found 5 unused exports in 2 files:
src/utils/helpers.ts
⚠️ formatDate (line 45)
⚠️ parseDate (line 67)
src/components/Button.tsx
⚠️ ButtonProps [default] (line 12)
⚠️ ButtonVariant (line 8)
Total files scanned: 47
Total unused exports: 5
- Loads your TypeScript project using
ts-morph - Scans all
.tsand.tsxfiles - Maps every export in your codebase
- Maps every import in your codebase
- Compares them to find exports that are never imported
- Shows you the results grouped by file
src/
├── core/
│ ├── errors.ts # Custom error classes
│ └── ProjectLoader.ts # tsconfig.json parser
├── analysis/
│ ├── ExportMapper.ts # Extract all exports
│ ├── ImportMapper.ts # Extract all imports
│ ├── GraphBuilder.ts # Build usage graph
│ └── Analyzer.ts # Orchestration layer
├── reporting/
│ └── Reporter.ts # Format output
├── types.ts # Type definitions
└── cli.ts # CLI entry point
Ghost-Hunter uses efficient data structures for O(1) lookup performance:
Map<string, ExportSignature>for export trackingSet<string>for import existence checks
0- No unused exports found1- Unused exports detected2- Configuration error3- Analysis error4- Unexpected error
- Only analyzes files included in your
tsconfig.json - Doesn't detect dynamic imports using string concatenation
- Doesn't know if external packages are using your exports
- Won't catch usage through reflection or runtime shenanigans
MIT