{"record":{"id":"a1b7508c3815c9d7","repo":"zed-industries/zed","slug":"cannot-list-directory-because-its-path-matches-the-a1b750","errorCode":null,"errorMessage":"Cannot list directory because its path matches the user's worktree `file_scan_exclusions` setting: {}","messagePattern":"Cannot list directory because its path matches the user's worktree `file_scan_exclusions` setting: (.+?)","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/agent/src/tools/list_directory_tool.rs","lineNumber":293,"sourceCode":"\n                let global_settings = WorktreeSettings::get_global(cx);\n                if global_settings.is_path_excluded(&project_path.path) {\n                    anyhow::bail!(\n                        \"Cannot list directory because its path matches the user's global `file_scan_exclusions` setting: {}\",\n                        input.path\n                    );\n                }\n\n                if global_settings.is_path_private(&project_path.path) {\n                    anyhow::bail!(\n                        \"Cannot list directory because its path matches the user's global `private_files` setting: {}\",\n                        input.path\n                    );\n                }\n\n                let worktree_settings = WorktreeSettings::get(Some((&project_path).into()), cx);\n                if worktree_settings.is_path_excluded(&project_path.path) {\n                    anyhow::bail!(\n                        \"Cannot list directory because its path matches the user's worktree `file_scan_exclusions` setting: {}\",\n                        input.path\n                    );\n                }\n\n                if worktree_settings.is_path_private(&project_path.path) {\n                    anyhow::bail!(\n                        \"Cannot list directory because its path matches the user's worktree `private_paths` setting: {}\",\n                        input.path\n                    );\n                }\n\n                let worktree_snapshot = worktree.read(cx).snapshot();\n                let Some(entry) = worktree_snapshot.entry_for_path(&project_path.path) else {\n                    anyhow::bail!(\"Path not found: {}\", input.path);\n                };\n                if !entry.is_dir() {\n                    anyhow::bail!(\"{} is not a directory.\", input.path);","sourceCodeStart":275,"sourceCodeEnd":311,"githubUrl":"https://github.com/zed-industries/zed/blob/f4178619acd0d47ea1f76a2025c42962c6d6638c/crates/agent/src/tools/list_directory_tool.rs#L275-L311","documentation":"Zed's agent `list_directory` tool refuses to enumerate a directory whose resolved path matches the worktree-level `file_scan_exclusions` setting. This is a deliberate privacy/scan policy: paths excluded from file scanning are also invisible to the agent. The check runs after the global checks, using `WorktreeSettings::get(Some((&project_path).into()), cx)` followed by `is_path_excluded`.","triggerScenarios":"The agent (or a test) invokes the `list_directory` tool with a path that matches a pattern in the project's `.zed/settings.json` (or parent `.zed` directory) `file_scan_exclusions` array, e.g. `\"target\"`, `\"node_modules\"`, `\".git\"`, or a glob like `\"**/*.env\"`.","commonSituations":"Teams exclude build output, vendored deps, or secret dirs from Zed's file scan; the agent then fails when asked to list them. Adding `target` or `node_modules` to `file_scan_exclusions` then asking the agent to explore those directories is the classic hit.","solutions":["Remove or narrow the matching pattern in the worktree `.zed/settings.json` `file_scan_exclusions` array (e.g. replace `\"target\"` with `\"target/debug\"` only).","Ask the agent to list a sibling directory that is not excluded, and reference specific files by exact path instead.","If the exclusion is intentional, treat this error as expected behavior and do not retry the same path.","Check the global `file_scan_exclusions` too — the global check fires first, so both levels must permit the path."],"exampleFix":"// .zed/settings.json (worktree settings)\n// before\n{\n  \"file_scan_exclusions\": [\"node_modules\"]\n}\n// after — exclude only a subdirectory so the parent stays listable\n{\n  \"file_scan_exclusions\": [\"node_modules/.cache\"]\n}","handlingStrategy":"validation","validationCode":"// Before calling the list_directory tool with a path:\nlet global = WorktreeSettings::get_global(cx);\nlet worktree = WorktreeSettings::get(Some((&project_path).into()), cx);\nif worktree.is_path_excluded(&project_path.path) || global.is_path_excluded(&project_path.path) {\n    // skip the call; report the path as scan-excluded\n}","typeGuard":null,"tryCatchPattern":"// If invoking the tool, treat this bail as a deterministic refusal, not a retryable error:\nmatch list_directory(path).await {\n    Err(e) if e.to_string().contains(\"file_scan_exclusions\") => {\n        // surface to the user; do not retry the same path\n    }\n    rest => rest,\n}","preventionTips":["Keep `file_scan_exclusions` patterns narrow; prefer deep specific paths over broad directory names.","Do not ask the agent to explore directories you deliberately excluded.","Test new exclusion globs against paths the agent will need before saving settings."],"tags":["rust","zed","agent","list-directory","settings","file-scan-exclusions","access-denied"],"backgroundTag":"file-access-denied-by-settings","analyzedSha":"f4178619acd0d47ea1f76a2025c42962c6d6638c","analyzedAt":"2026-08-20T19:29:52.058Z","contentChangedAt":"2026-08-20T19:29:52.058Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}