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:
- Changes the working directory back to the original repository
- 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.
(I hope this is ok!)
Problem
EnterWorktreechanges Claude Code's working directory into a git worktree, but there is no correspondingExitWorktreetool to return to the main repository mid-session.This means:
cdvia Bash doesn't work — the cwd resets back to the worktree after each commandExpected behavior
An
ExitWorktreetool (or similar mechanism) that:keepparameter)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.