# Preserve selected agent when starting thread in new worktree \(\#51628\) · gitcafe/zed

[View on GitCafe](https://git.cafe/gitcafe/zed/commit/c17bc26b3a8fddca20b595805cfa558334787fcc)

Repository: [gitcafe/zed](https://git.cafe/gitcafe/zed)

Visibility: public

Requested revision: c17bc26b3a8fddca20b595805cfa558334787fcc

Requested commit: c17bc26b3a8fddca20b595805cfa558334787fcc

Commit: c17bc26b3a8fddca20b595805cfa558334787fcc

Tree: 8b107cd298f51814a5b073908c271588a98623a5

Author: Richard Feldman

Committer: GitHub

## Message

```
Preserve selected agent when starting thread in new worktree (#51628)

When the user selected a custom agent (e.g. Codex) and chose "Start
Thread in New Worktree", the new workspace's panel ignored the selection
and defaulted to Zed Agent (NativeAgent).

The fix captures `self.selected_agent()` in
`handle_worktree_creation_requested` before the async task, passes it
through to `setup_new_workspace`, and forwards it to `external_thread`
instead of `None`.

Closes AI-84

(No release notes because it's still feature-flagged.)

Release Notes:

- N/A
```

## Parents

- [9386e20505636b938f6bdbc0038e755882d1e702](https://git.cafe/gitcafe/zed/commit/9386e20505636b938f6bdbc0038e755882d1e702?format=markdown)

[Source at this commit](https://git.cafe/gitcafe/zed/tree/c17bc26b3a8fddca20b595805cfa558334787fcc?format=markdown)
