EnterWorktree should support entering existing worktrees via path parameter

Resolved 💬 2 comments Opened Jun 3, 2026 by AgentCTO Closed Jun 6, 2026

What

EnterWorktree currently only creates new worktrees. It should also support switching into an existing worktree of the current repository by passing a path parameter.

name and path would be mutually exclusive:

  • name (existing): create a new worktree with this name
  • path (new): enter an existing worktree at this absolute path

Why it matters

Orchestrator workflows that dispatch worker agents into isolated worktrees sometimes need to enter the worker's worktree after it completes — e.g., to finish a blocked commit, run verification, or complete PR creation. Today the only workaround is using Bash with explicit cd, which bypasses the session CWD tracking, plan/memory cache invalidation, and other benefits of EnterWorktree.

Concrete example

A triage-worker agent completed code changes but was blocked by a pre-commit hook failure (missing npm dependency). The orchestrator needed to:

  1. Fix the infra issue from the repo root
  2. Enter the worker's existing worktree to commit and push
  3. Exit back to main

Step 2 required creating a throwaway worktree (immediately discarded) or falling back to raw Bash commands with hardcoded paths.

Suggested behavior

EnterWorktree(path="/abs/path/to/.claude/worktrees/agent-abc123")
  • Validates the path is a git worktree of the current repo (git worktree list --porcelain)
  • Switches session CWD, clears caches, same as current behavior
  • ExitWorktree(action: "keep") leaves it intact; action: "remove" cleans it up
  • Errors if path is not a worktree or belongs to a different repo

Related

#60624 — regression where EnterWorktree errors on existing worktree instead of attaching

View original on GitHub ↗

This issue has 2 comments on GitHub. Read the full discussion on GitHub ↗