Skip to content

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

Open
jmc-epic wants to merge 1 commit intoanomalyco:devfrom
jmc-epic:feat/sdk-settings-sources
Open

feat(sdk): add settingSources to control which config sources are loaded#20784
jmc-epic wants to merge 1 commit intoanomalyco:devfrom
jmc-epic:feat/sdk-settings-sources

Conversation

@jmc-epic
Copy link
Copy Markdown

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

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.
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.

1 participant