{"record":{"id":"4957a114312b4367","repo":"zed-industries/zed","slug":"cannot-read-file-because-its-path-matches-the-work","errorCode":null,"errorMessage":"Cannot read file because its path matches the worktree `file_scan_exclusions` setting: {}","messagePattern":"Cannot read file because its path matches the worktree `file_scan_exclusions` setting: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/agent/src/tools/read_file_tool.rs","lineNumber":320,"sourceCode":"            project.read_with(cx, |_project, cx| {\n                let global_settings = WorktreeSettings::get_global(cx);\n                if global_settings.is_path_excluded(&project_path.path) {\n                    anyhow::bail!(\n                        \"Cannot read file because its path matches the 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 read file because its path matches the 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 read file because its path matches the 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 read file because its path matches the worktree `private_files` setting: {}\",\n                        input.path\n                    );\n                }\n\n                anyhow::Ok(())\n            }).map_err(tool_content_err)?;\n\n            if fs.is_dir(&abs_path).await {\n                return Err(tool_content_err(format!(\n                    \"{} is a directory, not a file. Use the list_directory tool to explore directory contents.\",","sourceCodeStart":302,"sourceCodeEnd":338,"githubUrl":"https://github.com/zed-industries/zed/blob/bc538def4545534201bbfcac4e95ac34ea6501b6/crates/agent/src/tools/read_file_tool.rs#L302-L338","documentation":"The worktree-scoped scan-exclusion gate of read_file: after the global checks pass, WorktreeSettings::get scoped to the project path is consulted, and a match against that worktree's `file_scan_exclusions` (the repo's own .zed/settings.json) aborts the read.","triggerScenarios":"read_file on a file matched only by the worktree's local `file_scan_exclusions` globs — vendored dirs, generated code, or CI artifacts the repo checks in exclusions for.","commonSituations":"A repository's checked-in .zed/settings.json excludes generated or vendored paths; the agent is asked to read a file under them.","solutions":["Adjust the worktree's .zed/settings.json `file_scan_exclusions` so it no longer matches the file","Read the file outside the agent if the checked-in exclusion is intentional","Ask the agent to read an equivalent non-excluded source file"],"exampleFix":"// before — <repo>/.zed/settings.json\n\"file_scan_exclusions\": [\"generated/**\"]\n\n// after — exclude only the noisiest generated subtree\n\"file_scan_exclusions\": [\"generated/proto/**\"]","handlingStrategy":"validation","validationCode":"let excluded = project.read_with(cx, |_, cx| {\n    WorktreeSettings::get(Some((&project_path).into()), cx)\n        .is_path_excluded(&project_path.path)\n});\nif excluded {\n    // repo-local settings exclude this file; skip the read_file call\n}","typeGuard":null,"tryCatchPattern":"Match `worktree \\`file_scan_exclusions\\`` in the message and direct the user to the repo's .zed/settings.json.","preventionTips":["When global settings look clean but reads still fail, inspect the worktree-level settings","Keep repo-level exclusions limited to generated/vendored trees the agent never needs"],"tags":["agent","read-file","file-scan-exclusions","worktree-settings","project-settings"],"backgroundTag":null,"analyzedSha":"bc538def4545534201bbfcac4e95ac34ea6501b6","analyzedAt":"2026-08-16T07:30:46.435Z","schemaVersion":2},"datasetVersion":"2026-08-16T08:17:34.114Z"}