Skip to content

feat: respect XDG_DATA_HOME and CLAUDE_CONFIG_DIR for path resolution#217

Open
troian wants to merge 1 commit into
griffinmartin:mainfrom
troian:feat/xdg-data-home-support
Open

feat: respect XDG_DATA_HOME and CLAUDE_CONFIG_DIR for path resolution#217
troian wants to merge 1 commit into
griffinmartin:mainfrom
troian:feat/xdg-data-home-support

Conversation

@troian
Copy link
Copy Markdown

@troian troian commented May 1, 2026

The plugin hardcoded ~/.local/share/opencode/ and ~/.claude/ for all file paths, ignoring XDG_DATA_HOME and CLAUDE_CONFIG_DIR. This prevented running multiple OpenCode instances in parallel with different Claude accounts, since all instances shared the same claude-account-source.txt. Changes:

  • credentials.ts: getAccountStateFile() and getAuthJsonPaths() use $XDG_DATA_HOME with fallback to ~/.local/share
  • keychain.ts: readCredentialsFile() and writeBackCredentials() use $CLAUDE_CONFIG_DIR with fallback to ~/.claude
  • logger.ts: getDefaultLogPath() uses $XDG_DATA_HOME with fallback to ~/.local/share
  • Tests added for all new paths; existing tests updated to isolate env vars that now affect path resolution
  • README updated with env var docs and parallel instance usage

When unset, behavior is unchanged (same defaults as before).

Summary

Related issue

Testing

Checklist

  • PR title follows Conventional Commits (feat:, fix:, docs:, chore:, etc.)
  • make all passes locally (runs lint, build, and test)
  • Tests added or updated where applicable
  • README or docs updated where applicable

The plugin hardcoded ~/.local/share/opencode/ and ~/.claude/ for all
file paths, ignoring XDG_DATA_HOME and CLAUDE_CONFIG_DIR. This prevented
running multiple OpenCode instances in parallel with different Claude
accounts, since all instances shared the same claude-account-source.txt.
Changes:
- credentials.ts: getAccountStateFile() and getAuthJsonPaths() use
  $XDG_DATA_HOME with fallback to ~/.local/share
- keychain.ts: readCredentialsFile() and writeBackCredentials() use
  $CLAUDE_CONFIG_DIR with fallback to ~/.claude
- logger.ts: getDefaultLogPath() uses $XDG_DATA_HOME with fallback
  to ~/.local/share
- Tests added for all new paths; existing tests updated to isolate
  env vars that now affect path resolution
- README updated with env var docs and parallel instance usage

When unset, behavior is unchanged (same defaults as before).

Signed-off-by: Artur Troian <troian@users.noreply.github.com>
@troian
Copy link
Copy Markdown
Author

troian commented May 4, 2026

hey @griffinmartin any chance you can take a look

@griffinmartin
Copy link
Copy Markdown
Owner

@troian Sorry I've been pretty busy so haven't been testing all the open PRs as much as I have in the past. I'll get to it this week.

@markthepixel
Copy link
Copy Markdown

I have a similar issue. Running three Claude Team accounts across different project dirs via CLAUDE_CONFIG_DIR + direnv, and the account selection bleeds across all of them because claude-account-source.txt is always written to the hardcoded path.

Ended up pre-writing it from a shell wrapper before each opencode launch as a workaround, but that breaks every update.

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.

3 participants