You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
[FEATURE]: Store provider credentials in environment variables #5423
I have verified this feature I'm about to request hasn't been suggested before.
Describe the enhancement you want to request
User problem
As a security minded user, I don't want to store api keys in files, especially not in a shared environment.
Instead of storing provider credentials in ~/.local/share/opencode/auth.json, I'd prefer to either have the location configurable (e.g. setting $OPENCODE_AUTH_JSON would tell opencode where it should read/write the auth.json file) or allow passing provider keys through environment variables.
Proposal
I see two different approaches
Configurable auth.json location (recommended)
Currently, the location of the opencode auth.json is hardcoded. We should make this configurable with the OPENCODE_AUTH_JSON environment variable. The default value can be ~/.local/share/opencode/auth.json to keep it backward compatible.
Passing provider keys from environment variables
I see three possible approaches:
for every configured provider with an invalid/not configured apiKey, opencode looks for the OPENCODE_<PROVIDERNAME>_APIKEY environment variable
for every known provider, opencode looks for the OPENCODE_<PROVIDERNAME>_APIKEY environment variable
for every configured provider with type: "api", keyFrom: "envVar" opencode looks for the OPENCODE_<PROVIDERNAME>_APIKEY environment variable
+1 for being able to set auth config via ENV vars, because auth.json is not a good experience when using OpenCode in a non-interactive mode as an autonomous agent.
Reacted by Qijia Yang, Nazmus Sayad, Quino Terrasa, Thomas Haertel, diktamxx and Teddy Thomas
Activity
github-actions commentedon Dec 12, 2025
This issue might be a duplicate of existing issues. Please check:
Feel free to ignore if your specific use case differs from these alternatives.
MrAMS commentedon May 8, 2026
Is there something like
OPENCODE_AUTH_JSONnow?askonomm commentedon May 26, 2026
+1 for being able to set auth config via ENV vars, because auth.json is not a good experience when using OpenCode in a non-interactive mode as an autonomous agent.