zed-industries/zed · error · anyhow::Error

Cannot read file because its path matches the global…

Error message

Cannot read file because its path matches the global `private_files` setting: {}

What it means

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(...)`.

Solutions

  1. Keep the exclusion and read the file yourself, pasting only the relevant non-secret lines into the chat.
  2. Remove or narrow the `private_files` pattern in global settings if the file is not actually sensitive.
  3. Move real secrets out of the repo (e.g. into a secret manager) so the pattern no longer matches.
  4. Remember worktree-level `private_paths` is also checked later — both levels must allow the read.

Example fix

// ~/.config/zed/settings.json (global)
// before
{
  "private_files": [".env"]
}
// after — expose a non-secret example file instead
{
  "private_files": [".env.local"]
}
Defensive patterns

Strategy: validation

Validate before calling

if WorktreeSettings::get_global(cx).is_path_private(&project_path.path) {
    // private file: never pass to read_file; ask the user for redacted contents
}

Try / catch

match read_file(path).await {
    Err(e) if e.to_string().contains("global `private_files`") => {
        // privacy refusal — do not attempt alternates like list_directory on the parent if also private
    }
    rest => rest,
}

Prevention

When it happens

Trigger: 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`.

Common situations: 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.

Related errors


AI-assisted analysis of zed-industries/zed@f4178619ac (2026-08-20). Data as JSON: /api/errors/5a3fea6b43709c1a. Report an issue: GitHub.

Appendix: source

Thrown at crates/agent/src/tools/read_file_tool.rs:320

            project.read_with(cx, |_project, cx| {
                let global_settings = WorktreeSettings::get_global(cx);
                if global_settings.is_path_excluded(&project_path.path) {
                    anyhow::bail!(
                        "Cannot read file because its path matches the global `file_scan_exclusions` setting: {}",
                        input.path
                    );
                }

                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.",

View on GitHub (pinned to f4178619ac)