env-guard

Reviewed at commit 0f95222

Blocks Claude from editing or writing .env files, private keys and other common secret files, and tells it why.

Made by
modsforclaude
What we checked

Only steps in when Claude edits or writes a file, and only looks at the file path, never at what is in the file. Makes no network calls and stores nothing.

Review details

Written and reviewed by the modsforClaude.com maintainers at the pinned commit. Hooks Edit, Write and NotebookEdit tool calls and uses $.fs.stat to resolve symlinks. Validates with claude plugin validate; 5 of 5 tests pass on Claude Code 2.1.286.

What it uses
  • Reads your prompts: no
  • Sees tool calls: no
  • Blocks or changes tool calls: no
  • Reads or writes files: no
  • Runs programs on your machine: no
  • Calls the model (uses tokens): no
  • Sends data over the network: no
  • Stores data: no
  • Shows something on screen: no
Hooked events

When Claude tries to change a protected file with Edit, Write or NotebookEdit, the call is refused before it runs and Claude is told why, so it asks you to make the change yourself.

Protected by default: .env, .env.*, *.pem, *.key, *.pfx, *.p12, id_rsa, id_dsa, id_ecdsa, id_ed25519, secrets.*. Always allowed: .env.example, .env.sample, .env.template. Both lists can be changed in the settings of the mod.

Symlinks that lead to a protected file are blocked too. The mod only looks at the file path: it never reads the content of the edit or the files themselves, makes no network calls and stores nothing.

What it does not do

It is a safety net against accidental edits, not a security boundary. It does not block reading secret files, and it does not block shell commands that write to them, such as echo X >> .env. Use Claude Code's permission rules for those.

Load it

See How to load a Claude Code mod for the terminal and the desktop app.

Made this mod? Add a badge to your README

modsforClaude badge for env-guard

Paste this into your README. The badge says reviewed once the current version has been reviewed, and links readers to this page.

[![Listed on modsforClaude](https://modsforclaude.com/badge/env-guard.svg)](https://modsforclaude.com/mods/env-guard/)

← All mods