A .env file is a plain text file in your home folder.
Any process running as your user can read it without a prompt, and that includes every dependency you install: its install scripts, its code, and everything it pulls in.
On macOS, privacy prompts only cover a few folders (Desktop, Documents, Downloads, iCloud Drive), so a project in ~/git or ~/code has no extra protection.
This keeps happening.
- August 2025, Nx ("s1ngularity"): malicious releases scanned disks for
.env files, SSH keys and tokens, and pushed them to public GitHub repos under the victim's own account. They also ran any installed AI coding CLI, Claude Code included, with permission checks disabled, and told it to hunt for secrets. Wiz counted over 1,000 valid GitHub tokens. - November 2025, Shai-Hulud 2.0: a self-spreading npm worm, 14,206 leaked secrets across 487 organizations by Check Point's count.
- March 2026, LiteLLM: two hijacked releases went after SSH keys, cloud credentials and "environment files commonly used to store secrets". About 3 million downloads a day.
- April 2026, a fake
tanstack npm package: a postinstall hook sent .env and .env.local to a webhook. - May 2026, node-ipc: a hijacked maintainer account shipped a payload that took `.env` files, SSH keys and cloud credentials. About 822,000 downloads a week.
- May 2026, Nx Console: the VS Code extension (2.2M installs) was hijacked with a GitHub token stolen in an earlier attack. It took GitHub, npm, AWS and 1Password tokens, and Claude Code's configuration files.
Agents make it worse.
We put more tokens in .env so the agent can use them.
Count yours.
This skips node_modules, ~/Library and .env.example files, and took 25 seconds on my Mac:
find ~ -name ".env*" -not -name "*.example" -not -path "*/node_modules/*" -not -path "*/Library/*" -print0 2>/dev/null | xargs -0 grep -hE "^[A-Z_]*(KEY|TOKEN|SECRET|PASSWORD)[A-Z_]*=." | wc -l
It can still count a placeholder or two if you keep templates under another name.
Mine found 11, in 7 files.
What I do instead.
On December 1, I had Claude Code write a script that bought a Hetzner server the moment it came back in stock.
The Hetzner API token can create servers on my account, so it can charge my card.
Claude never saw my API token.
The script ran as:
av inject +HCLOUD_TOKEN -- sh buy-server.sh
The token lives in a vault, and only that one command gets it as an environment variable.
š Claude sees the command and its output, never the token value. š
I grepped the session transcript afterwards to be sure, and the token isn't in it.
Each time something asks for a secret, I get a native prompt that shows the command, the secret name, the working directory and the full chain of who's asking (Claude ā zsh ā av ā hcloud), with "Approve Once" or "Deny".
av is Automic Vault. The binary is signed by Max Howell, who created Homebrew, which is a big part of why I trust it (codesign -dv --verbose=2 /usr/local/bin/av 2>&1 | grep Authority shows it).
Its av scan is where my 34 came from: it looks at more than `.env` files, including SSH keys, CLI login files, shell history and macOS settings.
I have no connection to it.
Other ways to do the same:
- 1Password: put
op://vault/item/field references in .env instead of values, then op run --env-file=.env -- npm start. - macOS Keychain: store with
security add-generic-password -s myapi -a "$USER" -w (it prompts for the value, so it stays out of your shell history), then API_KEY=$(security find-generic-password -s myapi -w) npm start. - Bitwarden Secrets Manager:
bws run -- npm start. - Doppler and Infisical:
doppler run -- and infisical run --. Both keep a login token on the machine. - dotenvx encrypts
.env, but its decryption key sits next to it in .env.keys, so it doesn't help against this.
Limits.
None of these help if the malicious code runs inside the same command that gets the secret.
They shrink the window from "every process, all the time" to "this one process, when I say so".
And a vault only protects secrets you move into it.
If you want to read the full blog version: https://jurajb.dev/env-secrets-claude-code/
That's it. Have fun with agents and remember that plain files are plain files. chmod 600 doesn't save you. The apps and CLI tools are still running under your user and can read the files.