diff --git a/aider/main.py b/aider/main.py index b040c4194..652425905 100644 --- a/aider/main.py +++ b/aider/main.py @@ -358,11 +358,21 @@ def register_models(git_root, model_settings_fname, io, verbose=False): def load_dotenv_files(git_root, dotenv_fname, encoding="utf-8"): + # Standard .env file search path dotenv_files = generate_search_path_list( ".env", git_root, dotenv_fname, ) + + # Explicitly add the OAuth keys file to the beginning of the list + oauth_keys_file = Path.home() / ".aider" / "oauth-keys.env" + if oauth_keys_file.exists(): + # Insert at the beginning so it's loaded first (and potentially overridden) + dotenv_files.insert(0, str(oauth_keys_file.resolve())) + # Remove duplicates if it somehow got included by generate_search_path_list + dotenv_files = list(dict.fromkeys(dotenv_files)) + loaded = [] for fname in dotenv_files: try: