zed-industries/zed · error
Cannot read file because its path matches the global `file_s
Error message
Cannot read file because its path matches the global `file_scan_exclusions` setting: {} What it means
The read_file tool refuses files matching the global `file_scan_exclusions` setting, checking WorktreeSettings::get_global before any filesystem access. This keeps scan-excluded files (lockfiles, build artifacts, vendored code) out of agent context, mirroring the list_directory gate for file reads.
Source
Thrown at crates/agent/src/tools/read_file_tool.rs:305
project_path,
canonical_target,
} => (project_path, Some(canonical_target)),
})
}).map_err(tool_content_err)?;
let abs_path = project
.read_with(cx, |project, cx| {
project.absolute_path(&project_path, cx)
})
.ok_or_else(|| {
anyhow!("Failed to convert {} to absolute path", input.path)
}).map_err(tool_content_err)?;
// Check settings exclusions synchronously
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
);View on GitHub (pinned to bc538def45)
Solutions
- Narrow or remove the matching glob in the global `file_scan_exclusions` setting and retry
- Paste the relevant snippet into the chat instead of having the agent read the excluded file
- Read the file outside the agent if the exclusion is intentional
Example fix
// before — global settings.json "file_scan_exclusions": ["**/pnpm-lock.yaml"] // after — rely on defaults; the agent can read the lockfile "file_scan_exclusions": []
Defensive patterns
Strategy: validation
Validate before calling
let excluded = project.read_with(cx, |_, cx| {
WorktreeSettings::get_global(cx).is_path_excluded(&project_path.path)
});
if excluded {
// skip read_file; the global scan exclusions hide this file from the agent
} Try / catch
Match the read-file `file_scan_exclusions` message, name the offending glob, and either narrow the setting or supply the content out-of-band.
Prevention
- Review file_scan_exclusions before onboarding a codebase to agent workflows
- For files the agent must read often (lockfiles, configs), make sure no glob accidentally matches them
When it happens
Trigger: read_file on a path matched by a global `file_scan_exclusions` glob — commonly pnpm-lock.yaml, Cargo.lock output dirs, node_modules files, or vendored code covered by defaults or user globs.
Common situations: The agent is asked to read a lockfile or a file under node_modules/target that default or user exclusions cover; user-added globs block files the agent needs.
Related errors
- Cannot list directory because its path matches the user's gl
- Invalid model ID {}
- Cannot read file because its path matches the global `privat
- Cannot read file because its path matches the worktree `file
- output token limit reached
AI-assisted analysis of zed-industries/zed@bc538def45 (2026-08-16).
Data as JSON: /api/errors/cb7bb01bb68b140c.
Report an issue: GitHub.