Source: darkzodchi @x.com | Full article: Knostic.ai
A developer (Dor Munis) was debugging an odd HTTP 407 proxy error when using Claude Code's /login command. Everything else worked fine β curling Anthropic's API directly returned 200. Running Claude Code in debug mode revealed the culprit: it was silently reading his .env file and loading his HTTP_PROXY credentials into memory automatically. Moving the .env outside the project directory fixed it immediately.
Claude Code automatically loads .env, .env.local, and similar files the moment it opens a project. No prompt. No permission request. No warning.
This means every secret in your .env files β API keys, database passwords, Stripe tokens, private keys, proxy credentials β gets loaded into memory the moment Claude Code touches your project.
Anthropic's own docs say file reads may be transmitted to their servers. That doesn't prove secrets leave your machine, but it also doesn't rule it out. The safe assumption: if it's not explicitly denied, assume it could be accessed.
-
No consent, no disclosure. It's not mentioned in Anthropic's Terms of Service or Privacy Policy. There's no permission prompt when it happens.
-
Loading β sending, but the risk is real. The secrets go into memory. Anthropic processes file reads server-side. That means secrets could be transmitted β there's no guarantee they aren't.
-
"Safe" commands become dangerous. If you give
echopermissions, Claude Code could print out every secret in your.env: private keys, API tokens, everything. -
Anthropic's own guides recommend blocking it. Their own docs suggest adding deny rules for
.env*files β which implies reading them is the default. -
The underlying cause is likely dotenv. Claude Code probably uses
dotenvordotenvxunder the hood, which auto-loads.envfiles from the current working directory. This makes it hard to avoid without significant architectural changes.
- Move
.envfiles outside your project directory entirely β this is the most reliable fix - Add deny rules in
~/.claude/settings.jsonor.claudeignore:{ "permissions": { "deny": [".env*"] } } - Disable auto-run in sensitive repositories
- Use an isolated environment (container/VM) when working with production credentials
- Never assume a coding assistant can't see something β if it's in the working directory, treat it as accessible
"If a file is not explicitly denied, it is accessible."
This isn't a minor bug β it's a design flaw. Loading sensitive files without user consent is a fundamental security boundary violation. Until Anthropic changes the default behavior, it's on you to audit your environment and lock things down.