# Secrets and API keys in Zed: keep credentials out of the agent's reach

Source: https://botpassword.com/agents/zed
Last checked: 2026-10-25

Zed's built-in agent supports MCP servers, which it calls context servers, configured under `context_servers` in Zed's `settings.json` with a local `command` or a remote `url`. Tool calls need confirmation by default, `agent.tool_permissions` can deny patterns such as `.env`, and Zed reads `.rules`, `AGENTS.md` and several other instruction files.

## MCP support

Yes. Transports: stdio, http.

- user: `Zed settings.json (open with the `zed: open settings file` action), key `context_servers``

## Environment variables and .env files

Local servers take an `env` object in their `context_servers` entry. The MCP page shows a literal `Authorization` header token for remote servers and, when no `Authorization` header is set, runs Zed's standard MCP OAuth flow. The pages reviewed do not describe environment variable interpolation or `.env` loading.

## File access

Zed's agent asks for confirmation before tool actions by default (`agent.tool_permissions.default` is `confirm`, or `agent.always_allow_tool_actions: false` before v0.224.0). `always_deny` patterns use Rust regex, take precedence over other rules, and the documentation's example for protecting sensitive files denies edits matching `\.env`. Per-tool keys for MCP use the form `mcp:<server>:<tool_name>`. The pages reviewed do not state which files the agent can read by default.

Deny or ignore files with: agent.tool_permissions always_deny patterns.

## Credential risks

- **CVE-2025-68433 (fixed in 0.218.2-pre).** Zed loaded MCP server settings from a project's `.zed/settings.json`, so a crafted repository could run shell commands with the user's privileges just by being opened. The fix added a worktree trust mechanism.
- **CVE-2025-55012 (fixed in 0.197.3).** The agent could bypass the approval prompts that guard writes to project configuration files, which led to command execution on the host.
- **Literal tokens in `settings.json`.** The documented remote-server example puts an `Authorization` bearer value directly in the settings file rather than referencing a variable.

## FAQ

### How do I add an MCP server to Zed?

Open Settings > AI > MCP Servers and choose Add Server, or add an entry under `context_servers` in `settings.json` with `command`, `args` and `env` for a local server or `url` and optional `headers` for a remote one.

### How do I stop Zed's agent touching .env files?

Add an `always_deny` pattern such as `{ "pattern": "\\.env" }` under the relevant tool in `agent.tool_permissions`.

### Does Zed read AGENTS.md?

Yes. Zed uses the first matching project file from `.rules`, `.cursorrules`, `.windsurfrules`, `.clinerules`, `.github/copilot-instructions.md`, `AGENT.md`, `AGENTS.md`, `CLAUDE.md` and `GEMINI.md`, plus a personal `~/.config/zed/AGENTS.md`.

### How do I give Zed an API key without it seeing the key?

Don't put the key in the prompt, in a file Zed can read, or in an environment variable it can print. Give it a tool that performs the authenticated step instead: a credential broker exposed over MCP or a CLI that injects the key into the command or HTTP request and returns only the result. BotPassword is that broker, through `bpw mcp` and the `bpw` CLI.

## Sources

- https://zed.dev/docs/ai/mcp
- https://zed.dev/docs/ai/tool-permissions
- https://zed.dev/docs/ai/instructions
- https://osv.dev/vulnerability/CVE-2025-68433
- https://www.sentinelone.com/vulnerability-database/cve-2025-55012/
