Feature: switch working directory to existing worktree mid-session
Summary
Claude Code supports --worktree at startup to create/use a git worktree, but there's no way to switch the working directory of an already-running session to an existing worktree.
Use Case
Terminal orchestrators (like TUICommander) create worktrees on behalf of the user via MCP while a Claude Code session is already running. The orchestrator can reassign the terminal in its UI, but Claude Code's internal CWD remains pinned to the original directory. The user must manually stop the session and start a new one in the worktree.
A mid-session worktree switch would allow seamless workflow:
- User (or orchestrator) creates a worktree for a new branch
- Running CC session receives a signal to switch its CWD to the worktree path
- CC continues working in the new directory without losing conversation context
Current Workaround
The orchestrator sends a text message to CC via PTY input telling it to stop and instruct the user to open a new session in the worktree. This loses conversation context.
Possible Approaches
- A slash command:
/cd /path/to/worktreeor/worktree switch <path> - An MCP tool that CC exposes:
switch_directoryorenter_worktree - Reacting to an environment signal or IPC message from the terminal orchestrator
Environment
- Claude Code v2.x
- Worktree created externally (git CLI or orchestrator), not by CC's
--worktreeflag
This issue has 3 comments on GitHub. Read the full discussion on GitHub ↗