Repository navigation
Open
Labels
Description
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.jsonandopencode.jsoncwhen 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_CONFIGis added on top of the global config. rtk reads it instead of the global config.OPENCODE_CONFIG_CONTENTand 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"}givesaskin OpenCode andallowin rtk forgit 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{}), whilels -lais 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:
- JSONC (a comment or trailing comma drops every rule of the file): opencode.jsonc with comments: every permission rule is silently dropped #4524, PR fix(hooks/opencode): parse permission configs as JSONC, comments no longer drop every rule #4528.
- Global
config.jsonand$XDG_CONFIG_HOME/opencode: OpenCode 1.x: rtk misses global rules under$XDG_CONFIG_HOME/opencodeand inconfig.json#4520. - Project
.opencode/directories: OpenCode hook misses .opencode project permissions and can lift deny or ask #4855, PR fix(opencode): discover project directory permission configs #4856.
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
rtk-wshm-sync-bot commentedon Oct 3, 2026
🔍 Automated Triage
bughighSummary
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.rsSuggested Actions
Triaged automatically by wshm · This is an automated analysis, not a human review.
KuSh commentedon Oct 5, 2026
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{}, whilels -lais still rewritten. OpenCode would have runrtk git statusunder its default. This costs savings, never a verdict. Modelling it needs the per-agent defaults as well, since agents can ship their own.TechWizard9999 commentedon Oct 30, 2026
Hi @KuSh , If this is not finished or backlog I can take this up
If any priority issues please assign me , Looking forward
Thankss!!
Tarek-9 commentedon Nov 11, 2026
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>viaexecFilewithout acwd, 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 projectopencode.jsonnever 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" } ] }opencode run --agent general "Run exactly: git push": the push runs (fatal: No configured push destination), the deny is lost.--standalone(server started in the project):Permission denied: shell.rtk git push *: denied, so OpenCode judges the rewritten command.rtk hook opencode --agent general "git push"run in the project directory answers{}.Passing the session's directory as
cwdtoexecFile, 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.