Skip to content

feat(config): add OPENCODE_DISABLE_GLOBAL_CONFIG flag - #21650

Closed
ZY-Yim wants to merge 7 commits into
anomalyco:devfrom
ZY-Yim:feat/disable-global-config
Closed

ZY-Yim wants to merge 7 commits into
anomalyco:devfrom
ZY-Yim:feat/disable-global-config

Conversation

@ZY-Yim

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

Copy link
Copy Markdown

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

github-actions Bot commented Apr 9, 2026

Copy link
Copy Markdown
Contributor

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

github-actions Bot commented Apr 9, 2026

Copy link
Copy Markdown
Contributor

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
@carstenrntng

Copy link
Copy Markdown

Hey! Just wanted to bump this — I have a use case where I'm shipping a repo with a self-contained opencode.json that shouldn't merge in user's global config from ~/.config/opencode/.

The implementation here looks correct and minimal. The CI failure appears to be a flaky Windows e2e test (status popover can switch to plugins tab) that's unrelated to the config changes — all Linux tests pass and the Windows failure is a UI timing issue.

Would be great to see this merged! Could someone re-run the CI or merge if the flaky test is a known issue?

Thanks!

…nfig

# Conflicts:
#	packages/opencode/src/config/config.ts
#	packages/opencode/src/config/paths.ts
#	packages/opencode/src/flag/flag.ts
@ZY-Yim

ZY-Yim commented Apr 24, 2026

Copy link
Copy Markdown
Author

Hey! Just wanted to bump this — I have a use case where I'm shipping a repo with a self-contained opencode.json that shouldn't merge in user's global config from ~/.config/opencode/.

The implementation here looks correct and minimal. The CI failure appears to be a flaky Windows e2e test (status popover can switch to plugins tab) that's unrelated to the config changes — all Linux tests pass and the Windows failure is a UI timing issue.

Would be great to see this merged! Could someone re-run the CI or merge if the flaky test is a known issue?

Thanks!

Hi @carstenrntn, Thanks for the bump! I've rebased and restarted the tests. Fingers crossed (and praying to the CI gods) that it passes and gets accepted soon! 🤞

@Xynonners

Copy link
Copy Markdown

Hey there,
Just wanted to bump this again as well. I'm doing plugin development and it's very useful to not have the dev environment collide with the main opencode's plugins (which are being used to build the plugin in the dev environment).

@bot-32142

Copy link
Copy Markdown

Hello maintainers,
Could you please take a look? This is really just 3-line change but significantly simplifies config management for plugin development/testing.

@rekram1-node

Copy link
Copy Markdown
Collaborator

Automated PR Cleanup

Thank you for contributing to opencode.

Due to the high volume of PRs from users and AI agents, we periodically close older PRs using automated criteria so maintainers can focus review time on the most active and community-supported contributions.

This PR was closed because it matched the following cleanup criteria:

  • The PR was created more than 1 month ago
  • The PR had fewer than 2 positive reactions
  • Positive reactions are counted as thumbs-up, heart, celebration, or rocket reactions on the PR

PRs created within the last month are not affected by this cleanup.

If you believe this PR was closed incorrectly, or if you are still actively working on it, please leave a comment explaining why it should be reopened. A maintainer can review and reopen it if appropriate.

Thanks again for taking the time to contribute.

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

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

5 participants