Skip to content

Instantly share code, notes, and snippets.

@cms
Created May 1, 2026 20:33
Show Gist options
  • Select an option

  • Save cms/9a8904e1a0f4b75fae50fc05bc41ece2 to your computer and use it in GitHub Desktop.

Select an option

Save cms/9a8904e1a0f4b75fae50fc05bc41ece2 to your computer and use it in GitHub Desktop.
Claude Code Silent .env Secret Leakage - Security Summary

πŸ•΅οΈ Claude Code Silent .env Secret Leakage

Source: darkzodchi @x.com | Full article: Knostic.ai


What Happened

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.


The Core Problem

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.


Why This Is a Serious Issue

  1. 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.

  2. 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.

  3. "Safe" commands become dangerous. If you give echo permissions, Claude Code could print out every secret in your .env: private keys, API tokens, everything.

  4. Anthropic's own guides recommend blocking it. Their own docs suggest adding deny rules for .env* files β€” which implies reading them is the default.

  5. The underlying cause is likely dotenv. Claude Code probably uses dotenv or dotenvx under the hood, which auto-loads .env files from the current working directory. This makes it hard to avoid without significant architectural changes.


How to Protect Yourself Right Now

  • Move .env files outside your project directory entirely β€” this is the most reliable fix
  • Add deny rules in ~/.claude/settings.json or .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

Bottom Line

"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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment