Repository navigation
fix(wt-switch-create): leave the current worktree session before entering by path - #4714
Merged
Merged
Conversation
…ring by path
A session already in a worktree can enter only under its repo's
.claude/worktrees/, so step 3's EnterWorktree({path}) always failed there
and the cd recovery left Claude Code tracking the old worktree. Step 3 now
calls ExitWorktree({action: "keep"}) first, which keeps the old worktree on
disk and makes the next entry a first entry.
Closes #4713
worktrunk-bot
commented
Nov 6, 2026
worktrunk-bot
left a comment
Collaborator
Author
There was a problem hiding this comment.
One gap in the stash handoff that the new step 3 ordering opens up (inline). I'm pushing the fix to this branch.
…de the new worktree Waiting to pop until the session reaches the new worktree left the stash unpopped when step 3 stopped (wt failure, unreachable repo, denied entry), so the handback ended with the user's uncommitted work hidden in the stash.
This was referenced Nov 6, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
A session already in a worktree can enter only a worktree under its repo's
.claude/worktrees/, so/wt-switch-createstep 3'sEnterWorktree({path})always hit the managed-location rejection there. Thecdrecovery then left Claude Code tracking the old worktree: its Bash guard, session exit, andExitWorktreeall kept acting on it. Step 3 now callsExitWorktree({action: "keep"})before entering. That keeps the old worktree on disk and makes the entry a first entry. With no repo argument the session enters from where leaving put it, with nocd. With a repo argument,cd <repo>follows as before.This applies the patch from the issue verbatim:
skills/wt-switch-create/SKILL.mdandrationale.md, plus theplugins/worktrunk/skills/mirror regenerated bytest_docs_are_in_sync. That includes the follow-on edits: the handback names the worktree the session left,git stash popwaits until the session is in the new worktree, Cleanup covers the worktree that was left, and rationale.md corrects the rejection list and the Known limits entry.Verification: the behavior depends on Claude Code's live
EnterWorktree/ExitWorktreetools, which CI can't run. The evidence is the issue's live checks against Claude Code 2.1.316 and wt v0.81.0, including a headless A/B where every already-in-a-worktree scenario went from 0/3 (0/2 for--worktree) to 3/3 and plain sessions stayed 3/3. Locally, the patch applied cleanly atd022f7683andtest_docs_are_in_syncpasses with the regenerated mirror.Closes #4713 — automated triage