Skip to content

fix: support XDG paths on Windows for opencode compatibility#37

Open
well0nez wants to merge 1 commit intoiHildy:mainfrom
well0nez:fix/windows-xdg-path-fallback
Open

fix: support XDG paths on Windows for opencode compatibility#37
well0nez wants to merge 1 commit intoiHildy:mainfrom
well0nez:fix/windows-xdg-path-fallback

Conversation

@well0nez
Copy link

@well0nez well0nez commented Feb 6, 2026

Summary

  • On Windows, opencode uses XDG-style paths (~/.config, ~/.local/share, ~/.local/state) instead of standard AppData paths
  • The sync plugin only checks AppData paths on Windows, causing it to miss config, sessions, secrets, and state data
  • This fix adds XDG path detection to resolveXdgPaths() on win32

Changes

src/sync/paths.ts - Modified resolveXdgPaths() to:

  1. Honor XDG_CONFIG_HOME/XDG_DATA_HOME/XDG_STATE_HOME env vars on Windows when explicitly set
  2. Auto-detect XDG layout by checking for ~/.config/opencode directory existence
  3. Fall back to standard Windows AppData paths only if neither condition applies

src/sync/paths.test.ts - Added two test cases:

  • Verifies XDG env vars are respected on win32
  • Verifies partial XDG env var sets trigger XDG path resolution

Behavior

  • No breaking change: Systems using standard AppData paths continue to work
  • New: Windows systems with XDG layout (like opencode's default) are now detected automatically
  • New: Users can explicitly set XDG env vars to override path detection

Testing

  • Tested locally on Windows 11 with opencode using XDG paths
  • Successfully synced config, sessions, secrets, prompt history, and model favorites after the fix
  • All existing tests continue to pass (3 pre-existing failures due to running tests on Windows with path separator differences)

opencode uses XDG-style paths (~/.config, ~/.local/share, ~/.local/state) on Windows instead of standard AppData paths. This causes the sync plugin to look in the wrong locations for sessions, secrets, state, and config data.

The fix adds XDG path detection to resolveXdgPaths() on win32:

- Honor XDG_CONFIG_HOME/XDG_DATA_HOME/XDG_STATE_HOME env vars when set

- Auto-detect XDG layout by checking for ~/.config/opencode existence

- Fall back to standard Windows AppData paths only if neither applies
@gemini-code-assist
Copy link
Contributor

Summary of Changes

Hello @well0nez, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request addresses an issue where the sync plugin on Windows failed to correctly locate configuration, session, and state data for applications like opencode that use XDG-style directory structures instead of the traditional AppData paths. By implementing robust XDG path detection, the system can now seamlessly find and utilize these paths, improving compatibility and data synchronization for Windows users employing XDG conventions.

Highlights

  • Windows XDG Path Support: The system now correctly identifies and uses XDG-style paths (~/.config, ~/.local/share, ~/.local/state) on Windows, ensuring compatibility with applications like opencode that utilize them.
  • Intelligent Path Resolution: The resolveXdgPaths() function has been enhanced to first check for explicit XDG environment variables, then detect an existing XDG layout (e.g., ~/.config/opencode), and only then fall back to standard Windows AppData paths.
  • Comprehensive Testing: New test cases have been added to validate that XDG environment variables are respected and that partial XDG environment variable sets correctly trigger XDG path resolution on Windows.
Changelog
  • src/sync/paths.test.ts
    • Added a new test case, "respects XDG env vars on windows", to verify that resolveXdgPaths correctly uses all specified XDG environment variables.
    • Added another test case, "prefers XDG on windows when only XDG_CONFIG_HOME is set", to ensure that the presence of even a single XDG environment variable (like XDG_CONFIG_HOME) correctly triggers the XDG path resolution logic, inferring other XDG paths.
  • src/sync/paths.ts
    • Imported the fs module to enable file system checks.
    • Modified the resolveXdgPaths function for win32 platform to:
    • Prioritize XDG_CONFIG_HOME, XDG_DATA_HOME, and XDG_STATE_HOME environment variables if explicitly set.
    • Automatically detect an XDG layout by checking for the existence of ~/.config/opencode.
    • Fall back to standard Windows AppData paths (APPDATA, LOCALAPPDATA) only if neither XDG environment variables are set nor an XDG layout is detected.
Activity
  • No specific activity (comments, reviews, or progress updates) has been recorded for this pull request yet.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request effectively addresses the need for XDG path support on Windows, particularly for opencode compatibility. The changes correctly prioritize explicit XDG environment variables, include a sensible auto-detection mechanism by checking for the ~/.config/opencode directory, and fall back to standard Windows AppData paths when XDG configurations are not present. The addition of fs import is necessary, and the new test cases in src/sync/paths.test.ts provide good coverage for the new logic, ensuring the intended behavior is validated. Overall, the solution is robust and well-tested for the described problem.

const xdgStateDir = env.XDG_STATE_HOME ?? path.join(homeDir, '.local', 'state');

const hasXdgEnv = Boolean(env.XDG_CONFIG_HOME ?? env.XDG_DATA_HOME ?? env.XDG_STATE_HOME);
const xdgConfigExists = fs.existsSync(path.join(xdgConfigDir, 'opencode'));
Copy link
Contributor

Choose a reason for hiding this comment

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

medium

The use of fs.existsSync is a synchronous file system operation. While it might be acceptable for path resolution during application startup, synchronous I/O operations can block the Node.js event loop, potentially leading to performance bottlenecks or unresponsiveness, especially in larger applications or under heavy load. Consider using an asynchronous alternative like fs.promises.access or fs.promises.stat if the resolveXdgPaths function could be refactored to be asynchronous. If not, ensure this synchronous call's impact is understood and deemed acceptable for the current use case.

@jules-relay
Copy link

jules-relay bot commented Feb 6, 2026

🤖 Review Jules Relay

I found 1 Gemini suggestion so far.

Type /relay batch to send all suggestions to Jules.

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.

1 participant