zed-industries/zed · error

Cannot read file because its path matches the worktree `file

Error message

Cannot read file because its path matches the worktree `file_scan_exclusions` setting: {}

What it means

The worktree-scoped scan-exclusion gate of read_file: after the global checks pass, WorktreeSettings::get scoped to the project path is consulted, and a match against that worktree's `file_scan_exclusions` (the repo's own .zed/settings.json) aborts the read.

Source

Thrown at crates/agent/src/tools/read_file_tool.rs:320

            project.read_with(cx, |_project, cx| {
                let global_settings = WorktreeSettings::get_global(cx);
                if global_settings.is_path_excluded(&project_path.path) {
                    anyhow::bail!(
                        "Cannot read file because its path matches the global `file_scan_exclusions` setting: {}",
                        input.path
                    );
                }

                if global_settings.is_path_private(&project_path.path) {
                    anyhow::bail!(
                        "Cannot read file because its path matches the global `private_files` setting: {}",
                        input.path
                    );
                }

                let worktree_settings = WorktreeSettings::get(Some((&project_path).into()), cx);
                if worktree_settings.is_path_excluded(&project_path.path) {
                    anyhow::bail!(
                        "Cannot read file because its path matches the worktree `file_scan_exclusions` setting: {}",
                        input.path
                    );
                }

                if worktree_settings.is_path_private(&project_path.path) {
                    anyhow::bail!(
                        "Cannot read file because its path matches the worktree `private_files` setting: {}",
                        input.path
                    );
                }

                anyhow::Ok(())
            }).map_err(tool_content_err)?;

            if fs.is_dir(&abs_path).await {
                return Err(tool_content_err(format!(
                    "{} is a directory, not a file. Use the list_directory tool to explore directory contents.",

View on GitHub (pinned to bc538def45)

Solutions

  1. Adjust the worktree's .zed/settings.json `file_scan_exclusions` so it no longer matches the file
  2. Read the file outside the agent if the checked-in exclusion is intentional
  3. Ask the agent to read an equivalent non-excluded source file

Example fix

// before — <repo>/.zed/settings.json
"file_scan_exclusions": ["generated/**"]

// after — exclude only the noisiest generated subtree
"file_scan_exclusions": ["generated/proto/**"]
Defensive patterns

Strategy: validation

Validate before calling

let excluded = project.read_with(cx, |_, cx| {
    WorktreeSettings::get(Some((&project_path).into()), cx)
        .is_path_excluded(&project_path.path)
});
if excluded {
    // repo-local settings exclude this file; skip the read_file call
}

Try / catch

Match `worktree \`file_scan_exclusions\`` in the message and direct the user to the repo's .zed/settings.json.

Prevention

When it happens

Trigger: read_file on a file matched only by the worktree's local `file_scan_exclusions` globs — vendored dirs, generated code, or CI artifacts the repo checks in exclusions for.

Common situations: A repository's checked-in .zed/settings.json excludes generated or vendored paths; the agent is asked to read a file under them.

Related errors


AI-assisted analysis of zed-industries/zed@bc538def45 (2026-08-16). Data as JSON: /api/errors/4957a114312b4367. Report an issue: GitHub.