Skip to content

v2 config: child repositories cannot combine global and shared workspace configuration #36539

Closed as not planned

Description

@dmmop

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
        └── ...
  1. Create workspace/.envrc:

    export OPENCODE_CONFIG_DIR=$(pwd)/.opencode
  2. Put configuration shared by all repositories in workspace/.opencode/, including an opencode.json with an enabled MCP server and workspace-specific skills.

  3. Start the OpenCode v2 background service from $HOME, where the global OpenCode configuration is available.

  4. Enter a child repository and verify that direnv sets the workspace variable:

    cd workspace/project
    echo $OPENCODE_CONFIG_DIR
    # /absolute/path/to/workspace/.opencode
  5. Open opencode2 inside workspace/project. The client connects to the background service that was already started from $HOME.

  6. Inside the resulting OpenCode session, inspect the variable:

    echo $OPENCODE_CONFIG_DIR
    # Empty
  7. Run opencode2 mcp list. The workspace MCP server is not listed, and the workspace skills are not available in the session.

  8. Restarting the background service from inside workspace/project reverses 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 the OPENCODE_CONFIG_DIR value loaded through workspace/.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, but workspace/.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

  1. github-actions commented on Jul 12, 2026

    @github-actions
    Contributor

    This issue might be a duplicate of existing issues. Please check:

    If 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.

  2. opencode-agent commented on Jul 12, 2026

    @opencode-agent
    Contributor

    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/.opencode is automatically merged for workspace/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_DIR with the long-running service separately, rather than making client environment forwarding part of this fix.

  3. opencode-agent commented on Jul 12, 2026

    @opencode-agent
    Contributor

    Correction: the implementation is now merged into the v2 branch via #36568. The earlier dev-targeted PR #36565 was closed without merging.

  4. dmmop commented on Jul 13, 2026

    @dmmop
    Author

    Heads up: the fix from #36568 appears to have been reverted by #36577.

    Note: app/opencode-agent is only the commit bot; the real authors are Dax Raad (#36568) and Little Frank (#36577).

    Net result: the current v2 HEAD (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.

  5. github-actions commented on Sep 12, 2026

    @github-actions
    Contributor

    To stay organized issues are automatically closed after 60 days of no activity. If the issue is still relevant please open a new one.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions