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
- Create configs in
.opencode/ for parent and child.
- 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
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.jsonfiles behave and opposite of the documented "local overrides global" precedence model.Root cause:
ConfigPaths.directoriesusesFilesystem.up, which yields directories child-first.The merge loop in
loadInstanceStateappliesmergeDeep(result, next)where the later-processed entry wins.So the last parent always overrides the child.
Plain
opencode.jsonfiles (not in.opencode/) don't have this problem:Filesystem.findUpis called with{ rootFirst: true }, which reverses the list before merging.Plugins
MCP context7, no plugins
OpenCode version
1.3.7
Steps to reproduce
.opencode/for parent and child.For example:
Check without
.opencode/directories (correct behavior):Screenshot and/or share link
No response
Operating System
Ubuntu 24
Terminal
Konsole