Most of us have a .env file full of keys in the project folder. I would not want an agent browsing it.
Permission rules live in .claude/settings.json. A Read deny rule blocks Claude’s file tools from reading a path.
{
"permissions": {
"deny": [
"Read(./.env)",
"Read(./secrets/**)"
]
}
}
Rules are checked in the order deny, then ask, then allow, and the first match wins. A broad deny cannot be overruled by a narrower allow, and a deny in user settings beats an allow in project settings. That makes deny the safe place for anything sensitive.
I would put this in the project settings the day a repository gets its first .env. It takes a minute to write, and you can check it into git so the whole team gets it. It works the same in interactive and scripted sessions.
The caveat is that a deny rule governs Claude’s file tools. A .claudeignore file does nothing here; the docs say to move its entries into Read deny rules. And the docs describe Bash rules as having limits, so do not treat one pattern as a wall. Keep the real secrets out of the project folder when you can.
Further reading: Configure permissions – Claude Code docs, On this site: scope –allowedTools to single git commands, with a space before the star, On this site: scope instructions with paths in .claude/rules