brewedbits.dev

Personal blog with guides and news on selfhosting, Linux and AI, from the Netherlands

nextDash nextdash --aboutYour bookmarks. Your terminal. checks your links knows your Docker host one container, no cloudLive demo →nextdash.cc ↗

Tip: deny Read(./.env) so Claude never opens your secrets

Claude
~/tips/tip-claude-deny-read-env

"permissions": {

Stops Claude Code from reading your .env file by adding a deny rule to settings.

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

More Claude tips /recap /focus /skill-doctor /autocompact 500k claude purge ~/work/my-repo --dry-run All Claude tips (83) All topics

Link