Repository navigation
Description
Summary
In OpenCode v2, a running background service does not load the shared workspace configuration referenced by OPENCODE_CONFIG_DIR when OpenCode is opened inside a child git repository. The shell has the correct environment variable, but the resulting session only has the configuration associated with the context where the background service was started.
Environment
- opencode version: v0.0.0-next-15361
- OS: Linux 7.0.0-27-generic (Ubuntu, x86_64)
- Terminal: TERM_PROGRAM=ghostty, TERM=xterm-ghostty, COLORTERM=truecolor
- Shell: /usr/bin/zsh
- Install/channel: next (preview)
Reproduction
$HOME/
├── .envrc # global environment
├── .config/
│ └── opencode/ # global OpenCode config
└── workspace/
├── .envrc # exports OPENCODE_CONFIG_DIR
├── .opencode/
│ ├── opencode.json # shared workspace MCP/config
│ ├── skills/
│ └── agents/
├── project/ # git repo; OpenCode is opened here
│ └── ...
├── project2/ # git repo; should inherit both configs
│ └── ...
└── project3/ # git repo; should inherit both configs
└── ...
-
Create
workspace/.envrc:export OPENCODE_CONFIG_DIR=$(pwd)/.opencode
-
Put configuration shared by all repositories in
workspace/.opencode/, including anopencode.jsonwith an enabled MCP server and workspace-specific skills. -
Start the OpenCode v2 background service from
$HOME, where the global OpenCode configuration is available. -
Enter a child repository and verify that
direnvsets the workspace variable:cd workspace/project echo $OPENCODE_CONFIG_DIR # /absolute/path/to/workspace/.opencode
-
Open
opencode2insideworkspace/project. The client connects to the background service that was already started from$HOME. -
Inside the resulting OpenCode session, inspect the variable:
echo $OPENCODE_CONFIG_DIR # Empty
-
Run
opencode2 mcp list. The workspace MCP server is not listed, and the workspace skills are not available in the session. -
Restarting the background service from inside
workspace/projectreverses the problem: the workspace MCP server and skills become available, but the global configuration is lost.
Expected Behavior
Opening OpenCode v2 inside workspace/project, workspace/project2, or workspace/project3 should combine:
- The global OpenCode configuration.
- The shared configuration from
workspace/.opencode/, referenced by theOPENCODE_CONFIG_DIRvalue loaded throughworkspace/.envrc. - Any project-specific configuration, if present.
Each child git repository should inherit the common configuration from its parent workspace without losing the global configuration.
Actual Behavior
The loaded configuration depends on the directory context from which the background service was started, rather than the directory where the OpenCode client is opened:
- Service started from
$HOME: global configuration is available, butworkspace/.opencode/is not loaded in child projects. - Service restarted from the workspace: workspace configuration is available, but global configuration is lost.
The shell used to open OpenCode inside the child repository has the expected OPENCODE_CONFIG_DIR, while a shell command executed inside the resulting OpenCode session shows it as empty. Consequently, the workspace MCP server is absent from opencode2 mcp list and workspace skills are unavailable.
Additional Context
Restarting the service from the workspace is not a viable workaround because it trades the global configuration for the workspace configuration. OpenCode v2 should merge the global and shared workspace configuration according to the active client location instead of requiring the service to be restarted from one configuration scope or the other.
Activity
github-actions commentedon Jul 12, 2026
This issue might be a duplicate of existing issues. Please check:
OPENCODE_CONFIG_DIRreplaces global config in v2 services — covers the same root cause where v2/core treatsOPENCODE_CONFIG_DIRas a replacement for the global config directory rather than an additive layer$HOME, not subfolders — related regression where global config is not loaded from subdirectories in v2If your issue is distinct (e.g. specifically about the background service inheriting the environment from its start directory rather than the client's directory), feel free to clarify the difference.
opencode-agent commentedon Jul 12, 2026
We reproduced the background-service behavior. We’re addressing the underlying multi-repo workspace use case in #36565 by making config discovery continue through all ancestor directories across Git boundaries. With that change,
workspace/.opencodeis automatically merged forworkspace/project,project2, etc.; configs closer to the active directory retain precedence, and global config remains the base layer.We’re still considering the right semantics for
OPENCODE_CONFIG_DIRwith the long-running service separately, rather than making client environment forwarding part of this fix.opencode-agent commentedon Jul 12, 2026
Correction: the implementation is now merged into the
v2branch via #36568. The earlierdev-targeted PR #36565 was closed without merging.dmmop commentedon Jul 13, 2026
Heads up: the fix from #36568 appears to have been reverted by #36577.
fix(config): load configs across git boundaries(merge6e55ddd, 2026-07-12 22:07, authored by @thdxr ) removed thestop: worktreeparameter fromConfigPaths.files/ConfigPaths.directories, so config discovery traverses across Git boundaries.fix(core): load config across git boundaries(mergef112a73, 2026-07-13 00:05, authored by authored by Little Frank[email protected]) re-addedstop: worktreein bothfiles()anddirectories().Note:
app/opencode-agentis only the commit bot; the real authors are Dax Raad (#36568) and Little Frank (#36577).Net result: the current
v2HEAD (828a4b3) still has the old code that stops at the worktree/git boundary, so the cross-repo config merge from #36568 is effectively undone. Builds after this (e.g.next-15402) won't include the fix.github-actions commentedon Sep 12, 2026
To stay organized issues are automatically closed after 60 days of no activity. If the issue is still relevant please open a new one.