Skip to content

Fix XDG base directory support for config and log paths#350

Merged
Tarquinen merged 2 commits intoOpencode-DCP:devfrom
NamedIdentity:fix/xdg-base-directory-paths
Feb 5, 2026
Merged

Fix XDG base directory support for config and log paths#350
Tarquinen merged 2 commits intoOpencode-DCP:devfrom
NamedIdentity:fix/xdg-base-directory-paths

Conversation

@NamedIdentity
Copy link
Contributor

@NamedIdentity NamedIdentity commented Feb 4, 2026

Closes #349

Summary
Config loader and logger hardcode homedir()/.config/opencode instead of respecting XDG_CONFIG_HOME and XDG_DATA_HOME environment variables. This causes DCP to fail to find its config file and fail to write debug logs for any user running with custom XDG base directories.

What Changed
lib/config.ts

Before:
const GLOBAL_CONFIG_DIR = join(homedir(), ".config", "opencode")

After:
const GLOBAL_CONFIG_DIR = process.env.XDG_CONFIG_HOME
? join(process.env.XDG_CONFIG_HOME, "opencode")
: join(homedir(), ".config", "opencode")
lib/logger.ts

Before:
const opencodeConfigDir = join(homedir(), ".config", "opencode")
this.logDir = join(opencodeConfigDir, "logs", "dcp")

After:
const dataHome =
process.env.XDG_DATA_HOME || join(homedir(), ".local", "share")
this.logDir = join(dataHome, "opencode", "logs", "dcp")

Note: The logger also moves from the config directory (XDG_CONFIG_HOME) to the data directory (XDG_DATA_HOME), which is where logs belong per the XDG spec. Log files are runtime data, not configuration.

Behavior

  • When XDG_CONFIG_HOME is set: config loads from $XDG_CONFIG_HOME/opencode/dcp.jsonc
  • When XDG_CONFIG_HOME is unset: unchanged behavior (~/.config/opencode/dcp.jsonc)
  • When XDG_DATA_HOME is set: logs write to $XDG_DATA_HOME/opencode/logs/dcp/
  • When XDG_DATA_HOME is unset: logs write to ~/.local/share/opencode/logs/dcp/

No breaking changes for users with default paths.

Testing

  • Build passes
  • Verified config loading from custom XDG_CONFIG_HOME path
  • Verified debug logs writing to custom XDG_DATA_HOME path
  • Verified default fallback paths unchanged when env vars unset

Config loader now checks XDG_CONFIG_HOME before falling back to
~/.config/opencode. Logger now uses XDG_DATA_HOME (defaulting to
~/.local/share) for log storage, which is where runtime data belongs
per the XDG Base Directory Specification.

No behavior change for users with default (unset) XDG paths.
@Tarquinen
Copy link
Collaborator

I think you missed one spot in lib/state/persistence.ts, can you add that as well to the PR please? Thank you for your help!

STORAGE_DIR in persistence.ts also hardcoded ~/.local/share instead of
checking XDG_DATA_HOME. Same pattern as the logger fix.
@NamedIdentity
Copy link
Contributor Author

NamedIdentity commented Feb 4, 2026

@Tarquinen

Agent found and fixed the persistence.ts. Thanks for the direction.

@Tarquinen
Copy link
Collaborator

Looks good, thank you! The dev branch is cooking a pretty huge update, I need a day or two more before it can be released so this will be in @latest probably friday.

@Tarquinen Tarquinen merged commit e7cdd3c into Opencode-DCP:dev Feb 5, 2026
1 check failed
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.

2 participants

Comments