---
name: Worktree merge CWD drift gotcha
description: Always cd to repo root before git merge in worktree cleanup — cwd drift causes silent self-merge + orphaned commits
type: feedback
originSessionId: 40dd1602-61d6-4526-babc-b9a42d6d8ecb
---
Always `cd "$REPO_ROOT"` before `git merge $WT_BRANCH` in execute-phase cleanup loop.

**Why:** 2026-05-11 — merge loop pulled cwd INSIDE worktree dir. `git merge $WT_BRANCH` ran from worktree → "Already up to date" (merging branch into itself). After `git branch -D worktree-agent-*` the commits became orphaned dangling objects. Recovered via `cd $REPO_ROOT && git merge --ff-only <commit-sha>` using still-present loose objects.

**How to apply:** First line of every merge block in execute-phase must be `cd C:/Users/decid/Documents/projects/rebno` (or `cd "$ORCHESTRATOR_ROOT"`). Cleanup loop in execute-phase.md does NOT cd-protect — orchestrator must add it explicitly.

Secondary: Worktree dir removal may fail with Permission denied (Windows file locks). `git worktree remove --force` can fail; branch deleted but dir stays. Non-blocking — each plan gets unique agent ID.
