Worktree lifecycle: auto-cleanup or reuse across sessions

Resolved 💬 3 comments Opened Apr 5, 2026 by gdsajin-byte Closed Apr 8, 2026

Problem

When using Claude Code via the Desktop App, every new session automatically creates a fresh git worktree under .claude/worktrees/. This leads to several issues for teams that manage git directly:

1. Worktrees accumulate and are never cleaned up

Each session creates a new worktree with a random name (e.g., inspiring-nobel, happy-tesla). When the session ends, the worktree is left behind. Over days/weeks, .claude/worktrees/ fills up with orphaned directories.

2. No option to reuse an existing worktree

There is no way to tell Claude Code "use this existing worktree" or "continue in the same worktree as last session." Every session starts fresh.

3. Incompatible with single-branch + submodule workflows

Projects that use a single main branch with git submodules do not benefit from worktree isolation. The worktree creates a new branch each time, which conflicts with the intended git workflow. Submodules also are not initialized in the new worktree, breaking the project structure.

4. Multi-agent setups are affected

When running multiple Claude Code agents against the same repository, each agent creating its own worktree clone adds unnecessary disk usage and git state complexity.

Suggested improvements

  • Auto-cleanup: Remove worktrees when the session ends (or offer a prompt to keep/remove)
  • Reuse option: Allow sessions to attach to an existing worktree instead of always creating a new one
  • Opt-out: Provide a setting to disable automatic worktree creation entirely, allowing direct work on the local branch
  • Worktree GC command: A built-in command to list and prune stale worktrees (e.g., /worktree cleanup)

Environment

  • Claude Code Desktop App (macOS)
  • Multi-agent workflow with shared repository
  • Single-branch (main) + git submodule structure

View original on GitHub ↗

This issue has 3 comments on GitHub. Read the full discussion on GitHub ↗