Skip to content

.opencode/ config precedence is inverted in nested directories #21307

@zckman

Description

@zckman

Description

When .opencode/opencode.json (or .jsonc) exists in multiple nested directories, the parent directory wins instead of the child.
This is the opposite of how plain opencode.json files behave and opposite of the documented "local overrides global" precedence model.

Root cause:
ConfigPaths.directories uses Filesystem.up, which yields directories child-first.
The merge loop in loadInstanceState applies mergeDeep(result, next) where the later-processed entry wins.
So the last parent always overrides the child.

Plain opencode.json files (not in .opencode/) don't have this problem:
Filesystem.findUp is called with { rootFirst: true }, which reverses the list before merging.

Plugins

MCP context7, no plugins

OpenCode version

1.3.7

Steps to reproduce

  1. Create configs in .opencode/ for parent and child.
  2. Verify the resulting config values

For example:

mkdir -p /tmp/oc-bug/.opencode /tmp/oc-bug/child/.opencode

echo '{ "$schema": "https://opencode.ai/config.json", "username": "parent-wins" }' \
  > /tmp/oc-bug/.opencode/opencode.json

echo '{ "$schema": "https://opencode.ai/config.json", "username": "child-should-win" }' \
  > /tmp/oc-bug/child/.opencode/opencode.json

cd /tmp/oc-bug/child && opencode debug config | grep username

# Expected: "username": "child-should-win"
# Actual:   "username": "parent-wins"

Check without .opencode/ directories (correct behavior):

mkdir -p /tmp/oc-bug2/child

echo '{ "$schema": "https://opencode.ai/config.json", "username": "parent" }' \
  > /tmp/oc-bug2/opencode.json

echo '{ "$schema": "https://opencode.ai/config.json", "username": "child-wins" }' \
  > /tmp/oc-bug2/child/opencode.json

cd /tmp/oc-bug2/child && opencode debug config | grep username
# Correct output: "username": "child-wins"

Screenshot and/or share link

No response

Operating System

Ubuntu 24

Terminal

Konsole

Metadata

Metadata

Assignees

Labels

bugSomething isn't workingcoreAnything pertaining to core functionality of the application (opencode server stuff)

Type

No type
No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions