Overview
Theprune command intelligently analyzes dependency folders and removes only those that are truly safe to delete. Unlike sweep, which lets you choose what to delete, prune uses a staleness score (0-100) to automatically determine what should be removed.
This is the safest automated cleanup option - perfect for regular maintenance without risking active projects.
Usage
Flags
Root path to scan. Defaults to the current directory. Scans recursively through all subdirectories.
Minimum staleness score required to prune (0-100). Only folders with scores at or above this threshold are deleted. Higher values = more conservative.
Only analyze and list folders with their scores - don’t delete anything. Use this to preview what would be pruned.
Display help information for the prune command.
Examples
Prune with Default Threshold
Remove folders with staleness score ≥ 50:Preview with Dry Run
See what would be pruned without deleting:Conservative Pruning (High Threshold)
Only remove folders with very high staleness scores:Aggressive Pruning (Low Threshold)
Remove more folders by lowering the threshold:Prune Specific Directory
Analyze and prune a specific path:Preview Before Pruning
Always preview first on important directories:Staleness Scoring System
Each folder is assigned a score from 0 to 100 based on multiple heuristics:| Score Range | Reason | Description |
|---|---|---|
| 90-95 | Orphan folder (no lockfile) | Dependency folder exists but no lockfile found - likely abandoned |
| 90 | Build cache | Re-generable folders like .next, .svelte-kit, dist, build |
| 80 | Lockfile very stale (90+ days) | Lockfile hasn’t been modified in over 3 months |
| 70 | Lockfile stale (60 days) | Lockfile hasn’t been modified in 2-3 months |
| 60 | Lockfile moderately stale (45 days) | Lockfile hasn’t been modified in 1.5-2 months |
| 45 | Lockfile somewhat stale (30 days) | Lockfile modified within last month |
| 20 | Active project | Lockfile recently modified (within 30 days) |
| 15 | Uncommitted changes | Lockfile has uncommitted changes in git |
Folders with scores below the threshold are automatically skipped - they won’t be deleted.
How Prune Works
- Scans recursively - Finds all dependency folders
- Analyzes each folder - Checks for:
- Presence of lockfile (package-lock.json, Cargo.lock, etc.)
- Lockfile modification time (staleness)
- Git status (uncommitted changes)
- Folder type (build cache vs. dependencies)
- Calculates score - Assigns a staleness score (0-100)
- Compares to threshold - Only folders with score ≥ threshold are deleted
- Deletes selected folders - Removes folders that meet the threshold (unless —dry-run)
- Reports results - Shows what was deleted and how much space was freed
Scoring Heuristics Details
Orphan Detection
If a dependency folder exists but no corresponding lockfile is found, it scores 95 (very high). This usually means:- The lockfile was deleted
- The project was abandoned mid-setup
- The folder is left over from a failed installation
Build Cache Detection
Folders like.next, .svelte-kit, dist, build score 90 because:
- They’re re-generated by build tools
- Safe to delete anytime
- Can always be rebuilt from source
Lockfile Staleness
The time since the lockfile was last modified determines staleness:- 90+ days → score 80 (very stale)
- 60-90 days → score 70 (stale)
- 45-60 days → score 60 (moderately stale)
- 30-45 days → score 45 (somewhat stale)
- Less than 30 days → score 20 (active)
Git Integration
If the lockfile has uncommitted changes (detected via git), the score drops to 15 because:- The project is actively being worked on
- Changes haven’t been committed yet
- High risk of disrupting active work
Threshold Recommendations
| Threshold | Use Case | What Gets Deleted |
|---|---|---|
| 80-100 | Very conservative | Only orphans, build caches, and very stale projects (90+ days) |
| 60-79 | Conservative | Orphans, build caches, and stale projects (45+ days) |
| 50 (default) | Balanced | Orphans, build caches, and moderately stale projects (30+ days) |
| 30-49 | Aggressive | Everything except very active projects |
| 0-29 | Very aggressive | Almost everything (use with caution) |
Common Use Cases
Regular Maintenance
Run prune weekly to keep your workspace clean:Safe Cleanup Before Backup
Remove stale folders before backing up:Clean Up Old Projects
Focus on an archive directory:Preview Impact
See what would be deleted before committing:Conservative Cleanup
Only remove extremely stale folders:Aggressive Space Reclaim
When you really need disk space:Prune vs. Sweep
| Feature | prune | sweep |
|---|---|---|
| Selection method | Automatic (score-based) | Manual (interactive UI) |
| Safety | Very safe (skips active projects) | Safe (you choose what to delete) |
| Speed | Fast (automated) | Slower (requires interaction) |
| Use case | Regular maintenance | One-time cleanups |
| Dry-run | Yes (--dry-run) | No (use list instead) |
| Customization | Threshold parameter | Interactive selection |
| Best for | Automation, cron jobs | Manual cleanup sessions |
Use
prune for regular automated cleanup. Use sweep when you want full control over what gets deleted.Automation Example
Add to your shell profile for weekly cleanup:Safety Features
- Automatic skipping of active projects - Low scores protect recent work
- Git integration - Detects uncommitted changes
- Dry-run mode - Preview before deleting
- Threshold control - Adjust aggressiveness to your comfort level
- Smart scoring - Multiple heuristics prevent false positives
- Graceful error handling - Continues even if some folders fail
Limitations
- Git dependency - Uncommitted change detection requires git
- Time-based only - Doesn’t detect compile errors or corruption (use
repairfor that) - Conservative scoring - May miss some folders that could be safely deleted
- Lockfile required - Relies on lockfile timestamps for staleness detection
Related Commands
list- Preview all folders without scoringsweep- Manual selection and deletionrepair- Fix corrupted dependencies- Default mode - Refresh a single project