You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
opencode v2: background service does not inherit workspace .envrc variables from the TUI #44914
OpenCode V2 resolves {env:...} values for local MCP servers from the background service environment, not from the environment that launched the TUI session.
When a workspace uses .envrc, variables available in the terminal that started the TUI are unavailable to a background service launched elsewhere or before direnv activated the workspace. This prevents local MCP servers from receiving their configured credentials.
Ensure the OpenCode background service was started outside that workspace, or before the workspace .envrc was activated.
Run opencode2 mcp list.
Expected Behavior
A TUI session started from a workspace with an active .envrc should make that workspace environment available when resolving {env:...} substitutions for its local MCP servers.
If this is incompatible with the shared-service model, OpenCode V2 should clearly document the limitation and report that the variable is unavailable in the background-service environment.
Actual Behavior
The local MCP receives an empty or missing required environment variable and exits during startup. OpenCode reports only:
example failed: MCP error -32000: Connection closed
The child process stderr identifies the missing variable when run directly, but that detail is not surfaced by OpenCode. Its log contains only:
No corresponding child stderr is recorded, even when the MCP is configured with LOG_LEVEL=debug.
Additional Context
The same MCP configuration connects successfully when the background service has the required environment variable, and fails after a service restart that does not inherit the workspace .envrc.
This makes MCP behavior depend on where and when the shared background service was started rather than on the environment of the workspace TUI session.
Partly done: MCP servers that exit unexpectedly now report the end of their stderr (#52418), so failures from missing variables are visible. {env:VAR} in config still resolves from the background service's environment, not the TUI's shell or .envrc; that's tracked in #51784 and #52891. Closing this in favor of those.
Activity
neriousy commentedon Oct 22, 2026
Partly done: MCP servers that exit unexpectedly now report the end of their stderr (#52418), so failures from missing variables are visible.
{env:VAR}in config still resolves from the background service's environment, not the TUI's shell or.envrc; that's tracked in #51784 and #52891. Closing this in favor of those.