Skip to content

Loading env files no longer clobbers the loaded environment #3888

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

spott
Copy link

@spott spott commented Apr 25, 2025

If the user has an env variable loaded, that variable is no longer clobbered by a .env file referencing the same variable.

So if your env has "ANTHROPIC_API_KEY", and you have an env file with "ANTHROPIC_API_KEY", you will use the value from your environment, rather than your env file. This sets up the priority:

$HOME/.env
$GIT_ROOT/.env
$PWD/.env
${--env-file}

Part of the reason I think this is the correct way to do this is that there are a couple of secret management tools that will parse an env file with secret references into the environment with secrets (so an env file with USERNAME="op://vault/secret name/username" gets instantiated in the environment as USERNAME=<my secret username>). This is how I discovered this behavior.

@@ -326,7 +326,6 @@ def generate_search_path_list(default_file, git_root, command_line_file):
uniq.reverse()
files = uniq
files = list(map(str, files))
files = list(dict.fromkeys(files))
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm pretty sure this doesn't actually change anything (maybe it was from a previous version to make the list unique). If it actually does something, I'd love to know what.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant