The cleanup command identifies and removes worktrees that haven't been used recently. By default, it performs a dry run -- showing what would be deleted without actually deleting anything.
Usage
bash
owt cleanup [OPTIONS]Options
| Option | Description |
|---|---|
--force | Actually delete stale worktrees (without this flag, it's a dry run) |
--days <n> | Days threshold for stale detection (default: 14) |
--json | Output results in JSON format |
Examples
Preview Stale Worktrees (Dry Run)
bash
owt cleanupOutput:
Dry run - no worktrees will be deleted.
Stale worktrees (>14 days inactive):
- feature/old-feature (21 days inactive)
- bugfix/ancient-fix (45 days inactive)
Protected worktrees (skipped):
- feature/wip (has uncommitted changes)
- feature/local (has unpushed commits)
Run with --force to delete stale worktrees.Actually Delete Stale Worktrees
bash
owt cleanup --forceCustom Age Threshold
bash
# Clean worktrees inactive for more than 7 days
owt cleanup --force --days 7
# Only clean very old worktrees (30+ days)
owt cleanup --force --days 30JSON Output
bash
owt cleanup --jsonOutput:
json
{
"dry_run": true,
"threshold_days": 14,
"stale_worktrees": [
{
"name": "feature/old-feature",
"days_inactive": 21,
"has_uncommitted_changes": false
}
],
"protected_worktrees": [
{
"name": "feature/wip",
"reason": "Has uncommitted changes"
}
]
}Protection Rules
Worktrees are protected from cleanup (even with --force) if they have:
- Uncommitted changes -- Unsaved work would be lost
- Unpushed commits -- Local commits not yet pushed to remote
The main worktree is never cleaned up regardless of flags.
What Gets Deleted
For each stale worktree that passes protection checks:
- tmux session -- Killed if it exists
- Worktree directory -- Completely removed
- Git worktree reference -- Pruned from git
- Status tracking -- Cleared
The git branch is NOT deleted. To delete branches separately:
bash
git branch -d feature/old-branchUse Cases
Weekly Maintenance
bash
# Preview what's stale
owt cleanup
# If it looks good, actually clean up
owt cleanup --forceScripting and CI
bash
# Use JSON output for automation
owt cleanup --json | jq '.stale_worktrees | length'See Also
owt delete-- Delete a specific worktreeowt list-- List all worktrees