Repository navigation
Preserve thread context when switching git worktrees #54966
Replies: 5 comments 4 replies
|
Personally, I like that most context (including agent threads) is linked to a given worktree, most of the time. However, I sometimes find myself wanting to detach, duplicate, or transfer a thread from one worktree to another, and it would be really nice to be able to do that. Personally, the ideal experience would be to include it in the contextual menu for a specific thread (while also exposing a command palette/binding item). |
|
This feature is very important because I often have the agent start from the main branch to create several new, parallel feature branches (worktrees), which are eventually merged. In most cases, I can review them through other means, or if the feature is small, no review is needed. However, sometimes there are issues with the feature itself or the agent's implementation process, so I need to review its changes. The problem is that all thread is tied to the main branch, making it impossible to simultaneously view or continue the context while switch to a work tree to inspect the files. |
|
Agree - this is extremely important. I feel very frustrated when switching branch/worktree and my chat/terminal disappears. I want to keep the same agent CLI open for all the worktrees so I can see diff while keep working with my agent. |
|
100% agree. Applies also to agentic terminal threads which are currently somewhat unusable in slightly more advanced agentic workflows. |
|
Can we have the building block for it be a change-root tool like in Cursor? I'm trying to switch over from Cursor (because of the many bugs) to Zed. My past workflow was to open a new chat in the main checkout, then (after initial research) I ask the agent to open a new worktree and switch to it. This frees me from the mechanical work of creating a worktree, before I even know its needed or what it should be called. Note that the Cursor change-root tool is very buggy which I had to work around, and is also why I'm searching for an alternative Agentic orchestrator/harness. |
Uh oh!
There was an error while loading. Please reload this page.
Problem
When working with git worktrees, a common AI-assisted workflow is:
git worktree add.Today this is impossible in one step.
git::SwitchWorktreedrops the agent panel draft and open threads when switching (WorktreeOperation::Switchsetssource_for_transfer = Noneincrates/git_ui/src/worktree_service.rs). Transfer of workspace state — including agent threads — only happens forWorktreeOperation::Create(new worktrees created from Zed's own UI).So the actual flow forces the user to:
This breaks the continuity of AI-assisted development across worktrees.
Expected behavior
When a user (or agent) switches to a git worktree — whether via
git::SwitchWorktree, the worktree picker, or a programmatic action — the active agent thread should be transferred to the new workspace/worktree context, analogous to howWorktreeOperation::Createalready copies workspace state.Ideally:
SwitchWorktree).At minimum, an opt-in flag on
SwitchWorktree(e.g.transfer_agent_state: bool) would allow callers to request the transfer.Current workaround
None that preserves thread history. Users must start a new thread after switching, duplicating context manually.
Why this matters
Git worktrees are the idiomatic way to work on multiple branches simultaneously without stashing. Agents that create worktrees as part of their workflow (e.g. "create a branch and implement this feature in isolation") leave the user stranded in the original worktree with a broken handoff. Carrying agent context across the switch would make the worktree + agent workflow fully continuous.
Related
crates/git_ui/src/worktree_service.rs—WorktreeOperationenum andsource_for_transferlogiccrates/git_ui/src/git_ui.rs:77—SwitchWorktreeaction registrationzed_actions::SwitchWorktreestruct (currently{ path: PathBuf, display_name: String }, no transfer flag)All reactions