anomalyco / anomalyco/opencode
Config: nested .opencode directory configs merged in wrong precedence order (farther directory overrides nearer)
@kitlangton is already working on this.
Since Aug 26, 2026.
- Dominant language
- TypeScript
- Stars
- 209k
- Forks
- 27.5k
- PR merge metrics
- PR metrics pending
Description
Description
ConfigPaths.directories() merges nested .opencode configs in an order that
lets farther directories override nearer ones — contradicting both the docs and
its sibling code path.
The docs state the intended precedence (docs/config.mdx, "Precedence order"):
later sources override earlier ones, "project configs can override global
defaults", and among multiple levels the natural reading is nearest-wins.
Consistent with that, ConfigPaths.files() explicitly reverses its walk result
(config/paths.ts:20) so the nearest opencode.json wins when merged in list
order (config.ts:407-409).
But directories() (paths.ts:23-41) has no such reversal. It returns project
.opencode dirs nearest-first plus ~/.opencode last, and the merge loop
(config.ts:424-433) merges them after the files() batch with later-wins, so:
<root>/.opencode/opencode.jsonsilently overrides
<root>/packages/app/.opencode/opencode.jsonwhen running from
packages/app— the opposite of whatfiles()does for the same nesting.~/.opencode/opencode.jsonis merged after every project.opencodedir,
overriding all of them.
Reproduced on current dev:
repo/.opencode/opencode.json { "model": "ROOT/claude-sonnet-4-5" }
repo/packages/app/.opencode/opencode.json { "model": "NESTED/gpt-4o" }
cd repo/packages/app && opencode debug config resolves to
"model": "ROOT/claude-sonnet-4-5". Per the documented precedence the nested
value should win.
The same ordering also feeds command/agent/plugin discovery
(config.ts:459-465) and tui-migrate.ts, so those inherit the inverted
precedence too.
If the documented order is the intent, the fix is likely one .toReversed() on
the project portion of directories() (plus deciding where ~/.opencode
belongs relative to project dirs). Happy to send a PR with nested-case tests if
the expected precedence is confirmed.
Plugins
No response
OpenCode version
dev + manually reproduced (opencode debug config)
Steps to reproduce
mkdir -p repo/.opencode repo/packages/app/.opencodeecho '{ "$schema": "https://opencode.ai/config.json", "model": "ROOT/claude-sonnet-4-5" }' > repo/.opencode/opencode.jsonecho '{ "$schema": "https://opencode.ai/config.json", "model": "NESTED/gpt-4o" }' > repo/packages/app/.opencode/opencode.json && git init repocd repo/packages/app && opencode debug config- Output shows the ROOT model; per documented precedence it should show the NESTED one
Screenshot and/or share link
No response
Operating System
Windows 11 (platform-independent)
Terminal
Windows Terminal
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Assessment
This issue has not been assessed yet.