Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 13 additions & 8 deletions src/credentials.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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")
}
Comment on lines +70 to +72

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Windows branch ignores XDG_DATA_HOME

On Windows, getOpencodeDataDir() unconditionally returns ~/.local/share/opencode without consulting XDG_DATA_HOME. This mirrors the pre-existing behaviour and keeps Windows handling consistent with getAuthJsonPaths(), which adds the proper LOCALAPPDATA path on top. However, if a Windows user sets XDG_DATA_HOME (e.g. running under WSL-inspired tooling), the variable is silently ignored for claude-account-source.txt while getAuthJsonPaths() still only checks it via getOpencodeDataDir() — so the behaviour is at least symmetric. Worth confirming this is intentional if Windows XDG support is ever planned.

Prompt To Fix With AI
This is a comment left during a code review.
Path: src/credentials.ts
Line: 70-72

Comment:
**Windows branch ignores XDG_DATA_HOME**

On Windows, `getOpencodeDataDir()` unconditionally returns `~/.local/share/opencode` without consulting `XDG_DATA_HOME`. This mirrors the pre-existing behaviour and keeps Windows handling consistent with `getAuthJsonPaths()`, which adds the proper `LOCALAPPDATA` path on top. However, if a Windows user sets `XDG_DATA_HOME` (e.g. running under WSL-inspired tooling), the variable is silently ignored for `claude-account-source.txt` while `getAuthJsonPaths()` still only checks it via `getOpencodeDataDir()` — so the behaviour is at least symmetric. Worth confirming this is intentional if Windows XDG support is ever planned.

How can I resolve this? If you propose a fix, please make it concise.

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!

Fix in Cursor Fix in Claude Code Fix in Codex

const xdgDataHome = process.env.XDG_DATA_HOME
if (xdgDataHome && xdgDataHome.trim().length > 0) {
return join(xdgDataHome, "opencode")
}
Comment on lines +73 to +76

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 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.

Suggested change
const xdgDataHome = process.env.XDG_DATA_HOME
if (xdgDataHome && xdgDataHome.trim().length > 0) {
return join(xdgDataHome, "opencode")
}
const xdgDataHome = process.env.XDG_DATA_HOME?.trim()
if (xdgDataHome) {
return join(xdgDataHome, "opencode")
}
Prompt To Fix With AI
This 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.

Fix in Cursor Fix in Claude Code Fix in Codex

return join(homedir(), ".local", "share", "opencode")
}

export function loadPersistedAccountSource(): string | null {
Expand All @@ -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")
Expand Down