Skip to content

Deny Access to .env Files

.env files often contain secrets such as API keys, database passwords, service tokens, production configuration, and private credentials.

Deny access to .env files by default.

If Claude needs a value, provide a redacted example or one specific non-sensitive variable instead of exposing the whole file.

Add a Read deny rule in settings.json. A bare filename matches at any depth, so Read(.env) and Read(**/.env) are equivalent.

{
"permissions": {
"deny": ["Read(.env)", "Read(.env.*)"]
}
}

A Read deny rule applies to Claude’s file tools, to file commands Claude Code recognizes in Bash such as cat, head, tail, and sed, and to Bash redirections. It does not stop a command that reads files without naming them, such as grep -r pattern ., or a script that opens the file itself.

If the restriction has to hold against every process, enable sandboxing as well.

Read .env files: Deny
Read source files: Allow
Run tests: Allow
Install packages: Ask
Delete files: Ask