[BUG] Claude Code loads and exports .env on startup, even with read permissions denied

Resolved 💬 9 comments Opened Aug 12, 2025 by gndk Closed Jan 9, 2026

Environment

  • Platform (select one):
  • [ ] Anthropic API
  • [ ] AWS Bedrock
  • [ ] Google Vertex AI
  • [ ] Other: <!-- specify -->
  • Claude CLI version: 1.0.73 (Claude Code)
  • Operating System: macOS & Ubuntu 22.04
  • Terminal: iterm2 & ghostyy

Bug Description

Claude Code loads and exports .env on startup, even with read permissions denied.

Steps to Reproduce

  1. Start CC in empty directory, ask it "check APP_ENV env var". It will output empty.
  2. Add .env with "APP_ENV=dev".
  3. Start CC again, ask it "check APP_ENV env var". It will output "dev".
  4. Add permissions.deny config for .env and .env.*, per https://docs.anthropic.com/en/docs/claude-code/settings#excluding-sensitive-files
  5. Start CC again, ask it "check APP_ENV env var". It will output "dev". Ask it "whats in .env". It won't be able to read the file because of the permissions settings.

Expected Behavior

Either don't load .env files and export the variables as env vars OR at least document it.

The permissions should not be ignored either way.

Actual Behavior

Claude Code loads .env on startup, even with permissions denied in settings.json.

Additional Context

It is NOT inheriting it from my shell session. The var is not set there.

<img width="710" height="572" alt="Image" src="https://github.com/user-attachments/assets/9fea7f3d-c9f8-40ec-87f9-c06d0ea98e37" />

View original on GitHub ↗

This issue has 9 comments on GitHub. Read the full discussion on GitHub ↗