Skip to content

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

Description

@KuSh

On OpenCode 1.x, rtk hook opencode still judges a rewrite against OpenCode's permission rules rebuilt from config files. That's the 1.x path: 1.x sends no agent field and has no API that returns the resolved rules. #4521 covers 2.x, where the plugin can get the resolved rules from OpenCode instead.

rtk reads the global rules from ~/.config/opencode/opencode.json(c) only (global_opencode_dir and CONFIG_NAMES in src/hooks/permissions_opencode.rs, unchanged on develop). Measured on 1.18.34, OpenCode reads more:

  • $XDG_CONFIG_HOME/opencode when the variable is set. With {"permission":{"bash":{"ls *":"ask"}}} only in $XDG_CONFIG_HOME/opencode/opencode.json, OpenCode alone asked for ls -la, and without the variable it ran the command. rtk doesn't see that rule, so it judges ls -la and rtk ls -la the same and rewrites, and the rewritten command no longer matches the ask.
  • config.json as well as opencode.json/opencode.jsonc. OpenCode's log shows loading path=…/opencode/config.json first. rtk reads only the latter two names.

Found while reviewing #4187. Low priority: it needs XDG_CONFIG_HOME set, or rules kept in config.json, on a 1.x install.

Rows a fix has to pass on 1.x:

  • with XDG_CONFIG_HOME set, an ask in $XDG_CONFIG_HOME/opencode/opencode.json still prompts;
  • an ask in config.json still prompts;
  • with XDG_CONFIG_HOME unset, ~/.config/opencode keeps working.

Activity

  1. rtk-wshm-sync-bot commented on Oct 11, 2026

    @rtk-wshm-sync-bot

    wshm · Automated triage by AI

    🔍 Automated Triage

    🐛 Category bug
    🟠 Priority high
    🎯 Confidence 90%

    Summary

    rtk only reads OpenCode global config/agent files from ~/.config/opencode, ignoring $XDG_CONFIG_HOME/opencode, causing missed permission rules and incorrect rewrites

    This looks like a simple fix that could be auto-resolved. Repo maintainers can use /wshm fix to attempt it.

    📁 Relevant files
    • src/hooks/permissions_opencode.rs

    Suggested Actions

    1. Update global_opencode_dir in src/hooks/permissions_opencode.rs to check $XDG_CONFIG_HOME first, falling back to ~/.c…
    2. Apply the same fix to the global agent markdown file lookup path
    3. Add tests for all three rows: XDG ask-rule, XDG agent-file permissions, and unset-XDG fallback
    4. Cross-check against OpenCode permission rules: rtk's config loader diverges from OpenCode's config resolution #4422 (OpenCode config loader divergence) and OpenCode: rtk hook check --agent opencode judges differently from the plugin #4518 for overlapping root cause

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

  2. changed the title [-]OpenCode: rtk reads the global config and agent files from `~/.config/opencode` only, not `$XDG_CONFIG_HOME/opencode`[/-] [+]OpenCode 1.x: rtk misses global rules under `$XDG_CONFIG_HOME/opencode` and in `config.json`[/+] on Oct 11, 2026
  3. feliperm17 commented on Oct 29, 2026

    @feliperm17

    Hi @KuSh! While diagnosing #4638 in src/hooks/permissions_opencode.rs, I also reproduced the $XDG_CONFIG_HOME/opencode gap locally (rules placed solely under $XDG_CONFIG_HOME/opencode are currently skipped because global_opencode_dir falls back directly to $HOME/.config/opencode).

    I'd love to take this one on as well — updating global_opencode_dir to respect XDG_CONFIG_HOME (when non-empty) before $HOME/.config/opencode, adding config.json support alongside opencode.json/opencode.jsonc, and covering the precedence order with unit tests in permissions_opencode::tests.

    I can base it on top of #4458 (or coordinate it cleanly with the #4638 1.x follow-up) so there are no merge conflicts. Could you assign this to me?

  4. feliperm17 commented on Nov 1, 2026

    @feliperm17

    Hi @KuSh! I've opened #4932 targeting develop to resolve this:

    • global_opencode_dir() now uses $XDG_CONFIG_HOME/opencode when XDG_CONFIG_HOME is non-empty (and ~/.config/opencode when unset/empty), which also covers global markdown agent checks under agents/ and agent/.
    • Global config loading now merges config.json -> opencode.json -> opencode.jsonc in order (keeping project discovery restricted to opencode.json and opencode.jsonc).
  5. KuSh commented on Nov 8, 2026

    @KuSh
    CollaboratorAuthor

    There are 2 open pull requests for this issue: #4522, #4932 (oldest first).

    If you were about to start on it, reviewing or testing one of these helps more than another pull request: a note on which approach fits, or a test result on your setup, is welcome on the pull request itself.

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

Metadata

Metadata

Assignees

Labels

area:configbugopencodepriority:low

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions