Repository navigation
Description
Describe the feature or problem you'd like to solve
Copilot CLI retains a separate Git worktree for each session, even after the session becomes inactive. These worktrees accumulate duplicated build outputs, project-local caches, virtual environments, and generated artifacts. On my machine, Copilot session data reached approximately 58 GiB, with inactive worktrees consuming several gigabytes each. I want session history and checkpoints to remain available without retaining every physical worktree indefinitely. Copilot CLI should safely release inactive worktrees and recreate or reuse a clean worktree when a session resumes. Current, active, named, or pinned sessions should remain protected.
Proposed solution
Problem
Copilot CLI sessions can retain separate Git worktrees indefinitely. Although linked worktrees share the Git object database, each worktree accumulates its own build outputs, project-local caches, virtual environments, and generated artifacts.
On my machine:
~/.copilotused approximately 59 GiBsession-stateaccounted for 58 GiB- Seven large inactive sessions used 42.7 GiB
- Their
build/and.gradle/directories alone used 28.7 GiB - Individual sessions consumed between 3.4 and 8.7 GiB
Deleting sessions is not always appropriate because users may want to retain conversation history, checkpoints, and resumability.
Proposal
Decouple session retention from worktree retention.
When a session becomes inactive or is closed, Copilot CLI could:
- Preserve its history, branch, commit SHA, checkpoints, and metadata.
- Release its physical worktree when it is safe.
- Recreate or lease a clean worktree when the session resumes.
Optionally, Copilot CLI could maintain a small repository-specific pool of reusable worktrees instead of creating a new worktree for every session.
Safety requirements
A worktree should be eligible for release or reuse only when:
- It is not owned by an active session.
- No process is using it as its working directory.
- It has no staged, tracked, or untracked user changes.
- No merge, rebase, bisect, cherry-pick, or revert is active.
- It is not locked, missing, or marked as prunable.
- Its submodules are clean.
- The target branch is not checked out in another worktree.
Acquisition should use an atomic lease to prevent concurrent sessions from selecting the same worktree.
If validation or reassignment fails, Copilot CLI should quarantine the worktree rather than force-cleaning it.
Suggested controls
Potential commands:
/session worktree status
/session worktree release [session-id]
/session worktree cleanup --dry-run
Potential settings:
{
"worktreeRetentionDays": 7,
"worktreePoolSizePerRepository": 1,
"preserveNamedSessionWorktrees": true
}
Named, pinned, current, and active sessions should be protected by default.
Build-cache consideration
Blindly retaining ignored directories such as build/ can introduce stale outputs across branches.
A safer approach would combine disposable or reusable worktrees with supported shared caches, such as Gradle's content-addressed build cache.
The initial implementation could release and recreate worktrees without retaining generated outputs. Warm-cache reuse could be added separately after correctness validation.
Expected benefits
• Significant reduction in long-term disk usage
• Session history retained without retaining full build environments
• Fewer duplicate virtual environments and project-local caches
• Faster startup and builds when safe shared caches are enabled
• Less need to delete important sessions manually
Would the team consider adding independent worktree retention or a conservative reusable-worktree pool?
Example prompts or workflows
No response
Additional context
No response
Activity