Skip to content

Feature request: Built-in git worktree lifecycle management #1613

Description

@arunsathiya

Copilot CLI should be able to create and destroy git worktrees as part of its normal problem-solving workflow. When working on a task, Copilot could spin up a dedicated worktree, do the work in isolation, and clean it up when done. This would make it safer and cleaner to work on multiple tasks in parallel without risk of context or file conflicts between sessions.

Activity

  1. travisbader commented on Mar 15, 2026

    @travisbader

    In addition to native worktree lifecycle management, I'd like to request feature parity with Claude Code's WorktreeCreate and WorktreeRemove hook events (Claude Code hooks reference).

    Claude Code fires these hooks at the worktree level — separate from sessionStart — specifically when a worktree is created or removed. Common use cases include running git lfs pull and npm install (or equivalent) in the new worktree immediately after creation, and cleanup on removal. Without a dedicated WorktreeCreate hook, there's no reliable way to initialize a worktree's environment before the agent starts touching files.
    For real-world examples of this pattern in action, see:

  2. added
    area:toolsBuilt-in tools: file editing, shell, search, LSP, git, and tool call behavior
    area:sessionsSession management, resume, history, session picker, and session state
    and removed on Apr 16, 2026
  3. added theissue type on Apr 16, 2026
  4. springcomp commented on Jun 9, 2026

    @springcomp

    Without a dedicated WorktreeCreate hook, there's no reliable way to initialize a worktree's environment before the agent starts touching files.

    Claude supports a .worktreeinclude file that allows to do just that:

    • copy .gitignored files to the new worktree.
    • symlink folders like node_modules to the new worktree.
    • etc.
  5. jacobcarpenter-logos commented on Jul 29, 2026

    @jacobcarpenter-logos

    We were just discussing this issue again today, and I happened to notice in the settings dialog of the Github Copliot App (not the CLI), it does mention support for a .worktreeinclude file. I'm struggling to find online documentation that supports this, but seems worth trying.

    Image
  6. kvnloo commented on Sep 27, 2026

    @kvnloo

    A native implementation would benefit from treating a worktree as a managed resource with an explicit lifecycle rather than just running git worktree add/remove.

    Something like:

    creating -> initializing -> ready -> dirty/clean -> retiring -> removed

    with receipts for branch, base SHA, path, setup hooks, and cleanup decision.

    The safety rule I would strongly preserve: never automatically delete a dirty/unmerged worktree just because the agent thinks the task is done. Cleanup should require a proven clean/merged state or explicit user approval.

    WorktreeCreate/WorktreeRemove hooks then fit naturally around the state transitions and can handle dependencies, ignored files, ports, etc.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    area:sessionsSession management, resume, history, session picker, and session statearea:toolsBuilt-in tools: file editing, shell, search, LSP, git, and tool call behavior

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions