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

git.worktree_directory must be a relative path, got

Error message

git.worktree_directory must be a relative path, got: {worktree_directory_setting:?}

What it means

Zed validates the git.worktree_directory setting before creating a managed git worktree (crates/project/src/git_store.rs:10492). The value must be relative because it is joined onto the repository anchor path; absolute POSIX paths, Windows drive-letter paths, and values starting with a backslash are rejected up front (an explicit leading-slash check compensates for Windows Path::is_absolute() requiring a drive letter).

Solutions

  1. Use a relative path such as ".zed-worktrees" (resolved inside the repository)
  2. To place worktrees next to the repository, use "../my-repo-worktrees"
  3. Remove the setting entirely to fall back to the default location

Example fix

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

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

Strategy: validation

Validate before calling

fn assert_relative_worktree_directory(setting: &str) -> Result<(), String> {
    if setting.starts_with('/')
        || setting.starts_with('\\')
        || Path::new(setting).is_absolute()
    {
        return Err(format!("git.worktree_directory must be a relative path, got: {setting:?}"));
    }
    Ok(())
}

Prevention

When it happens

Trigger: Setting "git": { "worktree_directory": "/tmp/worktrees" } (or "C:\\worktrees", "\\worktrees") in settings.json, then creating a worktree. A value like "///" also lands here because it is absolute before trailing separators are trimmed.

Common situations: Users copying an absolute path they previously passed to git worktree add into settings; Windows drive-letter paths; leading-backslash values.

Understand the failure class

Background: "Invalid value" and "allowed values are" config errors: what your library rejected and how to fix it — this error's family across 41 libraries.

Related errors


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

Appendix: source

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

                        let mut changed_path_statuses = Vec::new();
                        let prev_statuses = prev_snapshot.statuses_by_path.clone();
                        let current_status_paths = statuses
                            .entries
                            .iter()
                            .map(|(repo_path, _)| repo_path.clone())
                            .collect::<BTreeSet<_>>();

                        for path in &changed_paths {
                            let mut cursor = prev_statuses.cursor::<PathProgress>(());
                            cursor.seek_forward(&PathTarget::Path(path), Bias::Left);
                            while let Some(entry) = cursor.item() {
                                if !entry.repo_path.starts_with(path) {
                                    break;
                                }

                                if !current_status_paths.contains(&entry.repo_path) {
                                    changed_path_statuses.push(Edit::Remove(PathKey(
                                        entry.repo_path.as_ref().clone(),
                                    )));
                                }
                                cursor.next();
                            }
                        }

                        let mut cursor = prev_statuses.cursor::<PathProgress>(());

                        for (repo_path, status) in &*statuses.entries {
                            let current_diff_stat = diff_stats.get(repo_path).copied();
                            let current_staged_diff_stat =
                                staged_diff_stats.get(repo_path).copied();
                            let current_unstaged_diff_stat =
                                unstaged_diff_stats.get(repo_path).copied();

                            if cursor.seek_forward(&PathTarget::Path(repo_path), Bias::Left)
                                && cursor.item().is_some_and(|entry| {

View on GitHub (pinned to 916fc2b8cb)