Repository navigation
Description
On OpenCode 2.x, rtk hook opencode judges a rewrite against OpenCode's permission rules, which it rebuilds from config files. Every gap in that rebuild is a place where the rewritten command can lose a prompt or a deny that OpenCode applies to the typed one (#4195). After #4187, rtk reads the 2.x rule forms. Where it still can't see the rules, it answers {}, and the command runs as typed:
- markdown agents (
.opencode/agents/<id>.md,.opencode/agent/<id>.md) whose frontmatter declarespermission:/permissions:, which rtk doesn't parse; - legacy keys the two generations read differently (measured: 1.18.34 applies
bashandb*and ignoresshellandsh*; 2.0.26 appliesbash(renamed toshell),shellandsh*and ignoresb*).
Two sources it doesn't see at all:
- session rules:
ctx.session.update({ sessionID, permissions }), applied after the agent's rules, held in no config file; - global config under
$XDG_CONFIG_HOME/opencode: 2.0.26 reads it, and rtk only reads~/.config/opencode(OpenCode 1.x: rtk misses global rules under$XDG_CONFIG_HOME/opencodeand inconfig.json#4520).
OpenCode already resolves them
ctx.agent.get({ agentID }) is documented under "API → Agent" in https://opencode.ai/v2/docs/build/plugins. It returns AgentGetOutput = { location, data: AgentInfo } with a required permissions: PermissionRuleset, where PermissionRule = { action: string; resource: string; effect: "allow" | "deny" | "ask" } (AgentGetOutput, AgentInfo).
On 2.0.22 and 2.0.26 the list comes back in OpenCode's evaluation order:
- OpenCode's defaults;
- global root rules;
- the project's legacy
permissionmap, withbashalready normalised toshell; - the project's
permissionslist, with actions as written (sh*included); - agent rules from every file, markdown frontmatter included.
SessionInfo.permissions is optional (null in a plain opencode run). When set, it is evaluated after the agent's rules.
Proposal
The 2.x plugin forwards OpenCode's own data on stdin to rtk hook opencode, the way the native hosts send their hook payload to rtk hook <host>:
- the
execute.beforeevent (tool,sessionID,agent,input); ctx.agent.get({ agentID: event.agent }).data.permissions;- the session's
permissionswhen present.
rtk turns that into its ordered rule list and judges the typed and rewritten command against it. It matches action as a wildcard against shell, and no longer reads config files for 2.x. The {} fallbacks above then go away on 2.x. 1.x has no agent field and no such API, so it keeps the argv form and reads config files the 1.x way.
Known limit either way: saved approvals ("Allow always") are project-scoped allow rules outside both lists. Missing them can only make rtk stricter: a pre-approved command can prompt once rewritten. They can never silence an ask or lift a deny.
Rows a fix has to pass on 2.x
Each row must match OpenCode alone:
- every case above;
- a global agent ask against a project allow;
- an agent with no rules is still rewritten;
- a deny in any layer is still enforced.
Activity
rtk-wshm-sync-bot commentedon Oct 11, 2026
🔍 Automated Triage
bughighSummary
On OpenCode 2.x, rtk's config-file-based permission rebuild misses session rules, markdown agent frontmatter, XDG global config, and legacy key semantics, causing
{}fallback that lets rewrites bypass OpenCode's actual permission rules; proposes usingctx.agent.get/session data via stdin instead.📁 Relevant files
src/hook/opencode.rssrc/permissions/opencode.rsSuggested Actions
$XDG_CONFIG_HOME/opencodeand inconfig.json#4520 (XDG config) and OpenCode permission rules: rtk's config loader diverges from OpenCode's config resolution #4422 (config loader divergence) since fix overlapsrtkbefore permission evaluation #4195 whether ctx.agent.get is stable across OpenCode 2.0.22/2.0.26 before committing to stdin-forwarding d…Triaged automatically by wshm · This is an automated analysis, not a human review.
BramDriesen commentedon Oct 19, 2026
+1 for this! Also upgraded to Opencode V2 today and noticed that the RTK plugin no longer works. The "investigate" option of opencode itself also lead me to the same conclusion as this issue.
djbclark commentedon Oct 25, 2026
Data point for the
ctx.agent.getdirection: on OpenCode 2.x,ctx.permission.list()is not a source of effective rules. It returns pending permission requests ({ id, permission, patterns }, noeffect), normally an empty list. A plugin that reads an empty list as "no deny/ask rules" rewrites past rules that are configured. We hit this in a local rewrite shim and now decide from config files only, which still missesOPENCODE_CONFIG*, managed config and agent-level rules. Soctx.agent.get({ agentID }).permissionslooks like the right source. Anyone adding a host-side check should not usepermission.list().