Skip to content

fix(hook): read OpenCode's global config from XDG_CONFIG_HOME and config.json - #4522

Open
drakeo338 wants to merge 2 commits into
rtk-ai:developfrom
drakeo338:fix/opencode-xdg-config-home
Open

drakeo338 wants to merge 2 commits into
rtk-ai:developfrom
drakeo338:fix/opencode-xdg-config-home

Conversation

@drakeo338

Copy link
Copy Markdown
Contributor

Summary

Fixes #4520.

  • The global OpenCode directory is $XDG_CONFIG_HOME/opencode when set and non-empty, else ~/.config/opencode.
  • There, rtk merges whichever of config.json, opencode.json and opencode.jsonc exist, in that order, as OpenCode 1.18.34's loadGlobal does (remeda mergeDeep). Before, only the first of opencode.json/.jsonc was read.
  • Covers the global-files part of OpenCode permission rules: rtk's config loader diverges from OpenCode's config resolution #4422; merging the project config over the global one is left as it was.

Test plan

  • cargo fmt --all && cargo clippy --all-targets && cargo test: one failure, also on develop (git_log_malformed_digit_run_propagates_real_git_error expects git 2.51 wording; mine is 2.43)
  • Four unit tests; the XDG and config.json ones fail without the fix.
  • Manual testing: rtk <command> output inspected: rtk hook opencode ls -la went from {"command":"rtk ls -la"} to {} for each ask. Not run against a real OpenCode.

Prepared with an AI coding agent; the checks above ran on this branch.

…fig.json

rtk looked for OpenCode's global permission rules only in
~/.config/opencode, and only in the first of opencode.json and
opencode.jsonc. OpenCode 1.x reads its global directory from
$XDG_CONFIG_HOME/opencode when that is set, and merges config.json,
opencode.json and opencode.jsonc there in that order. An ask in any of
the files rtk skipped was silenced by the rewrite.

Use the same directory, and merge the three files the way OpenCode's
mergeDeep does, so a key repeated in a later file keeps its first position.
@rtk-wshm-sync-bot rtk-wshm-sync-bot Bot added bug Something isn't working hooks opencode labels Oct 12, 2026
@rtk-wshm-sync-bot

Copy link
Copy Markdown

wshm · Automated triage by AI

📊 Automated PR Analysis

🐛 Type bug-fix
🟢 Risk low

Summary

Fixes OpenCode hook global config loading to follow the XDG Base Directory spec (XDG_CONFIG_HOME when set and non-empty, else ~/.config) and to deep-merge config.json, opencode.json, and opencode.jsonc in order, matching OpenCode's own loadGlobal/mergeDeep behavior. Previously only the first of opencode.json/.jsonc was read and XDG_CONFIG_HOME was ignored.

Review Checklist

  • Tests present
  • Breaking change
  • Docs updated

Linked issues: #4520


Analyzed automatically by wshm · This is an automated analysis, not a human review.

@drakeo338

Copy link
Copy Markdown
Contributor Author

Merged develop (with #4187) into the branch; the only conflict was hooks/opencode/README.md, where the rules sentence now names the XDG/config.json global files and the agent-file lookup uses the same global directory.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working hooks opencode

Projects

None yet

Development

Successfully merging this pull request may close these issues.

OpenCode 1.x: rtk misses global rules under $XDG_CONFIG_HOME/opencode and in config.json

1 participant