zed-industries/zed · error · anyhow::Error

git.worktree_directory resolved to

Error message

git.worktree_directory resolved to {resolved:?}, which is outside the project root and its parent directory. It must resolve to a subdirectory of {repository_anchor_path:?} or a sibling of it.

What it means

After joining the relative setting onto the repository anchor path and normalizing, the resolved directory must start with either the repository directory or its parent (crates/project/src/git_store.rs:10528). Values whose '..' traversal escapes both - e.g. "../.." - are rejected so Zed never manages worktrees outside the project root or its sibling directory.

Solutions

  1. Keep worktrees inside the repository: "tools/worktrees" or ".worktrees"
  2. Keep them directly beside the repository: "../<repo-name>-worktrees"
  3. For centralized locations, create a symlink from the allowed sibling directory instead

Example fix

// settings.json - before
{ "git": { "worktree_directory": "../.." } }

// settings.json - after
{ "git": { "worktree_directory": "../acme-worktrees" } }
Defensive patterns

Strategy: validation

Validate before calling

// Mirror Zed's containment rule before creating worktrees programmatically
let joined = repository_anchor_path.join(trimmed_setting);
let resolved = normalize_path(joined);
let parent = repository_anchor_path.parent().unwrap_or(repository_anchor_path);
if !resolved.starts_with(parent) {
    return Err("worktree directory escapes the repository root and its parent".into());
}

Prevention

When it happens

Trigger: git.worktree_directory containing enough '..' segments to resolve above the repository's parent directory, for example "../.." or "subdir/../../..", when a worktree is created.

Common situations: Trying to gather all worktrees in a central folder like ~/worktrees; deeply nested repositories where "../.." looks harmless.

Related errors


AI-assisted analysis of zed-industries/zed@916fc2b8cb (2026-08-20). Data as JSON: /api/errors/c4117ac30198d3b2. Report an issue: GitHub.

Appendix: source

Thrown at crates/project/src/git_store.rs:10546

                                && cursor.item().is_some_and(|entry| {
                                    entry.status == *status
                                        && entry.diff_stat == current_diff_stat
                                        && entry.staged_diff_stat == current_staged_diff_stat
                                        && entry.unstaged_diff_stat == current_unstaged_diff_stat
                                })
                            {
                                continue;
                            }

                            changed_path_statuses.push(Edit::Insert(StatusEntry {
                                repo_path: repo_path.clone(),
                                status: *status,
                                diff_stat: current_diff_stat,
                                staged_diff_stat: current_staged_diff_stat,
                                unstaged_diff_stat: current_unstaged_diff_stat,
                            }));
                        }
                        anyhow::Ok(changed_path_statuses)
                    })
                    .await?;

                this.update(&mut cx, |this, cx| {
                    if !changed_path_statuses.is_empty() {
                        cx.emit(RepositoryEvent::StatusesChanged);
                        this.snapshot
                            .statuses_by_path
                            .edit(changed_path_statuses, ());
                        this.snapshot.scan_id += 1;
                    }

                    if let Some(updates_tx) = updates_tx {
                        updates_tx
                            .unbounded_send(DownstreamUpdate::UpdateRepository(
                                this.snapshot.clone(),
                            ))
                            .ok();

View on GitHub (pinned to 916fc2b8cb)