zed-industries/zed · error
{} is not a directory.
Error message
{} is not a directory. What it means
list_directory found an entry for the path in the worktree snapshot, but entry.is_dir() is false — the path names a regular file (or symlink treated as a file), so it cannot be enumerated as a directory and the tool refuses.
Source
Thrown at crates/agent/src/tools/list_directory_tool.rs:311
anyhow::bail!(
"Cannot list directory because its path matches the user's worktree `file_scan_exclusions` setting: {}",
input.path
);
}
if worktree_settings.is_path_private(&project_path.path) {
anyhow::bail!(
"Cannot list directory because its path matches the user's worktree `private_paths` setting: {}",
input.path
);
}
let worktree_snapshot = worktree.read(cx).snapshot();
let Some(entry) = worktree_snapshot.entry_for_path(&project_path.path) else {
anyhow::bail!("Path not found: {}", input.path);
};
if !entry.is_dir() {
anyhow::bail!("{} is not a directory.", input.path);
}
anyhow::Ok(())
}).map_err(|e| e.to_string())?;
if let Some(canonical_target) = &symlink_canonical_target {
let authorize = cx.update(|cx| {
authorize_symlink_access(
Self::NAME,
&input.path,
canonical_target,
&event_stream,
cx,
)
});
authorize.await.map_err(|e| e.to_string())?;
}
View on GitHub (pinned to bc538def45)
Solutions
- Use the read_file tool on that path instead — it is a file
- If a directory was expected, list the parent directory to find the correct folder name
Example fix
// before list_directory(path="crates/foo/Cargo.toml") // after read_file(path="crates/foo/Cargo.toml")
Defensive patterns
Strategy: type-guard
Type guard
fn is_listable_dir(project: &Project, project_path: &ProjectPath, cx: &App) -> bool {
project
.worktree_for_id(project_path.worktree_id, cx)
.and_then(|worktree| worktree.read(cx).snapshot().entry_for_path(&project_path.path).map(|e| e.is_dir()))
.unwrap_or(false)
} Try / catch
On 'is not a directory', route the same path to read_file instead of failing the user request.
Prevention
- Check entry.is_dir() from the worktree snapshot before choosing list_directory vs read_file
- Prefer listing the parent directory when unsure whether a path is a file or folder
When it happens
Trigger: list_directory invoked on a regular file — e.g. asking to 'list' a file path, or a directory that was replaced by a file of the same name.
Common situations: The agent mistakes a file for a directory (e.g. `Cargo.toml` vs a `cargo/` folder); a file path is pasted where a directory was expected.
Related errors
- Cannot list directory because its path matches the user's gl
- Cannot list directory because its path matches the user's gl
- Cannot list directory because its path matches the user's wo
- Cannot list directory because its path matches the user's wo
- Unexpected response structure: ${JSON.stringify(data)}
AI-assisted analysis of zed-industries/zed@bc538def45 (2026-08-16).
Data as JSON: /api/errors/67a94f884a4aa967.
Report an issue: GitHub.