# agent_ui: Fix worktree naming regression when using existing branches \(\#53669\) · gitcafe/zed

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

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

Visibility: public

Requested revision: 1c1f2d6f4c61874943be4c61cc354a424ea4e8d6

Requested commit: 1c1f2d6f4c61874943be4c61cc354a424ea4e8d6

Commit: 1c1f2d6f4c61874943be4c61cc354a424ea4e8d6

Tree: 21eef14382878be9b8e685b3602064b78a5a8970

Author: Richard Feldman

Committer: GitHub

## Message

```
agent_ui: Fix worktree naming regression when using existing branches (#53669)

When creating a new git worktree from an existing branch (e.g. `main`),
the worktree directory was incorrectly named after the branch instead of
getting a random adjective-noun name. Additionally, if a directory with
that name already existed, the rollback logic could destructively delete
the pre-existing worktree.

Changes:
- Generate a random adjective-noun name for worktree directories when no
explicit name is provided
- Collect existing worktree directory names to avoid collisions
- Check generated paths against known worktree paths before creating
- Reduce random name retry count from 100 to 10
- Add regression test

Release Notes:

- Fixed a regression where creating a git worktree from an existing
branch would name the worktree directory after the branch (instead of
generating a random name)
```

## Parents

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

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