Skip to content

fix(opencode): honor the user's own opencode config - #387

Open
larsmoan wants to merge 4 commits into
databricks:mainfrom
larsmoan:fix/opencode-honor-user-config
Open

fix(opencode): honor the user's own opencode config#387
larsmoan wants to merge 4 commits into
databricks:mainfrom
larsmoan:fix/opencode-honor-user-config

Conversation

@larsmoan

@larsmoan larsmoan commented Aug 25, 2026

Copy link
Copy Markdown

Fixes #391.

Before this, ucode opencode ignored your ~/.config/opencode/. Now it honors it.

The one-line cause

ucode set XDG_CONFIG_HOME to its own folder. That is the variable OpenCode uses to find your config folder — change it and your config is gone. The fix names ucode's file with OPENCODE_CONFIG instead, which OpenCode adds as one more layer rather than replacing the folder.

How OpenCode combines the layers

OpenCode reads several config sources in priority order and merges them. OPENCODE_CONFIG sits just above your global config, so:

  • Scalars — higher layer wins. ucode's model wins.
  • Objects — merged key by key. Your mcp servers and ucode's server all survive.
  • Arrays — replaced, not merged. So ucode writes no top-level array, which is why a user's disabled_providers stays whole.

Result: ucode keeps model and provider; the user keeps permissions, MCP servers, disabled_providers, skills, AGENTS.md, everything else. ucode still writes only its own file, and the path is unchanged, so ucode mcp add servers survive.

Verification

opencode debug config before the change shows only ucode's keys; after the change it shows the user's permission, disabled_providers and MCP servers merged with ucode's model, provider and MCP server. A launched ucode opencode run still reaches the gateway and returns a normal reply.

Tests

uv run --frozen pytest: 1937 passed, 41 skipped. ruff check .: clean. New regression test test_leaves_xdg_config_home_alone.

larsmoan and others added 2 commits August 25, 2026 14:31
ucode exported XDG_CONFIG_HOME to send opencode to its own directory. That
removed all of ~/.config/opencode from opencode's load path. Thus the user's
permission rules, MCP servers, disabled_providers, global skills, agents,
commands, plugins, tui.json and global AGENTS.md had no effect in a ucode
session.

Name ucode's file with OPENCODE_CONFIG in place of the redirect. OPENCODE_CONFIG
is a config layer above the user's global config, and opencode merges the layers.
Objects merge one key at a time and the later scalar wins. Thus ucode keeps
control of `model` and `provider`, and the user keeps everything else. ucode
still writes to its own file only.

The config file path does not change, so MCP servers that `ucode mcp add`
registered survive the upgrade.
@larsmoan
larsmoan marked this pull request as ready for review August 25, 2026 20:11
Copilot AI lite review requested due to automatic review settings August 25, 2026 20:11

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR updates the OpenCode agent integration so ucode opencode no longer hides the developer’s existing OpenCode config under ~/.config/opencode/. Instead of redirecting XDG_CONFIG_HOME, ucode now points OpenCode at ucode’s generated config via OPENCODE_CONFIG, allowing OpenCode to merge configs as intended while keeping ucode’s config written under ~/.ucode/.

Changes:

  • Stop exporting XDG_CONFIG_HOME for OpenCode; set OPENCODE_CONFIG to ucode’s generated config file instead.
  • Update e2e/unit tests to avoid reading the developer’s real ~/.config/opencode by setting XDG_CONFIG_HOME to a test-only empty location.
  • Document the OpenCode managed file path as a layering config in the README.

Reviewed changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
src/ucode/agents/opencode.py Switch runtime env construction from XDG_CONFIG_HOME redirection to OPENCODE_CONFIG layering.
tests/test_agent_opencode.py Adjust unit tests to assert OPENCODE_CONFIG is used and XDG_CONFIG_HOME is not overridden.
tests/test_e2e.py Update OpenCode e2e launches to keep tests hermetic now that XDG_CONFIG_HOME isn’t redirected by ucode.
tests/test_e2e_user_agent.py Update OpenCode user-agent e2e test env to use OPENCODE_CONFIG plus an empty XDG_CONFIG_HOME.
README.md Update managed-local-files table to reflect OpenCode’s config layering behavior and ucode-managed path.
Suppressed comments (1)

tests/test_e2e.py:872

  • Same hermeticity concern here: XDG_CONFIG_HOME is pointed at tmp_path/empty-xdg but the directory isn’t created, which can allow fallbacks to the developer’s real config depending on opencode’s lookup behavior.
        monkeypatch.setenv("XDG_CONFIG_HOME", str(tmp_path / "empty-xdg"))

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread tests/test_e2e.py
Comment thread tests/test_e2e_user_agent.py
Copilot AI review requested due to automatic review settings August 25, 2026 23:45

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 5 out of 5 changed files in this pull request and generated 1 comment.

Comment thread tests/test_agent_opencode.py Outdated
The single test asserted only that build_runtime_env adds no
XDG_CONFIG_HOME when the variable is absent. A reintroduced redirect
that overwrites a value the user already set would have passed. Split
the case in two so the pass-through is asserted with a sentinel.
Copilot AI review requested due to automatic review settings August 25, 2026 23:59

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 5 out of 5 changed files in this pull request and generated no new comments.

@larsmoan

Copy link
Copy Markdown
Author

@lilly-luo Do you have time to review this? Or are there adjustments I need to do in my PRs before you can take a look at them? 😊

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

ucode opencode ignores the user's own OpenCode config

2 participants