Skip to content

Deleting a session in the Copilot app does not remove its git worktree (folder, registration, and branch left behind) #4383

Description

@andy505050

Describe the bug

Deleting a project session from the Copilot desktop app removes the session from the session list, but its git worktree is left behind entirely:

  • the worktree folder under copilot-worktrees/<project>/<slug> still exists on disk
  • the worktree is still registered in the main repo (git worktree list shows it)
  • the session branch still exists

This is inconsistent with archive_session, whose documented behavior is to remove the worktree, and there is no documentation stating that delete keeps the worktree. Over time this accumulates orphaned worktrees and branches (see #3675).

Affected version

GitHub Copilot CLI 1.0.78

Steps to reproduce the behavior

  1. Configure a local project whose repo lives inside WSL (\\wsl.localhost\Ubuntu\home\...).
  2. Create a new session for the project (a worktree is created under copilot-worktrees/<project>/<slug>).
  3. Delete the session from the app.
  4. Session disappears from the list, but the worktree folder, git worktree list entry, and branch all remain.

Reproduced twice with different sessions.

Expected behavior

Deleting a session should remove its worktree (folder + git registration) and ideally the session branch, or at minimum document the behavior and offer a cleanup action. Related: #3675, #4246.

Additional context

On the first attempt, deletion also surfaced a partial-failure error caused by Windows git's ownership check on WSL UNC paths:

Failed to delete session: git ["--no-optional-locks", "status", "--porcelain=v1", "-b", "-M", "-uall"] failed:
fatal: detected dubious ownership in repository at '//wsl.localhost/Ubuntu/home/.../projects/copilot-worktrees/...'

Even after that error, the session record was removed while cleanup was skipped — a partial delete leaving inconsistent state. After adding safe.directory = //wsl.localhost/Ubuntu/home/.../projects/* (git 2.53), deletion completes without error but the worktree is still not cleaned up, so the missing cleanup is not caused by the ownership check.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions