-
Notifications
You must be signed in to change notification settings - Fork 9
Open
Description
Problem
Worktrees accumulate silently over time and are never automatically cleaned up. Each worktree can consume 1-12 GB of disk space. After several sessions, users can end up with many orphaned worktrees from completed/abandoned work (branches deleted from remote, sessions no longer active, etc.).
Today, cleanup requires the user to manually run git worktree list, cross-reference against active sessions, and git worktree remove each stale one.
Proposed Solution
Add automatic worktree cleanup logic, triggered on app startup or new session creation:
- List all worktrees on disk under
~/.polypilot/worktrees/ - Cross-reference against active sessions (check
_sessionsdictionary andOrganization.Sessions) - Identify orphaned worktrees — those with no active session pointing to them
- Classify orphans by risk level:
- Safe to auto-remove: Clean (no dirty files) + remote branch gone (
[gone]tracking status) - Prompt before removing: Has uncommitted changes or untracked files
- Keep: Has active session or running processes
- Safe to auto-remove: Clean (no dirty files) + remote branch gone (
- Auto-remove safe orphans (or at minimum, surface them to the user with an option to clean up)
- Run
git worktree pruneafter cleanup to remove stale git refs
Additional Context
RepoManager already has RemoveWorktreeAsync — this work is primarily about adding the discovery/reconciliation logic and hooking it into the session lifecycle.
Key files:
PolyPilot/Services/RepoManager.cs— worktree creation/removalPolyPilot/Services/CopilotService.cs— session creation (CreateSessionAsync)
Reactions are currently unavailable