Skip to content

Config variables in opencode.json overwritten with actual values on start up #9086

Closed

Description

@spenceforce

Description

I set api keys following guidance on variables in config files here. When I start opencode, the variables are overwritten with the actual value in opencode.json.

This defeats the purpose of using variables to keep secrets outside of opencode.json and makes it impossible to commit opencode.json as it can expose secrets.

Plugins

No response

OpenCode version

1.1.25

Steps to reproduce

  1. Use the env variable in opencode.json for a provider API key.
  2. Start opencode.
  3. Reload opencode.json to see if the variable was replaced with the actual value.

Screenshot and/or share link

No response

Operating System

Ubuntu 25.10

Terminal

Ubuntu terminal

Activity

  1. github-actions commented on Jan 17, 2026

    @github-actions
    Contributor

    This issue might be a duplicate of or related to existing issues. Please check:

    These issues all relate to how environment variables and secrets are handled in configuration files. If your case is specific to the overwriting behavior you described, it may be a distinct bug worth investigating separately.

    Feel free to ignore if none of these address your specific case.

  2. cravenceiling commented on Jan 17, 2026

    @cravenceiling
    Contributor

    I couldn't reproduce this. Where is your opencode.json file? Also, what is the output of opencode debug config? Does your api key appear there?

  3. spenceforce commented on Jan 17, 2026

    @spenceforce
    Author

    This happens in .config/opencode/opencode.json and my project specific opencode.json. I put the {env:API_KEY} back and when I opened opencode it didn't change it. But when I removed "$schema": "https://opencode.ai/config.json" from opencode.json and restarted opencode, it replaced the variable again. I assume it reads the config, then rewrites it if "$schema": "https://opencode.ai/config.json" is missing and writes the values for each field instead of the original string.

  4. rekram1-node commented on Jan 17, 2026

    @rekram1-node
    Contributor

    yes that is the case, if that schema field is missing

  5. spenceforce commented on Jan 17, 2026

    @spenceforce
    Author

    Ok, thats a security issue. Opencode should never write secrets to its config files. I find it odd that it rewrites my config at all instead of using a default value for "$schema" considering it uses default values for everything else.

  6. rekram1-node commented on Jan 18, 2026

    @rekram1-node
    Contributor

    fixed: 052f887

  7. spenceforce commented on Jan 18, 2026

    @spenceforce
    Author

    Awesome, thank you!

  8. github-actions commented on Mar 27, 2026

    @github-actions
    Contributor

    To stay organized issues are automatically closed after 90 days of no activity. If the issue is still relevant please open a new one.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

bugSomething isn't workingdocs

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions