rtk icon indicating copy to clipboard operation
rtk copied to clipboard

[OpenCode] RTK rewrite breaks existing Bash permission allowlists by adding `rtk` before permission evaluation

Open gonaik opened this issue 2 months ago โ€ข 5 comments

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

  1. Configure an OpenCode agent with a default-deny Bash policy:
permission:
  bash:
    "*": "deny"
    "npx ts-node*task-cli*": "allow"
  1. Enable the RTK OpenCode integration.

  2. Have the agent execute:

npx ts-node --compiler-options '{"module":"commonjs"}' .opencode/skills/task-management/scripts/task-cli.ts status
  1. 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:

  1. Preserve the original command for OpenCode permission evaluation while executing the RTK-rewritten command afterward.
  2. Provide OpenCode-specific metadata or another mechanism indicating that rtk <original> is a transparent rewrite of <original>.
  3. If OpenCode's plugin API cannot support this safely, provide an RTK/OpenCode integration option that avoids rewriting commands whose permission identity would change.
  4. Document a recommended permission-safe integration strategy that does not require duplicating every allow rule with an rtk prefix.

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.

gonaik avatar Sep 22 '26 10:09 gonaik

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.rs
  • src/integrations/opencode/hooks.rs

Suggested Actions

  1. Investigate preserving original command identity for OpenCode's tool.execute.before permission check
  2. Cross-reference #1771 (Claude Code re-evaluates permissions against rewritten command) โ€” likely same root design issue
  3. Evaluate option to expose an opt-out for permission-sensitive command families per agent config
  4. 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.

rtk-wshm-sync-bot avatar Sep 22 '26 10:09 rtk-wshm-sync-bot

will try to take a stab at this. will update once i have a pr up

mmfallacy avatar Sep 26 '26 17:09 mmfallacy

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.

KuSh avatar Oct 03 '26 11:10 KuSh

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.

KuSh avatar Oct 11 '26 22:10 KuSh

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.

amnesiaof avatar Oct 12 '26 07:10 amnesiaof