{"record":{"id":"5a3fea6b43709c1a","repo":"zed-industries/zed","slug":"cannot-read-file-because-its-path-matches-the-glob-5a3fea","errorCode":null,"errorMessage":"Cannot read file because its path matches the global `private_files` setting: {}","messagePattern":"Cannot read file because its path matches the global `private_files` setting: (.+?)","errorType":"exception","errorClass":"anyhow::Error","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/f4178619acd0d47ea1f76a2025c42962c6d6638c/crates/agent/src/tools/read_file_tool.rs#L302-L338","documentation":"The second gate in the `read_file` tool: the path matched the global `private_files` setting, so reading is denied to keep secret material out of model context. `private_files` is the global analogue of worktree `private_paths` and is checked with `WorktreeSettings::get_global(cx).is_path_private(...)`.","triggerScenarios":"The agent's `read_file` tool is called on a path matched by `private_files` in the user-level global settings — typically `.env`, `*.pem`, `id_rsa`, `credentials.json`.","commonSituations":"A global secrets-exclusion list blocks the agent from reading `.env` when a user asks the agent to debug config loading; the refusal is intentional privacy behavior, not a bug.","solutions":["Keep the exclusion and read the file yourself, pasting only the relevant non-secret lines into the chat.","Remove or narrow the `private_files` pattern in global settings if the file is not actually sensitive.","Move real secrets out of the repo (e.g. into a secret manager) so the pattern no longer matches.","Remember worktree-level `private_paths` is also checked later — both levels must allow the read."],"exampleFix":"// ~/.config/zed/settings.json (global)\n// before\n{\n  \"private_files\": [\".env\"]\n}\n// after — expose a non-secret example file instead\n{\n  \"private_files\": [\".env.local\"]\n}","handlingStrategy":"validation","validationCode":"if WorktreeSettings::get_global(cx).is_path_private(&project_path.path) {\n    // private file: never pass to read_file; ask the user for redacted contents\n}","typeGuard":null,"tryCatchPattern":"match read_file(path).await {\n    Err(e) if e.to_string().contains(\"global `private_files`\") => {\n        // privacy refusal — do not attempt alternates like list_directory on the parent if also private\n    }\n    rest => rest,\n}","preventionTips":["Keep secret files out of agent-reachable subtrees entirely.","Scope `private_files` patterns tightly so non-secret neighbors remain readable.","In agent loop code, filter private paths out of candidate file lists before planning reads."],"tags":["rust","zed","agent","read-file","settings","private-files","privacy","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"}