Keep your .env away from three coding agents
The real .env switch in Claude Code, Cursor and GitHub Copilot, checked Nov 8 against each vendor's docs.
Published here · 6 sources · Resume reading
A .claudeignore file does nothing. Your agent can read your .env keys. Here is the real switch in each coding agent, checked Nov 8, 2026 against each vendor's docs.
Claude Code
Put deny rules in .claude/settings.json [1][2]:
{
"permissions": {
"deny": [
"Read(./.env)",
"Read(./.env.*)",
"Read(./secrets/**)"
]
}
}These rules also block cat, head, tail and sed on those files. They do not cover a command that reads without naming the file, like grep -r pattern . [1].
For that, turn on the sandbox by typing /sandbox in Claude Code. It applies your Read deny rules to every shell command [3]. Works on macOS, Linux and WSL2. Not native Windows.
Cursor
.env* is on the default ignore list [4]. Add other secret files to .cursorignore in the project root (gitignore syntax):
secrets/
*.pem
*.keyWarning: terminal and MCP tools used by Agent can still reach ignored files [4].
GitHub Copilot
For Copilot Business and Copilot Enterprise only. Go to Repo Settings > Copilot > Content exclusion [5][6]. Add:
- ".env*"
- "/secrets/**"Takes up to 30 minutes in IDEs that already loaded the settings. GitHub says it is not a filesystem security boundary [5].
Rule for all three
Keep live keys out of the project folder the agent works in.
Each vendor's docs say these switches are not a filesystem security boundary. Use them to reduce accidental exposure, not to protect production secrets.
Send this to the friend who thinks a .claudeignore file keeps their keys safe.
Keep this guide
Questions about this guide
Does .claudeignore work?
No. A .claudeignore file has no effect. Use deny rules in .claude/settings.json instead.
Are these switches a security boundary?
No. Each vendor's docs say so. Keep live keys out of the project folder the agent works in.
Sources
- Claude Code docs: permissionscode.claude.com
- Claude Code docs: settings referencecode.claude.com
- Claude Code docs: sandboxingcode.claude.com
- Cursor docs: ignore filescursor.com
- GitHub docs: content exclusiondocs.github.com
- GitHub docs: configure content exclusiondocs.github.com