Skip to content

feat(sdk): add settingSources to control which config sources are loaded - #20784

Closed
jmc-epic wants to merge 1 commit into
anomalyco:devfrom
jmc-epic:feat/sdk-settings-sources
Closed

jmc-epic wants to merge 1 commit into
anomalyco:devfrom
jmc-epic:feat/sdk-settings-sources

Conversation

@jmc-epic

@jmc-epic jmc-epic commented Apr 3, 2026

Copy link
Copy Markdown

Issue for this PR

This PR adds a settingSources parameter for SDK usage, inspired by Claude Agent SDK's equivalent feature. When building specialized agents with the SDK, all config sources are loaded automatically — there's no way to scope which sources apply. This solves that by letting SDK users specify exactly which config sources to load.

(No existing issue — this is a net-new SDK feature contribution. Happy to open one if preferred.)

Type of change

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

What does this PR do?

Adds settingSources to ServerOptions and TuiOptions in the JS SDK. It accepts an array of source categories ("global", "project", "remote", "managed"). When provided, only the specified sources are loaded. The default is undefined which loads all sources (backward compatible).

The SDK serializes the array to an OPENCODE_SETTINGS_SOURCES env var on the spawned process. The core config loader in loadInstanceState() checks this env var and skips source blocks that aren't in the list. AGENTS.md instruction loading is also gated by the same mechanism.

Three things always load regardless: OPENCODE_CONFIG (explicit file override), OPENCODE_CONFIG_CONTENT (SDK programmatic config), and OPENCODE_CONFIG_DIR (explicit directory). OPENCODE_DISABLE_PROJECT_CONFIG continues working independently.

How did you verify your code works?

  • All existing tests pass (75 config + 9 instruction)
  • 15 new tests added and passing (10 config, 5 instruction) covering:
    • Default behavior (env var absent = all sources loaded)
    • Empty string = no filesystem sources
    • Single source selection (global-only, project-only)
    • Comma-separated multi-source selection
    • Always-loaded overrides (OPENCODE_CONFIG_DIR, OPENCODE_CONFIG_CONTENT)
    • Managed source gating
    • Directory filtering (project .opencode/ excluded when project not in sources)
    • Coexistence with OPENCODE_DISABLE_PROJECT_CONFIG
    • AGENTS.md gating for project, global, and OPENCODE_CONFIG_DIR
  • SDK typecheck passes clean
  • Ran bun typecheck from packages/opencode and packages/sdk/js — zero new errors

Screenshots / recordings

N/A — no UI changes.

Checklist

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

When using the SDK to build specialized agents, all config sources
(global, project, remote, managed) are loaded automatically. This
can pollute agent behavior with irrelevant settings.

Add settingSources parameter to ServerOptions and TuiOptions that
accepts an array of source categories: global, project, remote,
managed. Default behavior unchanged (all sources loaded). Setting
to empty array loads only programmatic config.

Also gates AGENTS.md instruction loading by the same source filter.
@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.

2 participants