zed-industries/zed · error
Cannot read file because its path matches the global `privat
Error message
Cannot read file because its path matches the global `private_files` setting: {} What it means
read_file rejects files matching the global `private_files` setting before touching the filesystem. This is a security control: private_files keeps secrets such as keys and .env files out of agent context entirely, and unlike file_scan_exclusions it should not be loosened to make a tool call succeed.
Source
Thrown at crates/agent/src/tools/read_file_tool.rs:312
.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
);
}
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
);View on GitHub (pinned to bc538def45)
Solutions
- Never route secrets through the agent — reference them by name and inject them via a secret manager at runtime
- If the glob over-matches non-secret files, narrow `private_files` in global settings.json
- Move non-secret files out of the private-matching path
Example fix
// before — global settings.json marks all of keys/ private "private_files": ["keys/**"] // after — only credential material is private "private_files": ["keys/*.pem", "keys/*.env"]
Defensive patterns
Strategy: validation
Validate before calling
let private = project.read_with(cx, |_, cx| {
WorktreeSettings::get_global(cx).is_path_private(&project_path.path)
});
if private {
// secret material: never pass to read_file
} Try / catch
On a private_files read error, stop and inform the user the file is secret by policy; do not retry, do not attempt alternate read paths.
Prevention
- Store secrets outside the workspace or under private_files-covered paths so the agent can never read them
- Reference secrets by name in agent sessions; inject values via a secret manager at runtime
When it happens
Trigger: read_file on a path matched by a global `private_files` glob (`.env*`, `**/*.pem`, `**/id_rsa*`). Checked after the global file_scan_exclusions gate and before worktree settings.
Common situations: The agent tries to read a secrets file while debugging config loading; defaults or user policy intentionally block it.
Related errors
- Cannot list directory because its path matches the user's gl
- Cannot read file because its path matches the worktree `priv
- Cannot read file because its path matches the global `file_s
- Invalid model ID {}
- no language model configured
AI-assisted analysis of zed-industries/zed@bc538def45 (2026-08-16).
Data as JSON: /api/errors/5a3fea6b43709c1a.
Report an issue: GitHub.