Skip to content

fix(wt-switch-create): leave the current worktree session before entering by path - #4714

Merged
max-sixty merged 2 commits into
mainfrom
fix/issue-4713
Nov 6, 2026
Merged

max-sixty merged 2 commits into
mainfrom
fix/issue-4713

Conversation

@worktrunk-bot

Copy link
Copy Markdown
Collaborator

A session already in a worktree can enter only a worktree under its repo's .claude/worktrees/, so /wt-switch-create step 3's EnterWorktree({path}) always hit the managed-location rejection there. The cd recovery then left Claude Code tracking the old worktree: its Bash guard, session exit, and ExitWorktree all kept acting on it. Step 3 now calls ExitWorktree({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 no cd. With a repo argument, cd <repo> follows as before.

This applies the patch from the issue verbatim: skills/wt-switch-create/SKILL.md and rationale.md, plus the plugins/worktrunk/skills/ mirror regenerated by test_docs_are_in_sync. That includes the follow-on edits: the handback names the worktree the session left, git stash pop waits 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/ExitWorktree tools, 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 at d022f7683 and test_docs_are_in_sync passes with the regenerated mirror.

Closes #4713 — automated triage

…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 worktrunk-bot added the automated-fix Automated CI fix label Nov 6, 2026

@worktrunk-bot worktrunk-bot left a comment

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One gap in the stash handoff that the new step 3 ordering opens up (inline). I'm pushing the fix to this branch.

Comment thread skills/wt-switch-create/SKILL.md Resolved
…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.
@max-sixty
max-sixty merged commit 9bd2b63 into main Nov 6, 2026
36 checks passed
@max-sixty
max-sixty deleted the fix/issue-4713 branch November 6, 2026 05:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

automated-fix Automated CI fix

Projects

None yet

Development

Successfully merging this pull request may close these issues.

/wt-switch-create never re-roots a session that is already in a worktree

2 participants