fix: honor XDG_CONFIG_HOME, XDG_DATA_HOME, and OpenCode env overrides#73
Merged
Conversation
…ODE_CONFIG_DIR OpenCode resolves config paths via the xdg-basedir npm package, which has no Windows-specific branch. The resolution rule is identical on all platforms: use the XDG_*_HOME env var if set, otherwise fall back to homedir + a fixed suffix. Previous code hardcoded ~/.config/opencode and ~/.local/share/opencode, breaking for users who relocate XDG dirs (including on Windows). Changes: - Add src/commands/code/xdg-paths.ts with centralized path resolvers - Update auth-sync.ts to use XDG_DATA_HOME for auth.json location - Update opencode.ts to use XDG_CONFIG_HOME / OPENCODE_CONFIG_DIR / OPENCODE_CONFIG - Replace string concatenation with path.join() for cross-platform separators All 223 tests pass.
GitHub Actions runners set XDG_CONFIG_HOME and XDG_DATA_HOME, causing tests that assert hardcoded paths to fail. Clear these env vars before each test to ensure deterministic path resolution.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
The CLI hardcoded OpenCode config and auth paths, ignoring the XDG base directory spec and OpenCode's own env overrides:
~/.config/opencode— ignoredXDG_CONFIG_HOMEandOPENCODE_CONFIG_DIR~/.local/share/opencode/auth.json— ignoredXDG_DATA_HOMEOPENCODE_CONFIG(single-file override) was not checkedpath.join()OpenCode resolves these via the
xdg-basedirpackage, which has no Windows-specific branch — the same rules apply on all platforms. Hardcoding the paths breaks users who relocate XDG dirs (common on Windows too).Changes
New:
src/commands/code/xdg-paths.ts— centralized path resolvergetOpencodeConfigDir()— honorsOPENCODE_CONFIG_DIR, thenXDG_CONFIG_HOME, then~/.config/opencodegetOpencodeDataDir()— honorsXDG_DATA_HOME, then~/.local/share/opencoderesolveGlobalConfigPath()— honorsOPENCODE_CONFIGenv vargetOpencodeAuthPath()— usespath.join()for correct separators on WindowsUpdated:
src/commands/code/opencode.ts— uses new resolvers for config dir, agents dir, and global config fileUpdated:
src/commands/code/auth-sync.ts— uses new resolver for auth file, replaces string concat withpath.join()Verification
All 223 tests pass.
Checklist
XDG_CONFIG_HOME/homedir + /.configon all platformsopencode.json, not the data directoryOPENCODE_CONFIG(single-file override)OPENCODE_CONFIG_DIR(directory override for agents/commands/plugins)opencode.jsonandopencode.jsonc