[OpenCode] RTK rewrite breaks existing Bash permission allowlists by adding `rtk` before permission evaluation
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 status
to:
rtk npx ts-node --compiler-options '{"module":"commonjs"}' .opencode/skills/task-management/scripts/task-cli.ts status
before 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.
wshm ยท Automated triage by AI
๐ Automated Triage
| ๐ Category | bug |
| ๐ Priority | high |
| ๐ฏ Confidence | 87% |
Summary
OpenCode integration rewrites cmd to rtk cmd before permission evaluation, breaking existing Bash allowlist patterns that match the unprefixed command.
๐ Relevant files
src/integrations/opencode/plugin.rssrc/integrations/opencode/hooks.rs
Suggested Actions
- Investigate preserving original command identity for OpenCode's tool.execute.before permission check
- Cross-reference #1771 (Claude Code re-evaluates permissions against rewritten command) โ likely same root design issue
- Evaluate option to expose an opt-out for permission-sensitive command families per agent config
- Consider documenting a permission-safe integration pattern until a structural fix ships
Triaged automatically by wshm ยท This is an automated analysis, not a human review.
will try to take a stab at this. will update once i have a pr up
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.before hands it {tool, sessionID, callID} and no agent name.
Run on OpenCode 1.18.34, with root "bash": "allow" and agent.build.permission.bash = {"*": "deny", "git status": "allow"}, command git status. On develop, on #4349's head and on #4349 narrowed to "skip a rewrite that changes the verdict", OpenCode logs evaluated permission=bash pattern="rtk git status" โฆ action.pattern=* action.action=deny and refuses the call. The same policy at root level runs the typed git status once the narrowed version lands.
So this issue stays open for agent-scoped rules after #4349. Two directions, and the choice is open:
- the plugin finds the session's agent (for example through the client API) and passes
--agent - rtk skips the rewrite when it would change the verdict under the root rules or any agent block. This costs savings in the other agents' sessions.
Status with #4187:
- 2.x: the plugin passes
--agent, so agent-scoped rules are judged. That settles the choice in the comment above for 2.x. - 1.x: it sends no agent field, so that path stays root-only and the agent-scoped case there remains open.
- Rule forms: rtk reads the 2.x forms. Where it can't see what OpenCode applies, it answers
{}and the command runs as typed. That covers markdown agents whose frontmatter declares rules, and legacy keys the two generations read differently. - Follow-ups:
- #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. - #4520: the 1.x config-file gaps.
- #4521: judging against the rules OpenCode itself resolves (
Fixed in #4187, merged to develop as 311ebcbf.
rtk now 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.ts stays unrewritten because the rewrite would have moved it from allow to 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.