---
name: Worktree merge cwd drift loses commits
description: ALWAYS cd to repo root before merging worktree-agent-* branch in execute-phase cleanup loop; cwd drift orphans executor commits
type: feedback
originSessionId: 0b50cd5a-5758-47bd-8c78-3ed254eb66f7
---
When merging back from `worktree-agent-*` branches at end of an `/gsd-execute-phase` wave, the orchestrator MUST `cd` to the project repo root before running `git merge "$WT_BRANCH"`. The cleanup loop in `~/.claude/get-shit-done/workflows/execute-phase.md` does NOT cd-protect.

**Why:** 2026-05-11 during Phase 6 Wave 1 (REBNO), running an inline merge block dragged cwd into the worktree directory. The merge then ran from inside the worktree, with `HEAD` already on `worktree-agent-...` — git reported "Already up to date" (merging the branch into itself). Subsequent `git branch -D worktree-agent-...` deleted the branch, orphaning the executor's 3 commits. Recovered via `cd "$REPO_ROOT" && git merge --ff-only <commit-sha>` using still-present loose objects in `.git/objects/`. Without that recovery the 06-10 plan output (~500 lines of new code + SUMMARY.md) would have been silently lost.

**How to apply:** Every time the orchestrator runs the worktree cleanup loop or any `git merge "$WT_BRANCH"`/`git branch -D worktree-agent-*` sequence, the FIRST line of the bash block must be `cd "<repo-root-absolute-path>"`. If a heredoc-style block sets `$WT` then runs commands sequentially, prefix every git invocation with `git -C "<repo-root>"` instead of relying on cwd. After `git worktree remove` fails (Windows file-lock case), the worktree directory is left orphaned — non-blocking for future plans (each gets a unique agent ID), but log a warning so the user can manually clean later.

**Recovery signature if it happens again:**
1. `git rev-parse HEAD` reports main still at pre-wave SHA despite executor commits visible during dispatch.
2. `git cat-file -t <executor-commit-sha>` returns `commit` (loose object still exists).
3. Recover: `cd <repo-root> && git merge --ff-only <executor-tip-sha>` — fast-forwards main onto orphaned chain.
