← ClaudeAtlas

exit-worktree-cwd-override-merge-from-worktreelisted

When ExitWorktree refuses with "cannot be called from a subagent with a cwd override," merge the worktree branch back to main using `git -C "<main-repo-path>" merge <worktree-branch>` from inside the worktree, instead of trying to exit first. Git merge operates on branch refs and doesn't care about working directory. Use when: (1) you entered a worktree via EnterWorktree, did your work, and now want to merge back to main but ExitWorktree refuses with the cwd-override error; (2) you need to merge a branch in worktree A while you are physically cwd'd in worktree B; (3) any situation where the harness-managed cwd state blocks the directory change ExitWorktree would normally do. Avoids the trap of trying to chase the ExitWorktree refusal by navigating manually — the merge doesn't need the navigation.
MrBinnacle/skills · ★ 0 · Code & Development · score 65
Install: claude install-skill MrBinnacle/skills
# ExitWorktree cwd-override: merge from inside the worktree with `git -C` ## Problem You called `EnterWorktree(name="my-feature")` to set up an isolated branch. The harness moved your session's working directory into `.claude/worktrees/my-feature` on branch `worktree-my-feature`. You dispatched a subagent, the work landed, you ran reviews, and now you want to ExitWorktree(action="keep") to return to main so you can fast-forward main to the new commits. `ExitWorktree` refuses: ``` ExitWorktree cannot be called from a subagent with a cwd override (isolation: "worktree" or explicit cwd) — it would mutate the parent session's process-wide working directory. ``` You're stuck: you can't exit; you can't change directory from inside the tool calls; the merge command appears to require being on the target branch. ## Root cause `ExitWorktree`'s job is to revert the session's working directory. In some harness configurations (notably when the session itself was launched with a cwd override, or after EnterWorktree has nested-overridden the cwd), the tool can't safely mutate the process-wide cwd back. It refuses rather than corrupt parent state. But the BLOCKER assumed by the error message — "I need to be on main to merge into main" — is wrong for `git merge`. Git operates on branch REFS, not on working directory state. You can merge into main from anywhere as long as you tell git which repo to operate on. ## Fix Use `git -C "<path-to-main-repo>"` to invoke git as if you were in