-
Notifications
You must be signed in to change notification settings - Fork 154
fix: respect XDG_DATA_HOME for auth sync paths #233
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -63,13 +63,18 @@ function getActiveAccount(): ClaudeAccount | null { | |||||||||||||||||
| } | ||||||||||||||||||
|
|
||||||||||||||||||
| function getAccountStateFile(): string { | ||||||||||||||||||
| return join( | ||||||||||||||||||
| homedir(), | ||||||||||||||||||
| ".local", | ||||||||||||||||||
| "share", | ||||||||||||||||||
| "opencode", | ||||||||||||||||||
| "claude-account-source.txt", | ||||||||||||||||||
| ) | ||||||||||||||||||
| return join(getOpencodeDataDir(), "claude-account-source.txt") | ||||||||||||||||||
| } | ||||||||||||||||||
|
|
||||||||||||||||||
| function getOpencodeDataDir(): string { | ||||||||||||||||||
| if (process.platform === "win32") { | ||||||||||||||||||
| return join(homedir(), ".local", "share", "opencode") | ||||||||||||||||||
| } | ||||||||||||||||||
| const xdgDataHome = process.env.XDG_DATA_HOME | ||||||||||||||||||
| if (xdgDataHome && xdgDataHome.trim().length > 0) { | ||||||||||||||||||
| return join(xdgDataHome, "opencode") | ||||||||||||||||||
| } | ||||||||||||||||||
|
Comment on lines
+73
to
+76
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
Prompt To Fix With AIThis is a comment left during a code review.
Path: src/credentials.ts
Line: 73-76
Comment:
The variable `xdgDataHome` is trimmed only for the length check but the **original untrimmed value** is passed to `join()`. If `XDG_DATA_HOME` contains leading or trailing whitespace (e.g. set via a shell script with a trailing space), `join(xdgDataHome, "opencode")` produces a path with embedded spaces that the OS will likely reject or silently misdirect — bypassing the fallback to `~/.local/share/opencode`.
```suggestion
const xdgDataHome = process.env.XDG_DATA_HOME?.trim()
if (xdgDataHome) {
return join(xdgDataHome, "opencode")
}
```
How can I resolve this? If you propose a fix, please make it concise. |
||||||||||||||||||
| return join(homedir(), ".local", "share", "opencode") | ||||||||||||||||||
| } | ||||||||||||||||||
|
|
||||||||||||||||||
| export function loadPersistedAccountSource(): string | null { | ||||||||||||||||||
|
|
@@ -96,7 +101,7 @@ export function saveAccountSource(source: string): void { | |||||||||||||||||
| } | ||||||||||||||||||
|
|
||||||||||||||||||
| function getAuthJsonPaths(): string[] { | ||||||||||||||||||
| const xdgPath = join(homedir(), ".local", "share", "opencode", "auth.json") | ||||||||||||||||||
| const xdgPath = join(getOpencodeDataDir(), "auth.json") | ||||||||||||||||||
| if (process.platform === "win32") { | ||||||||||||||||||
| const appData = | ||||||||||||||||||
| process.env.LOCALAPPDATA ?? join(homedir(), "AppData", "Local") | ||||||||||||||||||
|
|
||||||||||||||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
On Windows,
getOpencodeDataDir()unconditionally returns~/.local/share/opencodewithout consultingXDG_DATA_HOME. This mirrors the pre-existing behaviour and keeps Windows handling consistent withgetAuthJsonPaths(), which adds the properLOCALAPPDATApath on top. However, if a Windows user setsXDG_DATA_HOME(e.g. running under WSL-inspired tooling), the variable is silently ignored forclaude-account-source.txtwhilegetAuthJsonPaths()still only checks it viagetOpencodeDataDir()— so the behaviour is at least symmetric. Worth confirming this is intentional if Windows XDG support is ever planned.Prompt To Fix With AI
Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!