anomalyco / anomalyco/opencode

Config: nested .opencode directory configs merged in wrong precedence order (farther directory overrides nearer)

Open
#45,266 1 comment 0 reactions 1 assignee View on GitHub

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

  1. <root>/.opencode/opencode.json silently overrides
    <root>/packages/app/.opencode/opencode.json when running from
    packages/app — the opposite of what files() does for the same nesting.
  2. ~/.opencode/opencode.json is merged after every project .opencode dir,
    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
  1. mkdir -p repo/.opencode repo/packages/app/.opencode
  2. echo '{ "$schema": "https://opencode.ai/config.json", "model": "ROOT/claude-sonnet-4-5" }' > repo/.opencode/opencode.json
  3. echo '{ "$schema": "https://opencode.ai/config.json", "model": "NESTED/gpt-4o" }' > repo/packages/app/.opencode/opencode.json && git init repo
  4. cd repo/packages/app && opencode debug config
  5. 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

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.