Skip to content

fix: preserve shell environment over dotenv files - #5640

Closed
mikemikimike wants to merge 1 commit into
Aider-AI:mainfrom
mikemikimike:fix/dotenv-environment-precedence-5622
Closed

fix: preserve shell environment over dotenv files#5640
mikemikimike wants to merge 1 commit into
Aider-AI:mainfrom
mikemikimike:fix/dotenv-environment-precedence-5622

Conversation

@mikemikimike

Copy link
Copy Markdown

Summary

load_dotenv_files() currently loads every discovered dotenv file with override=True, allowing a repository .env file to replace values explicitly exported in the user's shell, including provider credentials and endpoints.

Changes

  • Preserve the existing dotenv search order and last-file-wins behavior for variables that were not set before loading.
  • Restore environment variables that existed before dotenv loading so explicit shell configuration takes precedence.
  • Add regression coverage for shell precedence while retaining the existing file-order coverage.

Fixes #5622

Tests

  • python -m pytest tests/basic/test_main.py::TestMain::test_load_dotenv_files_override tests/basic/test_main.py::TestMain::test_load_dotenv_files_does_not_override_existing_env tests/basic/test_main.py::TestMain::test_env_file_override -q (3 passed)
  • pre-commit run --files aider/main.py tests/basic/test_main.py (passed)

@CLAassistant

CLAassistant commented Aug 28, 2026

Copy link
Copy Markdown

CLA assistant check
All committers have signed the CLA.

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.

.env files are loaded with override=True, silently replacing variables exported in the user's shell

2 participants