A fast, reliable CLI tool to detect and safely clean up unused files and imports in your JS/TS projects (React, Next.js, React Native, Node.js).
CodePrune parses your imports and builds a complete dependency graph starting from your entry points, flagging any source file that is completely unreachable.
Install globally via npm:
npm install -g codepruneUse the init command to generate a config file. It auto-detects your framework from package.json:
codeprune init # Auto-detect with interactive selection
codeprune init --yes # Auto-detect and create config automatically
codeprune init react # Use specific frameworkThis creates a codeprune.config.json with sensible defaults for your project.
Supported frameworks: Next.js, React, React Native, Vue, Svelte, Express, Node.js
Once installed globally, you can use codeprune in any local JS/TS project.
In the root directory of the project you want to scan, create a codeprune.config.json file. This tells CodePrune where to look and where your dependency graph starts.
For Next.js:
{
"exclude": ["node_modules", ".next", "out", "public"],
"extensions": [".js", ".ts", ".tsx", ".jsx"],
"entry": ["app", "pages", "src"]
}For React (Vite/Create React App):
{
"exclude": ["node_modules", "dist", "build"],
"extensions": [".js", ".ts", ".tsx", ".jsx"],
"entry": ["src/main.tsx", "src/index.tsx"]
}For React Native:
{
"exclude": ["node_modules", "android", "ios", ".expo"],
"extensions": [".js", ".ts", ".tsx", ".jsx"],
"entry": ["App.tsx", "index.js"]
}Run the following command in your terminal:
codepruneYou can also output the results in JSON format (ideal for CI/CD pipelines):
codeprune --jsonOnce you have run the scanner, CodePrune will output a list of unused files.
The CLI groups files into two categories:
- ❌ Unused Files: Files that are definitely not imported anywhere in the graph.
⚠️ Possibly Unused: Files that are only referenced via dynamic imports (e.g.,import('./MyComponent')). Static analysis cannot confidently guarantee these are unused, so verify manually!
CodePrune features a built-in safe delete mode. Rather than permanently deleting your files immediately, it moves them to a local trash folder.
Run the scan with the delete flag:
codeprune --deleteThis will automatically:
- Scan your project.
- Identify the
❌ Unused Files. - Move all unused files out of your workspace and into a
.codeprune-trashfolder in your project's root.
For more control over which files to delete, use the interactive mode:
codeprune --delete --interactiveThis opens an interactive file selector where you can:
| Key | Action |
|---|---|
↑ / ↓ |
Navigate through files |
Space |
Toggle file selection |
Tab |
Select/deselect all files |
Enter |
Delete selected files |
Escape |
Cancel and exit |
Files are moved to .codeprune-trash for safe recovery.
What to check after running:
- Run your build/dev server (
npm run dev) to ensure nothing broke. - If a file was accidentally flagged as unused and your app broke, restore it using
codeprune restore --allorcodeprune restore --file "path/to/file" - Once you verify your project builds fine, you can permanently delete the
.codeprune-trashfolder.
Use the restore command to recover files from .codeprune-trash:
codeprune restore # List files in trash
codeprune restore --all # Restore all files
codeprune restore --file src/components/Button.tsx # Restore specific fileCodePrune can also clean up unused imports, variables, functions, classes, and more:
codeprune --fix-importsThis will:
- Remove unused imports - Identifies imports that are never used in the file and removes them
- Remove unused declarations - Removes unused variables, functions, classes, interfaces, and type aliases
- Organize imports - Groups and sorts imports (external modules first, then relative imports, alphabetically sorted)
You can combine with other options:
codeprune --fix-imports --delete| Option | Type | Description |
|---|---|---|
include |
string[] |
Directories to recursively scan for source files. |
exclude |
string[] |
Directories to completely ignore (e.g., node_modules). |
extensions |
string[] |
File extensions to track (.js, .tsx, .ts, etc.). |
entry |
string[] |
The starting points of your app. Can be specific files (src/index.js) or directories (src/pages). |
ignore |
string[] |
Specific folders/patterns to skip within included directories. |
codeprune help # Show available commands and optionscodeprune init # Auto-detect framework (interactive)
codeprune init --yes # Auto-detect and create config automatically
codeprune init react # Use specific framework
codeprune init -o custom.json # Custom output pathThe init command auto-detects your framework from:
package.jsondependencies (next, react, vue, svelte, express, etc.)- Config files (next.config.js, vite.config.ts, svelte.config.js)
Supported frameworks: next, react, react-native, node, vue, svelte, express
codeprune restore # List files in trash
codeprune restore --all # Restore all files
codeprune restore -f <file> # Restore specific file| Option | Alias | Description |
|---|---|---|
--config |
-c |
Custom config file path |
--json |
-j |
Output results in JSON format |
--delete |
-d |
Move unused files to .codeprune-trash |
--interactive |
-i |
Interactive file selection (use with --delete) |
--fix-imports |
-f |
Remove unused imports and organize imports |