[BUG] Prevent Claude Code from loading .env.local into environment
Preflight Checklist
- [x] I have searched existing issues and this hasn't been reported yet
- [x] This is a single bug report (please file separate reports for different bugs)
- [x] I am using the latest version of Claude Code
What's Wrong?
Claude code is sourcing .env* files on start and reading project defaults into the shell which then overrides settings defined in files like .env.test or .env.test.local which would normally be picked up when running unit tests but are now ignored because there's a shell environment set. This causes unit tests to run against local dev resources like databases.
What Should Happen?
Claude should not source industry standard .env files when starting - instead it should source .claude.env or some other namespaced .env files to prevent reading project defaults into claude's shell environment. People wanting values from .env can port those specific values into those files.
Error Messages/Logs
None.
Steps to Reproduce
Check shell env before loading clause
- set | grep -i "database"
- witness no DATABASE_URL is set
- start claude code
- as claude to run set and tell you what database_url is set to
- witness that it is now set to the same value as in your .env file(s)
Claude Model
Opus
Is this a regression?
I don't know
Last Working Version
NA
Claude Code Version
v2.0.54
Platform
Anthropic API
Operating System
macOS
Terminal/Shell
iTerm2
Additional Information
Have checked in iterm2 as well as terminal on mac and both behave the same.
Current workaround is to rename .env to ._env then start claude code then rename back. This works but it's a pain and if you forget this step you're at risk.
This issue has 3 comments on GitHub. Read the full discussion on GitHub ↗