Skip to content

Fix Windows OpenCode auth path - #5

Open
kapitalismho wants to merge 1 commit into
bjesuiter:mainfrom
kapitalismho:main
Open

Fix Windows OpenCode auth path#5
kapitalismho wants to merge 1 commit into
bjesuiter:mainfrom
kapitalismho:main

Conversation

@kapitalismho

Copy link
Copy Markdown

Summary

Fixes native Windows OpenCode Desktop account switching. Previously, cdx switch could update auth successfully from cdx's perspective, but OpenCode Desktop could still read an older auth file and continue using the previous account.

This updates Windows OpenCode auth writing so the selected credentials are written to the path OpenCode Desktop actually reads, while still updating the previous cdx path for compatibility.

Problem

  • cdx switch reported success on native Windows.
  • OpenCode Desktop could still continue using the previous account.

Root Cause

  • cdx wrote OpenCode auth to:
    %LOCALAPPDATA%\opencode\auth.json
  • OpenCode Desktop reads auth from the XDG data path instead:
    %USERPROFILE%\.local\share\opencode\auth.json when XDG_DATA_HOME is unset.

Fix

  • Use the XDG data path as the primary Windows OpenCode auth path.
  • Also update the old %LOCALAPPDATA% path for compatibility.
  • Update only the openai entry in each auth file, preserving other providers.
  • Deduplicate write targets, including case-insensitive Windows paths.
  • Show the compatibility path in cdx doctor.

Verified

  • bun test
  • Manual switching between multiple accounts in OpenCode Windows Desktop environment

References

OpenCode stores auth under Global.Path.data/auth.json:

Global.Path.data is based on xdgData:

xdgData resolves to XDG_DATA_HOME || ~/.local/share, with no Windows-specific %LOCALAPPDATA% fallback:

OpenCode Desktop starts a native sidecar/server process and does not override XDG_DATA_HOME, so the same XDG fallback applies on native Windows:

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