You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Worktree friction: add flag to automatically cd into previous subdirectory #937
When running wt switch --create {name} from a subdirectory within a worktree, worktrunk creates/switches to the new worktree correctly, but always cd into the worktree root directory instead of the equivalent subdirectory.
This is especially painful in monorepos — if I'm working in ./apps/gateway/ and need to create a feature branch, I end up at the repo root and have to navigate back to the service I was working on. In large monorepos with many services, this adds friction every time I switch branches.
Current workaround
After switching, manually cd back into the subdirectory:
# In ~/project.main/apps/gateway/
wt switch --create feature-XYZ
cd apps/gateway/
Ideal solution
A --subdir (-s) flag (and corresponding config option) that automatically cds into the same subdirectory in the new worktree, if it exists:
# In ~/project.main/apps/gateway/
wt switch --subdir --create feature-XYZ
# Now in ~/project.feature-button/apps/gateway/
If the subdirectory doesn't exist in the target worktree, fall back to the worktree root (silent fallback — the user will see they're at root).
changed the title [-]Worktree friction: add feature flag to automatically cd into previous subdirectory[/-][+]Worktree friction: add flag to automatically cd into previous subdirectory[/+]on Feb 5, 2026
There are cases where ending up at the worktree root makes sense too. For example: I'm deep in some subdirectory, create a new worktree to work on something completely different, and actually want to start fresh at the root rather than in the same nested location.
That said, I think for most workflows, especially in monorepos, preserving the subdirectory is the more common need. When you're fixing a bug in apps/gateway/ and need to branch off, you probably want to stay in apps/gateway/.
A few design options:
Default to preserving subdir, flag to override: wt switch --create foo preserves subdir by default; add --root (or -r) to explicitly land at root. Config option to flip the default.
Default to root (current behavior), flag to preserve: Add --subdir (or -s) as proposed. Config option to make it the default.
Always preserve subdir, no flag: Simplest, but loses flexibility for the "fresh start at root" case.
I'd lean toward option 1, preserving subdir feels like the less surprising behavior for most users, especially in monorepos where the friction is most acute. Users who want root can be explicit about it. But I could see an argument for option 2 if we want to be conservative about changing defaults.
let's go with (3) for the moment; I think we should have quite a high bar on adding options, and this could compose with a cd (git rev-parse --git-common-dir)?
if that proves insufficient we can consider adding something
Activity
max-sixty commentedon Feb 5, 2026
agree!
should we just always cd into the subdir?
[-]Worktree friction: add feature flag to automatically cd into previous subdirectory[/-][+]Worktree friction: add flag to automatically cd into previous subdirectory[/+]frederik-suerig commentedon Feb 5, 2026
There are cases where ending up at the worktree root makes sense too. For example: I'm deep in some subdirectory, create a new worktree to work on something completely different, and actually want to start fresh at the root rather than in the same nested location.
That said, I think for most workflows, especially in monorepos, preserving the subdirectory is the more common need. When you're fixing a bug in
apps/gateway/and need to branch off, you probably want to stay inapps/gateway/.A few design options:
wt switch --create foopreserves subdir by default; add--root(or-r) to explicitly land at root. Config option to flip the default.--subdir(or-s) as proposed. Config option to make it the default.I'd lean toward option 1, preserving subdir feels like the less surprising behavior for most users, especially in monorepos where the friction is most acute. Users who want root can be explicit about it. But I could see an argument for option 2 if we want to be conservative about changing defaults.
max-sixty commentedon Feb 5, 2026
let's go with (3) for the moment; I think we should have quite a high bar on adding options, and this could compose with a
cd (git rev-parse --git-common-dir)?if that proves insufficient we can consider adding something
feat(switch): preserve subdirectory position when switching worktrees
feat(switch): preserve subdirectory position when switching worktrees (…
fix: preserve subdirectory position on wt remove (#3344)