Comprehensive codebase cleanup analysis with interactive review
Performs comprehensive codebase cleanup analysis to identify unused imports, dead code, assets, dependencies, and configurations.
/plugin marketplace add Linaqruf/cc-plugins/plugin install codebase-cleanup@cc-plugins[scope: all | imports | deadcode | assets | deps | configs]This command orchestrates comprehensive cleanup analysis for TypeScript/JavaScript codebases. It detects unused imports, dead code, orphaned assets, unused dependencies, and obsolete configurations.
First, verify this is a JavaScript/TypeScript project:
# Check for package.json
test -f package.json && echo "Found package.json"
If no package.json found, inform the user:
This doesn't appear to be a JavaScript/TypeScript project.
The /cleanup command requires a package.json file.
Would you like to:
1. Specify a different directory
2. Continue anyway (limited analysis)
3. Cancel
If an argument was provided, validate it first.
Valid scopes:
all - Run all analyzersimports - Unused imports onlydeadcode - Dead code onlyassets - Unused assets onlydeps - Dependencies onlyconfigs - Configuration cleanup onlyMultiple scopes: Comma-separated values are allowed (e.g., imports,deadcode)
Invalid argument handling: If an unrecognized scope is provided, inform the user:
Unknown scope: "[provided-value]"
Valid scopes are:
- all, imports, deadcode, assets, deps, configs
You can also combine scopes: "imports,deadcode"
Would you like to:
1. Choose from valid scopes
2. Run full analysis (all)
3. Cancel
If no argument provided, ask the user:
What would you like to clean up?
1. **all** - Run all analyzers (imports, dead code, assets, dependencies, configs)
2. **imports** - Unused, duplicate, and circular imports
3. **deadcode** - Unreachable code, unused functions and variables
4. **assets** - Unused images, CSS, fonts, and static files
5. **deps** - Unused npm packages, security issues, duplicates
6. **configs** - Unused env vars, obsolete config files, stale feature flags
You can also select multiple: "imports,deadcode" or "deps,configs"
Detect project characteristics:
# Framework detection
grep -l '"next"' package.json 2>/dev/null && echo "Next.js"
grep -l '"vite"' package.json 2>/dev/null && echo "Vite"
grep -l '"react"' package.json 2>/dev/null && echo "React"
grep -l '"vue"' package.json 2>/dev/null && echo "Vue"
grep -l '"svelte"' package.json 2>/dev/null && echo "Svelte"
# TypeScript detection
test -f tsconfig.json && echo "TypeScript"
# Source directory
test -d src && echo "src/"
test -d app && echo "app/"
test -d pages && echo "pages/"
Check for optional tools that enhance analysis:
# TypeScript compiler
npx tsc --version 2>/dev/null
# depcheck for dependency analysis
npx depcheck --version 2>/dev/null
# madge for circular dependencies
npx madge --version 2>/dev/null
# ts-prune for unused exports
npx ts-prune --version 2>/dev/null
Report which tools are available and suggest installing missing ones for better analysis.
Based on scope selection, perform the appropriate analysis:
imports:deadcode:assets:deps:configs:all:Run all of the above in sequence, then aggregate results.
Create a structured markdown report:
# Codebase Cleanup Report
Generated: [timestamp]
Project: [name from package.json]
Framework: [detected framework]
## Executive Summary
| Category | Issues Found | Est. Savings |
|----------|--------------|--------------|
| Unused Imports | X | - |
| Dead Code | X functions | ~Y LOC |
| Unused Assets | X files | Y MB |
| Unused Dependencies | X packages | Y MB |
| Config Issues | X items | - |
| **Total** | **N issues** | **~Z MB** |
## High Priority (Safe to Remove)
[Issues with high confidence - can be safely removed]
### Unused Imports
[List of files with unused imports and suggested fixes]
### Unused npm Packages
```bash
npm uninstall [packages...]
[List of files with sizes]
[Issues that need verification before removal]
[Functions with no callers but could be used dynamically]
[Exports with no importers but could be public API]
[Issues that require human judgment]
[Directories with dynamic loading patterns]
[Flags that have been enabled/disabled for extended periods]
### Step 7: Interactive Confirmation
Present actions to user:
Found 63 potential cleanup opportunities across 5 categories.
What would you like to do?
#### For "Fix all safe issues":
Present batch of changes:
The following changes will be made:
Imports (23 files):
Dependencies:
Assets:
Proceed? (y/n)
#### For "Review by category":
Go through each category one by one:
File: src/components/Button.tsx
useEffect from react importlodash importActions:
### Step 8: Apply Changes (If Approved)
For imports:
- Show diff of proposed changes
- Get confirmation before editing
For dependencies:
- Generate npm uninstall command
- Let user run it (don't auto-execute)
For assets:
- List files to delete with paths
- Get explicit confirmation before deletion
For configs:
- Show which lines to remove from .env files
- Let user make the changes
### Step 9: Summary
After any actions taken:
Actions completed:
Remaining issues:
Next steps:
## Error Handling
### No package.json
Error: No package.json found in current directory.
This command is designed for JavaScript/TypeScript projects. Please navigate to a project directory or specify the path.
### Large Codebase Warning
Note: This is a large codebase (500+ files). Analysis may take a few minutes.
Continue? (y/n)
### Missing Tools
Some analysis tools are not installed:
The analysis will continue with available tools. Results may be more limited.
Install missing tools? (npm install -g depcheck madge)
## Reference
For detailed patterns and examples, refer to:
- `${CLAUDE_PLUGIN_ROOT}/skills/cleanup-patterns/SKILL.md`
- `${CLAUDE_PLUGIN_ROOT}/skills/cleanup-patterns/references/`
- `${CLAUDE_PLUGIN_ROOT}/skills/cleanup-patterns/examples/`
## Agents
This command can delegate to specialized agents:
- `import-analyzer` - For deep import analysis
- `dead-code-detector` - For comprehensive dead code detection
- `asset-tracker` - For static asset tracking
- `dependency-auditor` - For npm package auditing
- `config-cleaner` - For configuration cleanup