One bad dependency can turn Claude Code against your .env file
One bad dependency can turn Claude Code against your .env file.
It already happened here, here, here, here, here and here, and the list keeps growing every day.
A security scan of my Mac just flagged 34 vulnerabilities, and 11 secrets sit in plain text in my .env files.
On December 1, Claude Code bought me a server on Hetzner. It wrote a script that waited for a sold-out machine and bought it 10 seconds after it came back in stock. The API token it used can create servers on my account, which means it can charge my credit card. Claude never saw my API token.
This post is about why that matters, and how it works.
A .env file is readable by everything you run
A .env file is plain text in your home folder.
Any process running as your user can read it, without a prompt.
That includes every dependency you install: its install scripts, its code, and everything it pulls in.
macOS only asks for permission to a few folders: Desktop, Documents, Downloads, iCloud Drive and removable or network volumes (the full list).
A project in ~/git or ~/code gets no extra protection.
It already happened
In August 2025, malicious releases of Nx, a popular build tool, did exactly this (Wiz, Snyk).
They searched developers’ disks for .env files, SSH keys and tokens, and pushed what they found to public GitHub repos under the victim’s own account.
They also ran whatever AI coding CLI was installed, Claude Code included, with its permission checks switched off, and told it to hunt for secrets.
Wiz counted over 1,000 valid GitHub tokens in the leak.
Since then:
- November 2025, Shai-Hulud 2.0. A self-spreading npm worm leaked 14,206 secrets across 487 organizations, by Check Point’s count.
- March 2026, LiteLLM. Two hijacked releases of the popular Python library for calling AI models went after SSH keys, cloud credentials and “environment files commonly used to store secrets” (Sonatype). It gets about 3 million downloads a day.
- April 2026, a fake
tanstackpackage. Apostinstallhook sent.envand.env.localto a webhook the moment you installed it (Aikido). - May 2026, node-ipc. A hijacked maintainer account shipped a payload that took
.envfiles, SSH keys and cloud credentials, about 822,000 downloads a week (SafeDep). - May 2026, Nx Console. The VS Code extension, with over 2.2 million installs, was hijacked with a GitHub token stolen in an earlier attack. Its payload took GitHub, npm, AWS and 1Password tokens, and Claude Code’s configuration files (report).
The next one is a pnpm install, pip install or cargo build away.
Agents make it worse
We put more tokens in .env so the agent can use them.
And the agent will go find them for whoever asks.
There is a second copy, too.
Claude Code stores every session transcript in plain text under ~/.claude/projects, for 30 days by default.
When Claude reads a secret, it lands there.
I searched mine and found a Sentry token and a private key.
Count yours
This counts the secret-looking lines in your .env files.
It skips node_modules, ~/Library and .env.example templates, 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
Mine said 11, in 7 files.
How Claude bought a server without seeing the token
My Hetzner token lives in Automic Vault, not in a .env file.
Claude Code ran the buy script like this:
av inject +HCLOUD_TOKEN -- sh buy-server.sh
av puts the token into the environment of that one command and nothing else.
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.
Every time something asks for a secret, my Mac shows this prompt:
It shows the command, the secret’s name, the working directory, and the whole chain of who’s asking:
Claude → zsh → av → hcloud
I click Approve Once or Deny.
For the buy script, I approved once, and the token stayed inside that one process until it bought the server.
The server was a one-off.
The secret I use every day is the App Store Connect API key for Note to Self, my iOS app.
It lives in av too, so Claude Code uploads new TestFlight betas without ever seeing the key.
av is made by Max Howell, who created Homebrew.
That is a big part of why I trust a tool with my secrets, and you can check the signature yourself:
codesign -dv --verbose=2 /usr/local/bin/av 2>&1 | grep Authority
It also has av scan, which audits your machine for exposed secrets and weak settings.
That is where my 34 came from, and it looks at more than .env files: SSH keys, CLI login files, shell history and macOS settings.
I have no connection to Automic Vault, I just use it.
Other ways to do the same
The idea is the same everywhere: keep the secret in a vault, and inject it into one command when you run it.
1Password.
Put references in .env instead of values, API_KEY="op://vault/item/field", then run:
op run --env-file=.env -- npm start
Your .env then holds no secrets, so it’s safe to read (docs).
macOS Keychain. No extra tool needed. Store the secret once (it asks for the value, so it stays out of your shell history):
security add-generic-password -s myapi -a "$USER" -w
Then read it into one command:
API_KEY=$(security find-generic-password -s myapi -w) npm start
Bitwarden Secrets Manager.
bws run -- npm start (docs).
Its access token has to live somewhere on the machine, too.
Doppler and Infisical.
doppler run -- npm start and infisical run -- npm start.
Both keep a login token on your machine.
dotenvx encrypts your .env, but keeps the decryption key right next to it in .env.keys.
Anything that can read one can read the other, so it doesn’t help here.
What this doesn’t fix
If the malicious code runs inside the very command that gets the secret, it gets the secret. A vault shrinks the window from “every process, all the time” to “this one process, when I say so”. That is a big difference, but it isn’t zero.
And a vault only protects secrets you move into it. Until then, they sit in plain text where every dependency can read them.
Run the command above, and start with the biggest number.