fix(finish): cd to main repo before worktree removal#952
Open
JasonOA888 wants to merge 1 commit intoobra:mainfrom
Open
fix(finish): cd to main repo before worktree removal#952JasonOA888 wants to merge 1 commit intoobra:mainfrom
JasonOA888 wants to merge 1 commit intoobra:mainfrom
Conversation
When the current working directory is inside a worktree, `git worktree remove` fails with: fatal: cannot remove worktree '<path>': '<path>' is the current working directory This happens when Claude Code's shell session is still inside the worktree being cleaned up. Fix: Before removing the worktree, change directory to the main repository (the first entry in `git worktree list`). This ensures the removal command runs from outside the target worktree. Fixes obra#238
5 tasks
robotsnh
approved these changes
Mar 30, 2026
robotsnh
left a comment
There was a problem hiding this comment.
This looks fine. My only concern is what would happen if the user's repo isn't on git, but there's already a git command in that code block, so that's a problem for another PR.
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
Fixes #238
Problem
The
/finishworkflow's Step 5 runsgit worktree remove <path>without first changing the working directory. When the current shell session is inside the worktree being removed, this fails:This is a common scenario when Claude Code's shell is still inside the feature worktree.
Solution
Before running
git worktree remove, change directory to the main repository:Testing
git worktree list | head -1 | awk '{print $1}'correctly returns the main repo pathFiles Changed
skills/finishing-a-development-branch/SKILL.md— Updated Step 5 with directory change