Repository navigation
Description
Summary
When using RTK's OpenCode integration, commands are transparently rewritten from:
npx ts-node --compiler-options '{"module":"commonjs"}' .opencode/skills/task-management/scripts/task-cli.ts statusto:
rtk npx ts-node --compiler-options '{"module":"commonjs"}' .opencode/skills/task-management/scripts/task-cli.ts statusbefore OpenCode evaluates Bash permissions.
This causes existing OpenCode permission rules for the original command to stop matching.
For example, an agent has:
permission:
bash:
"*": "deny"
"npx ts-node*task-cli*": "allow"Without RTK rewriting, the command is allowed.
With the RTK OpenCode plugin enabled, OpenCode's permission engine evaluates:
rtk npx ts-node --compiler-options '{"module":"commonjs"}' .opencode/skills/task-management/scripts/task-cli.ts status
which no longer matches:
npx ts-node*task-cli*
and therefore falls through to "*": "deny".
Environment
- RTK: 0.49.0
- OpenCode: 1.18.32
- OS: macOS arm64
- Shell: zsh
- RTK integration: OpenCode global integration /
tool.execute.before
Reproduction
- Configure an OpenCode agent with a default-deny Bash policy:
permission:
bash:
"*": "deny"
"npx ts-node*task-cli*": "allow"-
Enable the RTK OpenCode integration.
-
Have the agent execute:
npx ts-node --compiler-options '{"module":"commonjs"}' .opencode/skills/task-management/scripts/task-cli.ts status- OpenCode denies the command even though the original command matches the explicit allow rule.
Evidence
The OpenCode UI shows the original tool call:
npx ts-node --compiler-options '{"module":"commonjs"}' .opencode/skills/task-management/scripts/task-cli.ts status
but the OpenCode log shows the permission engine evaluating the RTK-rewritten form:
evaluated permission=bash
pattern="rtk npx ts-node --compiler-options '{\"module\":\"commonjs\"}' .opencode/skills/task-management/scripts/task-cli.ts status"
action.permission=bash
action.pattern=*
action.action=deny
The resolved agent configuration confirms that the original allow rule is active, so this is not caused by the agent permission configuration being ignored.
Expected behavior
Transparent RTK rewriting should ideally not change the security identity of the command for the host's permission system.
An existing permission such as:
npx ts-node*task-cli*
should continue to authorize the same command when RTK transparently optimizes it.
Users should not need to duplicate every OpenCode permission as:
git status *
rtk git status *
npx ts-node*task-cli*
rtk npx ts-node*task-cli*
python -m pytest *
rtk python -m pytest *
This becomes particularly problematic for OpenCode setups using per-agent default-deny allowlists.
Current workaround
Add a second RTK-prefixed permission for every command family:
"npx ts-node*task-cli*": "allow"
"rtk npx ts-node*task-cli*": "allow"This works, but requires maintaining duplicate security policies across every agent and command family.
Another workaround is excluding affected commands from RTK rewriting, but that removes RTK optimization specifically because of the permission-system interaction.
Possible solutions
I'm not sure which is most appropriate given OpenCode's plugin API, but possible approaches include:
- Preserve the original command for OpenCode permission evaluation while executing the RTK-rewritten command afterward.
- Provide OpenCode-specific metadata or another mechanism indicating that
rtk <original>is a transparent rewrite of<original>. - If OpenCode's plugin API cannot support this safely, provide an RTK/OpenCode integration option that avoids rewriting commands whose permission identity would change.
- Document a recommended permission-safe integration strategy that does not require duplicating every allow rule with an
rtkprefix.
Importantly, globally allowing:
rtk *
is not a desirable workaround for default-deny agent configurations, because it would substantially broaden the agent's allowed command surface.
Related
This appears conceptually related to #1771, where Claude Code re-evaluates permissions against the RTK-rewritten command.
The OpenCode integration is especially affected because the plugin currently mutates args.command in-place from tool.execute.before.
Activity
[-][OpenCode] RTK rewrite breaks existing Bash permission allowlists by adding before permission evaluation[/-][+][OpenCode] RTK rewrite breaks existing Bash permission allowlists by adding `rtk` before permission evaluation[/+]rtk-wshm-sync-bot commentedon Sep 22, 2026
🔍 Automated Triage
bughighSummary
OpenCode integration rewrites
cmdtortk cmdbefore permission evaluation, breaking existing Bash allowlist patterns that match the unprefixed command.📁 Relevant files
src/integrations/opencode/plugin.rssrc/integrations/opencode/hooks.rsSuggested Actions
Triaged automatically by wshm · This is an automated analysis, not a human review.
mmfallacy commentedon Sep 26, 2026
will try to take a stab at this. will update once i have a pr up
KuSh commentedon Oct 3, 2026
Status of the agent-scoped case after #4349. The rules in this report live in an agent block, and the plugin cannot see them:
tool.execute.beforehands it{tool, sessionID, callID}and no agent name.Run on OpenCode 1.18.34, with root
"bash": "allow"andagent.build.permission.bash = {"*": "deny", "git status": "allow"}, commandgit status. On develop, on #4349's head and on #4349 narrowed to "skip a rewrite that changes the verdict", OpenCode logsevaluated permission=bash pattern="rtk git status" … action.pattern=* action.action=denyand refuses the call. The same policy at root level runs the typedgit statusonce the narrowed version lands.So this issue stays open for agent-scoped rules after #4349. Two directions, and the choice is open:
--agentfix(hooks): skip the OpenCode rewrite when it would change the verdict
KuSh commentedon Oct 11, 2026
Status with #4187:
--agent, so agent-scoped rules are judged. That settles the choice in the comment above for 2.x.{}and the command runs as typed. That covers markdown agents whose frontmatter declares rules, and legacy keys the two generations read differently.ctx.agent.get) #4521: judging against the rules OpenCode itself resolves (ctx.agent.get). On 2.x that covers those cases, plus session rules and$XDG_CONFIG_HOME.$XDG_CONFIG_HOME/opencodeand inconfig.json#4520: the 1.x config-file gaps.amnesiaof commentedon Oct 12, 2026
Fixed in #4187, merged to
developas311ebcbf.rtknow reads the rules OpenCode itself applies, computes the verdict before and after the rewrite, and skips the rewrite when the two differ. Your example no longer slips through:npx ts-node … task-cli.tsstays unrewritten because the rewrite would have moved it fromallowto the*deny.The remainder is not closed here: on 2.x OpenCode resolves rules per agent at runtime through
ctx.agent.get, which rtk cannot see, so a rewrite can still change the verdict on that path. That is #4521.The 1.x fix is already merged into
develop(311ebcbf) and the 2.x remainder is tracked in #4521, so this looks safe to close. Not closing it myself — I no longer have triage rights on the repo.