Skip to content

Add ExitWorktree tool to complement EnterWorktree #29436

@Neffelian

Description

@Neffelian

Problem

EnterWorktree changes Claude Code's working directory into a git worktree, but there is no corresponding ExitWorktree tool to return to the main repository mid-session.

This means:

  • After merging a worktree branch back to the main repo, the session is stuck with its cwd inside the worktree
  • The worktree can't be cleaned up mid-session because removing it while the cwd is inside it breaks the shell
  • cd via Bash doesn't work — the cwd resets back to the worktree after each command
  • The only option is to leave cleanup for session exit, which is limiting if you want to do more work in the main repo

Expected behavior

An ExitWorktree tool (or similar mechanism) that:

  1. Changes the working directory back to the original repository
  2. Optionally removes the worktree (with a keep parameter)

This would allow entering and exiting worktrees at will within a single session, which is important for workflows that involve multiple sequential tasks.

Current workaround

Leave the worktree cleanup for the session exit prompt, but this prevents further work in the main repo directory during the same session.

Image (I hope this is ok!)

Metadata

Metadata

Assignees

No one assigned

    Labels

    duplicateThis issue or pull request already exists

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions