Safeguard
Developer Tools•

Is direnv safe for project secrets? What direnv allow really does

direnv loads an .envrc on entry, and direnv allow is the trust step. Learn what it protects against, what it misses, and how to use it safely.

Safeguard Security Team
3 min read

direnv is reasonably safe for local project settings if you treat .envrc as code. It blocks a new or changed .envrc until you run direnv allow, which stops a cloned repo from running scripts when you merely cd into it. It does not protect secrets you commit, so keep values out of the file.

What direnv does

The direnv manual explains that before each prompt it checks for an .envrc file in the current or parent directories. If one exists and is allowed, direnv loads it into your shell, and unloads the changes when you leave the folder. That gives each project its own environment variables without editing your shell profile.

An .envrc is a shell script, so it can run any command, not just set variables.

The trust mechanism

The manual describes the security mechanism plainly. When you create or change an .envrc, direnv complains that it is blocked, and nothing loads until you run direnv allow. This exists to avoid loading new files you have not reviewed.

Related commands from the manual:

CommandPurpose
direnv allowGrants permission to load the given .envrc or .env file
direnv denyRevokes that authorization
direnv editOpens the file in your editor and allows it afterwards
direnv pruneRemoves old allowed files

direnv records which files you approved under its data directory, in an allow folder. Changing the file's contents means you must approve it again.

What the allow step does not do

It confirms that you chose to run the file. It does not tell you the file is safe. If you run direnv allow on a freshly cloned repository without reading the .envrc, you have just run its code on your machine. Review first, as you would before running an install script.

It also does nothing about where the secrets live. If a teammate puts a real token in a committed .envrc, direnv will happily load it, and the token is now in your repository history.

A safe pattern for secrets

Keep the .envrc free of values. Have it call out to wherever the secret lives, such as a command line tool for your password manager or a cloud sign-in that produces a short-lived credential, and keep personal overrides in an untracked file. Commit a template with placeholder names so teammates know which variables to set.

Add the real file to a global ignore so it cannot be committed by accident. When you review a pull request that touches .envrc, read it like a script change, because it is one.

Where Safeguard fits

Safeguard works on the dependency and code side of your software: SBOM and dependency scanning, reachability analysis and policy gates. It does not store or manage credentials, so keep using your password manager, secrets manager or cloud identity for that. You can run a free scan of a project at gold.safeguard.sh/scan.

Quick check

Does direnv encrypt anything?

No. It sets environment variables from a file you approve. Encryption and storage are separate concerns.

Should I commit .envrc?

You can commit one that has no values and only calls out to a secure source. Review changes carefully, since it is executable.

Do I need to allow again after an edit?

Yes. Per the manual, a changed file is blocked until you allow it again.

Sources

Last reviewed: 19 October 2026.

Never miss an update

Weekly insights on software supply chain security, delivered to your inbox.

Self-healing security runs on Safeguard.

Your first fix PR is minutes away.

No sales call required, even your agent can complete the purchase over MCP.