Skip to content

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

Open

Description

@gonaik

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.

Activity

  1. changed the title [-][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[/+] on Sep 22, 2026
  2. rtk-wshm-sync-bot commented on Sep 22, 2026

    @rtk-wshm-sync-bot

    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 Hook output should include permissionDecision: "allow" so rewritten commands don't trigger Claude Code permission prompts (Mac desktop app) #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.

  3. mmfallacy commented on Sep 26, 2026

    @mmfallacy

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

  4. KuSh commented on Oct 3, 2026

    @KuSh
    Collaborator

    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.
  5. KuSh commented on Oct 11, 2026

    @KuSh
    Collaborator

    Status with #4187:

  6. amnesiaof commented on Oct 12, 2026

    @amnesiaof
    Contributor

    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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions