Skip to content

OpenCode permission rules: rtk's config loader diverges from OpenCode's config resolution #4422

Open

Description

@KuSh

src/hooks/permissions_opencode.rs (from #4349) rebuilds OpenCode's bash rules to decide whether a rewrite would change OpenCode's verdict. Where it reads different rules from OpenCode, the plugin falls back to develop's behaviour: it rewrites, and OpenCode judges the rtk … form. Checked against OpenCode 1.18.34's config loader, these divergences remain:

  • Both file names in a directory. OpenCode merges opencode.json and opencode.jsonc when both exist, in the global directory and in each project directory. rtk reads only the first one it can parse (read_first_config).
  • Project files. OpenCode merges every opencode.json(c) from the worktree root down to the cwd. rtk reads only the nearest one, and keeps walking up past the worktree root.
  • OPENCODE_CONFIG is added on top of the global config. rtk reads it instead of the global config.
  • OPENCODE_CONFIG_CONTENT and the managed config are not read.
  • Merge order. OpenCode deep-merges the files, so a key repeated in a later file keeps its first position, while rtk appends the later file's rules. With last-match-wins the two can disagree: global {"git *":"deny","git status":"ask"} plus project {"git *":"allow"} gives ask in OpenCode and allow in rtk for git status.
  • Built-in defaults. OpenCode puts {"permission":"*","pattern":"*","action":"allow"} ahead of the user's rules, so a command no rule matches runs. rtk treats "no rule" as its own verdict, which differs from Allow. With a config of allow rules and no catch-all, {"bash":{"git status":"allow","cargo test":"allow"}}, rtk skips the rewrite for exactly those two commands (rtk hook opencode "git status" gives {}), while ls -la is still rewritten. This costs savings, never a verdict. Modelling it needs the per-agent defaults as well, since agents can ship their own.

Tracked in their own issues:

On OpenCode 2.x, #4521 replaces the file reading with the rules OpenCode resolves itself (ctx.agent.get), which removes every row above there. On 1.x they stay.

A fix reads the same sources in the same order as OpenCode and merges objects key by key, with a test per source. Related: #4282 (an unparseable settings file drops its rules instead of failing closed).

Activity

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

    @rtk-wshm-sync-bot

    wshm · Automated triage by AI

    🔍 Automated Triage

    🐛 Category bug
    🟠 Priority high
    🎯 Confidence 88%

    Summary

    rtk's OpenCode config loader misses JSONC parsing, multi-file merge order, OPENCODE_CONFIG/CONTENT, and worktree-root limits, causing permission verdicts to diverge from OpenCode's actual resolution.

    📁 Relevant files
    • src/hooks/permissions_opencode.rs

    Suggested Actions

    1. Rewrite config loader to mirror OpenCode's merge order: global config.json/opencode.json(c), OPENCODE_CONFIG, project f…
    2. Switch JSON parsing to a JSONC-tolerant parser (comments/trailing commas) to match OpenCode 1.18.34 behavior
    3. Implement key-by-key deep merge instead of rule-list append to fix last-match-wins divergence
    4. Add a regression test per config source; cross-reference Permission rules: an unreadable or unparseable settings.json drops its deny rules instead of failing closed #4282 for fail-closed behavior on unparseable files

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

  2. KuSh commented on Oct 5, 2026

    @KuSh
    CollaboratorAuthor

    One more piece of OpenCode's resolution that rtk does not model: its built-in defaults. OpenCode 1.18.34 puts {"permission":"*","pattern":"*","action":"allow"} ahead of the user's rules, so a command no rule matches runs. rtk treats "no rule" as its own verdict, which differs from Allow. With #4349, a config of allow rules and no catch-all, {"bash":{"git status":"allow","cargo test":"allow"}}, makes rtk skip the rewrite for exactly those two commands: rtk hook opencode "git status" gives {}, while ls -la is still rewritten. OpenCode would have run rtk git status under its default. This costs savings, never a verdict. Modelling it needs the per-agent defaults as well, since agents can ship their own.

  3. TechWizard9999 commented on Oct 30, 2026

    @TechWizard9999
    Contributor

    Hi @KuSh , If this is not finished or backlog I can take this up
    If any priority issues please assign me , Looking forward
    Thankss!!

  4. Tarek-9 commented on Nov 11, 2026

    @Tarek-9

    One more divergence, this time on the plugin side.

    Setup: OpenCode 2.2.6 on Windows, rtk 1.1.0, sessions started with opencode run, which goes through OpenCode's background service.

    The plugin calls rtk hook opencode --agent <name> <command> via execFile without a cwd, so rtk reads the project config from its own working directory. With the background service that is the directory the service started in, not the session's project, and the project opencode.json never reaches the verdict check.

    Repro in a throwaway repo without a remote, project opencode.json:

    { "permissions": [
      { "action": "shell", "resource": "*", "effect": "allow" },
      { "action": "shell", "resource": "git push *", "effect": "deny" }
    ] }
    1. opencode run --agent general "Run exactly: git push": the push runs (fatal: No configured push destination), the deny is lost.
    2. Same with --standalone (server started in the project): Permission denied: shell.
    3. Deny changed to rtk git push *: denied, so OpenCode judges the rewritten command.
    4. rtk hook opencode --agent general "git push" run in the project directory answers {}.

    Passing the session's directory as cwd to execFile, or judging against the rules OpenCode resolves as proposed in #4521, would close it. Until then, deny rules with a leading * (*git *push*) also match the rewritten form.

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

Metadata

Metadata

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions