Skip to content

fix(core): keep OPENCODE_CONFIG_DIR additive for global AGENTS.md - #47468

Open
minutechreview wants to merge 1 commit into
anomalyco:devfrom
minutechreview:fix/opencode-config-dir-additive-agents-md
Open

minutechreview wants to merge 1 commit into
anomalyco:devfrom
minutechreview:fix/opencode-config-dir-additive-agents-md

Conversation

@minutechreview

Copy link
Copy Markdown

Issue for this PR

Closes #28658, #32825

Type of change

  • Bug fix

What does this PR do?

OPENCODE_CONFIG_DIR is meant to add a second config location, not replace the global one. It does add correctly for agents/commands/skills, because ConfigPaths.directories() always includes Global.Path.config (the static XDG path) regardless of the flag. But the global AGENTS.md lookup in session/instruction.ts and the equivalent lookup in core/instruction-context.ts both build their path from Global.Service's config property, which is Flag.OPENCODE_CONFIG_DIR ?? Global.Path.config — so once you set the env var, ~/.config/opencode/AGENTS.md is never checked again.

I added Global.configDirs(config) in packages/core/src/global.ts, which returns [config, Global.Path.config] (override first so it still wins if it defines its own AGENTS.md, deduped when they're the same value), and pointed both loaders at it instead of duplicating the logic. First-match-wins order is preserved in both call sites.

How did you verify your code works?

  • Added unit tests for Global.configDirs and for the extracted globalInstructionFiles helper in session/instruction.ts that assert the override is checked, the real default is still checked when the override doesn't have the file, override still wins when both exist, and no duplicate path when they're the same.
  • Added an integration test in core/test/instruction-context.test.ts that writes an AGENTS.md to the real global config dir, points OPENCODE_CONFIG_DIR at an unrelated empty dir, and confirms the global file still loads.
  • Confirmed the new tests fail against the pre-fix code (via git stash) and pass against the fix.
  • bun test for packages/core (1101 tests) and packages/opencode (3599 tests): all passing.
  • bun turbo typecheck for both packages: clean.
  • oxlint on all changed files: no new warnings (3 pre-existing unrelated unused-import warnings in instruction.ts are unchanged from dev).

Checklist

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

Setting OPENCODE_CONFIG_DIR made both the session-level and
system-context instruction loaders (session/instruction.ts and
core/instruction-context.ts) stop checking the real XDG global config
dir for AGENTS.md, since both built their global lookup path from
Global.Service's `config` field, which resolves to
`OPENCODE_CONFIG_DIR ?? Global.Path.config` and therefore fully
replaces the static default instead of adding to it. This matches
ConfigPaths.directories() reading Global.Path.config directly, but the
instruction loaders never did the same.

Add Global.configDirs(config), which returns the override first (so it
still wins when it defines its own AGENTS.md) followed by the real
static default when they differ, and use it from both loaders instead
of duplicating the logic.

Closes anomalyco#28658, anomalyco#32825
@hotzen

hotzen commented Sep 26, 2026

Copy link
Copy Markdown

this needs to be merged asap please!

@minutechreview

Copy link
Copy Markdown
Author

@hotzen #47468 fixes this. It builds the global config and AGENTS.md paths from the real global config folder instead of the OPENCODE_CONFIG_DIR override, so the global layer (including MCP servers) loads again. It's mergeable against dev, and I'm happy to rebase or adjust anything a maintainer wants.

@hotzen

hotzen commented Sep 29, 2026

Copy link
Copy Markdown

so how do we get the maintainer's attention

This branch has not been deployed

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

OPENCODE_CONFIG_DIR overrides global AGENTS.md path instead of adding to it

2 participants