# Prevent archival of manually-created worktrees \(\#58275\) · gitcafe/zed

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

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

Visibility: public

Requested revision: 29622911de00305340012f798f17c04a274f4b31

Requested commit: 29622911de00305340012f798f17c04a274f4b31

Commit: 29622911de00305340012f798f17c04a274f4b31

Tree: a50ef372b43d1a4b85af6f3e18f8e32b5c5b5b15

Author: Richard Feldman

Committer: GitHub

## Message

```
Prevent archival of manually-created worktrees (#58275)

This fixes archive cleanup for agent threads so Zed only removes
worktrees it explicitly created, rather than treating every linked
worktree under the configured managed directory as safe to delete. When
Zed creates a worktree, it now records it in the local database along
with the creation time of the worktree's git metadata directory
(`.git/worktrees/<name>/`). Archive planning requires that record, and
right before deleting anything, Zed re-stats the directory and compares
creation times: if the worktree was removed and recreated outside Zed
(or the time can't be read at all), deletion is skipped and the stale
record is dropped. Every failure mode fails safe by leaving the
directory untouched.

For remote (SSH) projects, the stat runs on the remote host via a new
`GitWorktreeCreatedAt` request. Worktrees created by a different Zed
install (another release channel, or another machine connecting to the
same host) have no record in the local database and are therefore never
auto-archived, which is the intended conservative behavior.

Closes https://github.com/zed-industries/zed/issues/57155

Closes AI-352

Release Notes:

- Fixed archiving an agent thread incorrectly deleting manually-created
git worktrees.
```

## Parents

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

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