feat(config): add OPENCODE_DISABLE_GLOBAL_CONFIG flag#21650
feat(config): add OPENCODE_DISABLE_GLOBAL_CONFIG flag#21650ZY-Yim wants to merge 4 commits intoanomalyco:devfrom
Conversation
…config loading When embedding OpenCode in a service (e.g. via `opencode serve`), the host application typically provides all configuration through `OPENCODE_CONFIG_CONTENT`. Loading global config files from `~/.config/opencode/` can cause unexpected behavior by merging unrelated user-level settings. This adds `OPENCODE_DISABLE_GLOBAL_CONFIG` environment variable that, when set to `1` or `true`, makes `loadGlobal()` return an empty config object, skipping all files under the global config directory (`config.json`, `opencode.json`, `opencode.jsonc`). This flag only affects global config — project-level `.opencode/` directories, `OPENCODE_CONFIG`, and `OPENCODE_CONFIG_CONTENT` continue to load normally.
…ories When OPENCODE_DISABLE_GLOBAL_CONFIG is set, exclude Global.Path.config (~/.config/opencode/) from the directories list. This prevents scanning global agents, skills, commands, and plugins when global config is disabled.
|
Hey! Your PR title Please update it to start with one of:
Where See CONTRIBUTING.md for details. |
|
The following comment was made by an LLM, it may be inaccurate: Found a potential duplicate: PR #20784: "feat(sdk): add settingSources to control which config sources are loaded" Why it's related: This PR also addresses controlling which configuration sources are loaded. It provides a |
Issue for this PR
Closes #21264
Type of change
What does this PR do?
When embedding OpenCode via
opencode servein a host application (e.g. Electron app), all config is provided throughOPENCODE_CONFIG_CONTENT. But global config files and directories from~/.config/opencode/still get loaded and merged, which caninterfere with the intended configuration.
This adds
OPENCODE_DISABLE_GLOBAL_CONFIGenv var. When set to1:loadGlobal()inconfig.tsreturns{}early, skippingconfig.json/opencode.json/opencode.jsoncunder~/.config/opencode/ConfigPaths.directories()inpaths.tsexcludesGlobal.Path.configfrom the returned list, so global agents, skills, commands,and plugins are also not scanned
Project-level
.opencode/directories,OPENCODE_CONFIG, andOPENCODE_CONFIG_CONTENTare not affected. Follows the existingOPENCODE_DISABLE_*naming convention.How did you verify your code works?
OPENCODE_DISABLE_GLOBAL_CONFIG=1+OPENCODE_CONFIG_CONTENTand ranopencode serve— global config loading logs(
service=config path=~/.config/opencode/...) no longer appear, onlyloaded custom config from OPENCODE_CONFIG_CONTENT.opencode/agents/and.opencode/skills/still load correctly with the flag setScreenshots / recordings
N/A — no UI changes, env var only.
Checklist