Skip to content

fix: let app config override system env vars for API keys#439

Merged
gabrielste1n merged 1 commit intoOpenWhispr:mainfrom
DamianPala:fix/env-override-priority
Mar 15, 2026
Merged

fix: let app config override system env vars for API keys#439
gabrielste1n merged 1 commit intoOpenWhispr:mainfrom
DamianPala:fix/env-override-priority

Conversation

@DamianPala
Copy link
Contributor

@DamianPala DamianPala commented Mar 15, 2026

Summary

API keys changed through Settings are ignored after app restart if the same key is exported in the user's shell environment

Problem

When a user changes an API key in Settings, it's saved to the app's .env file. But dotenv.config() was called without override, so any matching environment variable (e.g. OPENAI_API_KEY in ~/.profile or ~/.bashrc) always took precedence after restart. The user sees the new key in the UI but the app uses the old one.

Affects all API keys on any platform where the user exports keys in their shell.

Solution

Add override: true to dotenv.config() for the userData .env file only. Fallback .env files (development, resources, legacy) keep the default behavior so they don't override anything.

Test plan

  • Export an API key in shell profile (e.g. export OPENAI_API_KEY=old), set a different key in Settings, restart app, verify new key is used

dotenv loaded the userData .env without override, so API keys
exported in the user's shell profile always won. With override: true
the keys saved through Settings take precedence.
@DamianPala DamianPala marked this pull request as ready for review March 15, 2026 11:18
@gabrielste1n gabrielste1n merged commit 0b40dce into OpenWhispr:main Mar 15, 2026
4 checks passed
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.

2 participants