Deny Access to .env Files
.env files often contain secrets such as API keys, database passwords, service tokens, production configuration, and private credentials.
Recommended guidance
Section titled “Recommended guidance”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.
The rule
Section titled “The rule”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.*)"] }}What the rule does not cover
Section titled “What the rule does not cover”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.
Example policy
Section titled “Example policy”Read .env files: DenyRead source files: AllowRun tests: AllowInstall packages: AskDelete files: Ask