feat(worktree): suggest reparenting when Claude cd's into a worktree#101
Merged
Conversation
Subscribe to Claude Code's CwdChanged hook and surface a bottom banner when the agent moves into a directory that belongs to a different worktree from the source tab's container. Accept reparents the source tab so the running pty follows; no respawn, no resume. Handles three transitions: registered worktree (reparent), unknown git worktree of a tracked project (attach then reparent), and inside the source tab's own worktree (no-op). Banner gates on the active tab so the "which tab is this about?" ambiguity stays closed.
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.
Summary
When Claude
cds into a worktree the source tab doesn't own, surface abottom-anchored banner asking whether to move the tab there. Accept
reparents the source tab so the running pty follows the cd — no respawn,
no
--resume. Useful when you tell Claude "make a worktree and workthere" and end up with the agent operating from a different cwd than the
tab that owns it.
claude-shim/limpid-hookwritesper-pane
{oldCwd, newCwd, updatedAt}records into a newcwd-eventsdirectory;
CwdEventTrackerwatches withDispatchSource(same shapeas the existing agent / session trackers).
RegisteredMatchenum distinguishesnoRegisteredWorktreeContains(fall through to agit worktree listshell-out for unregistered worktrees),
alreadyInsideSourceWorktree(no-op, no shell-out), and
reparentTo(Kind)(surface the banner).Conflating the first two with a single
nilwould have producedduplicate worktree rows when the agent navigates around inside its
own worktree.
the active tab. If a
cdlands while the user is on a different tab,the suggestion is parked under that tab's id; landing on it later
surfaces it. Leaving the tab while a banner is visible re-parks.
didClosePanewiring —TabActions.closeTab/closeActivePanenow route into
CwdEventTrackerandSessionTrackerscarries acwdEventslot. A lazy sweep onactiveTabDidChangecatches closepaths that don't thread the tracker through.
Related issue
Skip.
Checklist
make build)make test)[Unreleased]) if user-visible