fix(finishing-a-development-branch): handle worktree CWD cleanup ordering#391
fix(finishing-a-development-branch): handle worktree CWD cleanup ordering#391tartansandal wants to merge 1 commit intoobra:mainfrom
Conversation
…ring Step 5 (Cleanup Worktree) now documents the correct ordering: 1. Move CWD out of worktree before removal 2. Remove worktree before deleting branch 3. Prune stale worktree refs Without this, removing a worktree while the shell CWD is inside it makes every subsequent command fail with 'Path does not exist' — an unrecoverable state. Similarly, git refuses to delete a branch that is checked out in a worktree. Also adds guidance for cross-session plans where the executing session's CWD will be inside the worktree. Adds two new Common Mistakes entries for these failure modes.
📝 WalkthroughWalkthroughA documentation file for finishing a development branch is updated to clarify worktree cleanup procedures, reorganizing Steps 4 and 5 with explicit sequencing requirements, rationale blocks explaining common pitfalls, and warnings about working directory positioning relative to worktree removal. Changes
Estimated code review effort🎯 2 (Simple) | ⏱️ ~12 minutes Possibly related issues
Suggested reviewers
Poem
🚥 Pre-merge checks | ✅ 3✅ Passed checks (3 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 2
🤖 Fix all issues with AI agents
In `@skills/finishing-a-development-branch/SKILL.md`:
- Around line 130-160: The doc is inconsistent: "Step 5: Cleanup Worktree" now
says cleanup applies to Options 1, 2, 4 but the Quick Reference table and the
“Automatic worktree cleanup” common-mistakes section still imply a different
behavior for Option 2; update the Quick Reference table entry for Option 2 to
indicate that worktree cleanup is part of the process (matching "Options 1, 2,
4"), and revise the “Automatic worktree cleanup” mistake text to state the new
policy (cleanup occurs for Options 1, 2, 4; Option 3 keeps the worktree), add
the explicit warning text required for generated plans about CWD being inside
the worktree and that plans must either start with "cd <main-repo>" or note that
worktree removal will invalidate the shell.
- Around line 185-191: Replace the two bolded section titles "**Removing
worktree while CWD is inside it**" and "**Deleting branch before removing
worktree**" with proper ATX headings using "### Removing worktree while CWD is
inside it" and "### Deleting branch before removing worktree" in SKILL.md to
satisfy MD036; ensure the rest of the paragraph content under each heading
remains unchanged and that any references to these titles (e.g., in links or
TOC) are updated if necessary.
Delegate creation to Claude Code's built-in EnterWorktree tool. Add optional worktree skip, state.yml tracking, team mode with per-implementer worktrees, and QA worktree strategy. Drops: directory selection logic (.worktrees/ vs worktrees/), gitignore verification (native tool handles), auto-commit of .gitignore changes without user consent. Keeps: CLAUDE.md preference check, setup command auto-detection, baseline test verification, project setup auto-detection. Addresses Finding X, obra#583, obra#574, obra#371, obra#348, obra#299, obra#279, obra#238, obra#186, obra#167, #5, PR obra#483, PR obra#391. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Add explicit cd-to-repo-root before any worktree removal, using worktree.main.repo_root from state.yml. Running git worktree remove from inside the worktree itself causes CWD to vanish mid-command. Move team shutdown to Step 1 of main flow (not just Team Context section) — specialists must be shut down before merging. Add state.yml write on completion: phase:idle, plan.status:executed, clear worktree.* and team entries so future sessions know no active work is in progress. Add native EnterWorktree cleanup awareness — check if worktree still exists before manual removal, since native tool may auto-clean. Replace "Type 'discard' to confirm" with AskUserQuestion approach. Fix Option 2 worktree cleanup contradiction — quick reference table now correctly shows Option 2 keeps worktree (no cleanup); prose updated to match. Addresses obra#167, PR obra#391, Findings D, X. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Delegate creation to Claude Code's built-in EnterWorktree tool. Add optional worktree skip, state.yml tracking, team mode with per-implementer worktrees, and QA worktree strategy. Drops: directory selection logic (.worktrees/ vs worktrees/), gitignore verification (native tool handles), auto-commit of .gitignore changes without user consent. Keeps: CLAUDE.md preference check, setup command auto-detection, baseline test verification, project setup auto-detection. Addresses Finding X, obra#583, obra#574, obra#371, obra#348, obra#299, obra#279, obra#238, obra#186, obra#167, #5, PR obra#483, PR obra#391. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Add explicit cd-to-repo-root before any worktree removal, using worktree.main.repo_root from state.yml. Running git worktree remove from inside the worktree itself causes CWD to vanish mid-command. Move team shutdown to Step 1 of main flow (not just Team Context section) — specialists must be shut down before merging. Add state.yml write on completion: phase:idle, plan.status:executed, clear worktree.* and team entries so future sessions know no active work is in progress. Add native EnterWorktree cleanup awareness — check if worktree still exists before manual removal, since native tool may auto-clean. Replace "Type 'discard' to confirm" with AskUserQuestion approach. Fix Option 2 worktree cleanup contradiction — quick reference table now correctly shows Option 2 keeps worktree (no cleanup); prose updated to match. Addresses obra#167, PR obra#391, Findings D, X. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Delegate creation to Claude Code's built-in EnterWorktree tool. Add optional worktree skip, state.yml tracking, team mode with per-implementer worktrees, and QA worktree strategy. Drops: directory selection logic (.worktrees/ vs worktrees/), gitignore verification (native tool handles), auto-commit of .gitignore changes without user consent. Keeps: CLAUDE.md preference check, setup command auto-detection, baseline test verification, project setup auto-detection. Addresses Finding X, obra#583, obra#574, obra#371, obra#348, obra#299, obra#279, obra#238, obra#186, obra#167, #5, PR obra#483, PR obra#391. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Add explicit cd-to-repo-root before any worktree removal, using worktree.main.repo_root from state.yml. Running git worktree remove from inside the worktree itself causes CWD to vanish mid-command. Move team shutdown to Step 1 of main flow (not just Team Context section) — specialists must be shut down before merging. Add state.yml write on completion: phase:idle, plan.status:executed, clear worktree.* and team entries so future sessions know no active work is in progress. Add native EnterWorktree cleanup awareness — check if worktree still exists before manual removal, since native tool may auto-clean. Replace "Type 'discard' to confirm" with AskUserQuestion approach. Fix Option 2 worktree cleanup contradiction — quick reference table now correctly shows Option 2 keeps worktree (no cleanup); prose updated to match. Addresses obra#167, PR obra#391, Findings D, X. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
|
Thanks for the PR. The substantive cleanup-ordering work here has been superseded by #1121, now merged into The current Closing this as superseded by the broader worktree rototill. |
Summary
Context
Discovered while using the skill to merge a feature branch from a git worktree. The previous Step 5 didn't account for:
git worktree remove, the shell's working directory no longer exists. Every subsequent command fails with "Path does not exist" — unrecoverable in the current shell.git branch -dfails if the branch is still checked out in a worktree. The worktree must be removed first.executing-plans), the executing session's CWD is inside the worktree. The plan must warn about this.Test Plan
cd <main-repo>Summary by CodeRabbit
✏️ Tip: You can customize this high-level summary in your review settings.