Skip to content

feat(config): add OPENCODE_DISABLE_GLOBAL_CONFIG flag#21650

Open
ZY-Yim wants to merge 4 commits intoanomalyco:devfrom
ZY-Yim:feat/disable-global-config
Open

feat(config): add OPENCODE_DISABLE_GLOBAL_CONFIG flag#21650
ZY-Yim wants to merge 4 commits intoanomalyco:devfrom
ZY-Yim:feat/disable-global-config

Conversation

@ZY-Yim
Copy link
Copy Markdown

@ZY-Yim ZY-Yim commented Apr 9, 2026

Issue for this PR

Closes #21264

Type of change

  • Bug fix
  • New feature
  • Refactor / code improvement
  • Documentation

What does this PR do?

When embedding OpenCode via opencode serve in a host application (e.g. Electron app), all config is provided through
OPENCODE_CONFIG_CONTENT. But global config files and directories from ~/.config/opencode/ still get loaded and merged, which can
interfere with the intended configuration.

This adds OPENCODE_DISABLE_GLOBAL_CONFIG env var. When set to 1:

  • loadGlobal() in config.ts returns {} early, skipping config.json / opencode.json / opencode.jsonc under
    ~/.config/opencode/
  • ConfigPaths.directories() in paths.ts excludes Global.Path.config from the returned list, so global agents, skills, commands,
    and plugins are also not scanned

Project-level .opencode/ directories, OPENCODE_CONFIG, and OPENCODE_CONFIG_CONTENT are not affected. Follows the existing
OPENCODE_DISABLE_* naming convention.

How did you verify your code works?

  1. Set OPENCODE_DISABLE_GLOBAL_CONFIG=1 + OPENCODE_CONFIG_CONTENT and ran opencode serve — global config loading logs
    (service=config path=~/.config/opencode/...) no longer appear, only loaded custom config from OPENCODE_CONFIG_CONTENT
  2. Without the flag — behavior identical to before, no regression
  3. Verified .opencode/agents/ and .opencode/skills/ still load correctly with the flag set

Screenshots / recordings

N/A — no UI changes, env var only.

Checklist

  • I have tested my changes locally
  • I have not included unrelated changes in this PR

ZY-Yim added 2 commits April 7, 2026 11:38
…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.
@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Apr 9, 2026

Hey! Your PR title feat: add OPENCODE_DISABLE_GLOBAL_CONFIG flag to skip global config loading doesn't follow conventional commit format.

Please update it to start with one of:

  • feat: or feat(scope): new feature
  • fix: or fix(scope): bug fix
  • docs: or docs(scope): documentation changes
  • chore: or chore(scope): maintenance tasks
  • refactor: or refactor(scope): code refactoring
  • test: or test(scope): adding or updating tests

Where scope is the package name (e.g., app, desktop, opencode).

See CONTRIBUTING.md for details.

@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Apr 9, 2026

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"
#20784

Why it's related: This PR also addresses controlling which configuration sources are loaded. It provides a settingSources mechanism, which may overlap with or be an alternative approach to the OPENCODE_DISABLE_GLOBAL_CONFIG flag being added in PR #21650. Both PRs are trying to solve the problem of selectively loading/excluding config sources, particularly useful for embedded scenarios like opencode serve.

@ZY-Yim ZY-Yim changed the title feat: add OPENCODE_DISABLE_GLOBAL_CONFIG flag to skip global config loading feat(config): add OPENCODE_DISABLE_GLOBAL_CONFIG flag Apr 9, 2026
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.

[FEATURE]: add OPENCODE_DISABLE_GLOBAL_CONFIG flag to skip global config loading

1 participant