Summary
Running wt remove from inside the worktree being removed causes sdkman to emit:
and fail to deactivate the previous worktree's SDK correctly.
Root cause
execute_instant_removal_or_fallback immediately renames the worktree directory (to a staging path) during the binary's execution — before the binary exits and before the shell sources the directive file.
Sequence:
- Binary runs → renames worktree dir (
.sdkmanrc now gone at old path)
- Binary exits
- Shell sources directive file → executes
cd /main/path
- sdkman's
chpwd hook fires → looks for .sdkmanrc at the previous (removed) worktree path → not found
The cd directive is written correctly, but the directory is already gone when sdkman checks it.
Expected behaviour
sdkman finds .sdkmanrc at the previous worktree path when its hook fires, deactivates the old SDK cleanly, then loads the SDK from the main worktree's .sdkmanrc.
Proposed fix
When changed_directory=true (user is inside the removed worktree), skip execute_instant_removal_or_fallback and instead write the removal as a backgrounded shell command into the directive file:
( git -C '/main/path' worktree remove '/worktree/path' && git -C '/main/path' branch -d 'branch-name' ) &
This ensures the sequence becomes:
- Binary exits
- Shell sources directive file:
a. cd '/main/path' → sdkman fires while .sdkmanrc still exists at the old path ✅
b. ( git worktree remove ... ) & → deletion runs in background after cd
The changed_directory=false path (removing a different worktree) is unaffected.
Environment
- wt 0.50.0
- macOS
- sdkman with a
.sdkmanrc in the worktree being removed
Summary
Running
wt removefrom inside the worktree being removed causes sdkman to emit:and fail to deactivate the previous worktree's SDK correctly.
Root cause
execute_instant_removal_or_fallbackimmediately renames the worktree directory (to a staging path) during the binary's execution — before the binary exits and before the shell sources the directive file.Sequence:
.sdkmanrcnow gone at old path)cd /main/pathchpwdhook fires → looks for.sdkmanrcat the previous (removed) worktree path → not foundThe
cddirective is written correctly, but the directory is already gone when sdkman checks it.Expected behaviour
sdkman finds
.sdkmanrcat the previous worktree path when its hook fires, deactivates the old SDK cleanly, then loads the SDK from the main worktree's.sdkmanrc.Proposed fix
When
changed_directory=true(user is inside the removed worktree), skipexecute_instant_removal_or_fallbackand instead write the removal as a backgrounded shell command into the directive file:This ensures the sequence becomes:
a.
cd '/main/path'→ sdkman fires while.sdkmanrcstill exists at the old path ✅b.
( git worktree remove ... ) &→ deletion runs in background after cdThe
changed_directory=falsepath (removing a different worktree) is unaffected.Environment
.sdkmanrcin the worktree being removed