Skip to content

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 ​

OptionDescription
--forceActually delete stale worktrees (without this flag, it's a dry run)
--days <n>Days threshold for stale detection (default: 14)
--jsonOutput results in JSON format

Examples ​

Preview Stale Worktrees (Dry Run) ​

bash
owt cleanup

Output:

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 --force

Custom 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 30

JSON Output ​

bash
owt cleanup --json

Output:

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:

  1. tmux session -- Killed if it exists
  2. Worktree directory -- Completely removed
  3. Git worktree reference -- Pruned from git
  4. Status tracking -- Cleared

The git branch is NOT deleted. To delete branches separately:

bash
git branch -d feature/old-branch

Use Cases ​

Weekly Maintenance ​

bash
# Preview what's stale
owt cleanup

# If it looks good, actually clean up
owt cleanup --force

Scripting and CI ​

bash
# Use JSON output for automation
owt cleanup --json | jq '.stale_worktrees | length'

See Also ​