zed-industries/zed · error
Cannot read file because its path matches the worktree `priv
Error message
Cannot read file because its path matches the worktree `private_files` setting: {} What it means
The last settings gate of read_file: the file matches the worktree-level private files setting (`private_files`, enforced via is_path_private on worktree-scoped WorktreeSettings). It is a repository-scoped security boundary — files under it are kept out of agent context even when global settings allow them.
Source
Thrown at crates/agent/src/tools/read_file_tool.rs:327
}
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.",
input.path
)));
}
if let Some(canonical_target) = &symlink_canonical_target {
let authorize = cx.update(|cx| {
authorize_symlink_access(View on GitHub (pinned to bc538def45)
Solutions
- Respect the policy — do not read the private file via the agent
- Narrow the worktree `private_files` glob in .zed/settings.json if it accidentally matches non-secret files
- Move non-secret content out of the private-matching path
Example fix
// before — <repo>/.zed/settings.json "private_files": ["local/**"] // after — only the credentials dir is private "private_files": ["local/creds/**"]
Defensive patterns
Strategy: validation
Validate before calling
let private = project.read_with(cx, |_, cx| {
WorktreeSettings::get(Some((&project_path).into()), cx)
.is_path_private(&project_path.path)
});
if private {
// repo-declared private file; refuse before calling read_file
} Try / catch
On the worktree `private_files` message, stop and report the policy; never retry or bypass.
Prevention
- Declare only genuine secret paths in worktree private_files settings
- Treat any private-files error as intended behavior, not a configuration bug
When it happens
Trigger: read_file where global exclusions and private_files pass but the worktree's `private_files` globs match the requested path.
Common situations: A repo checks in .zed/settings.json marking local key files or environment dirs private; the agent attempts to read one during debugging.
Related errors
- Cannot read file because its path matches the global `privat
- Cannot list directory because its path matches the user's gl
- Cannot list directory because its path matches the user's wo
- Cannot read file because its path matches the worktree `file
- Cannot list directory because its path matches the user's wo
AI-assisted analysis of zed-industries/zed@bc538def45 (2026-08-16).
Data as JSON: /api/errors/9dc7643b2c570bd7.
Report an issue: GitHub.