Skip to content

[FEATURE]: permissions: let deny rules carry a message to the model #63075

Open

Description

@Nautigsam
  • Feature hasn't been suggested before

Problem

A configured deny rule tells the model nothing. When a tool call hits a deny, the model gets the fixed string Permission denied: <action> and no reason, no alternative.

The ask flow has a feedback path. The reject reply can carry a message, and since #50157 that message reaches the model. A hard deny never creates a pending request, so that path never opens. #62689 proposes a permission.reply hook, but it covers the ask path too. permission.evaluate fires before the request exists, and the deny path produces no request for anything to hook, so a plugin cannot attach feedback to a deny either.

The workaround today is a tool.execute.before plugin that rejects the call itself and writes its own error text. That duplicates the permission rule in plugin code, and it cannot express path-based checks like external_directory.

Request

Let a deny rule carry a message:

{ "action": "external_directory", "resource": "~/.herdr/worktrees/*", "effect": "deny",
  "message": "Sibling worktrees are out of scope. If the work belongs there, move the session there or ask the user to." }

The message replaces (or extends) Permission denied: <action> in the tool error the model sees. A plugin hook on deny decisions would work as well, but the field on the rule is what a config author actually writes.

Why

I run agents in isolated worktrees under a shared parent, with external_directory denied on the parent. When an agent needs a sibling worktree, the right move is to relocate the session there. The fixed deny text never says that. So the agent routes around the boundary through the shell instead: python heredocs and git -C with paths the permission scanner does not inspect. I have seen these calls in my own sessions. I added a reminder to my global AGENTS.md telling agents to relocate the session instead, and hoped the model would connect the dots. The deny text itself never says it, and the boundary stays routable.

Related

Activity

  1. opencodejr commented on Nov 10, 2026

    @opencodejr
    Contributor

    Thanks for the detailed write-up! To restate it: you'd like a permission rule, especially a deny, to carry a message that the model sees instead of (or as well as) the fixed Permission denied: <action>, so the agent learns why it was blocked and what to do instead. Maintainers will consider it.

    You're right about the cause. A deny that comes from config is decided before the permission.evaluate hook runs, so neither the rule nor a plugin can attach a reason to it today.

    You can get the same result now with a plugin, though. A permission.evaluate hook can do the deny itself and set message, and that message becomes the tool error the model sees (OpenCode's built-in managed-policy plugin works the same way). The hook receives the resolved external_directory resources, which look like /abs/dir/*, so path-based checks work. This plugin type-checks against @opencode/plugin on dev, but I haven't run it in a live session:

    // ~/.config/opencode/plugins/deny-messages.ts  (or <project>/.opencode/plugins/)
    import { Plugin } from "@opencode/plugin"
    import os from "node:os"
    
    // action pattern, resource pattern (* = wildcard), and the message the model sees
    const rules = [
      {
        action: "external_directory",
        resource: `${os.homedir()}/.herdr/worktrees/*`,
        message:
          "Sibling worktrees are out of scope. If the work belongs there, move the session there or ask the user to.",
      },
    ]
    
    const glob = (pattern: string) =>
      new RegExp("^" + pattern.replace(/[.+?^${}()|[\]\\]/g, "\\$&").replace(/\*/g, ".*") + "$")
    
    export default Plugin.define({
      id: "deny-messages",
      setup: async (ctx) => {
        const compiled = rules.map((rule) => ({ ...rule, action: glob(rule.action), resource: glob(rule.resource) }))
        await ctx.permission.hook("evaluate", (event) => {
          const rule = compiled.find(
            (rule) => rule.action.test(event.action) && event.resources.some((resource) => rule.resource.test(resource)),
          )
          if (!rule) return
          event.effect = "deny"
          event.message = rule.message
        })
      },
    })

    One catch: take the matching deny out of your config and let the plugin handle it. If the config rule still denies, it wins before the hook runs, and the model sees the generic text again. This doesn't stop the shell routes you mention (#59564, #56288). It only changes what the model is told when a check does fire.

    Related:

  2. Nautigsam commented on Nov 10, 2026

    @Nautigsam
    Author

    I ran the proposed plugin in an isolated fixture (local HTTP stand-in for the model provider, one deterministic tool call, no credentials) on v2.2.5. It works as described:

    • Control, config deny and no plugin: the model receives {"error":{"type":"permission.rejected","message":"Permission denied: external_directory"}}.
    • Config rule removed, plugin hook sets event.effect = "deny" and event.message: the model receives the same shape with the message substituted in. No pending request is created, no ask prompt appears, and the denied file's content never reaches the model.

    Two details from the run:

    • The hook fires on the assert path, not just ask. external_directory authorization goes through assert, so this covers file-access checks.
    • On v2.2.5 no @opencode/plugin import is needed. A plain { id, setup(ctx) } export with ctx.permission.hook("evaluate", ...) loads fine, including with node: imports in the file.

    I have adopted this for my own worktree setup: a global plugin now owns the external_directory deny, with the message from the example above. I accept the tradeoff: the deny lives in code, and a plugin that fails to load degrades the boundary to an ask prompt instead of a hard deny.

    That leaves the core request as-is: a message on a config deny rule, so the steering is declarative and does not depend on plugin code that can fail to load.

  3. Sadrak2017 commented on Nov 10, 2026

    @Sadrak2017

    Could the core version preserve permission.rejected and the existing result shape when a rule supplies custom text? Orchestrators can then distinguish a final denial from an approval request without parsing relocation advice. We're dealing with installed-client compatibility in our Sinaps Studio work at SinapsData, so I'd keep old message-less rules unchanged and add a regression case for both payloads. The explanation should improve steering while the denial decision stays the same.

  4. alxark commented on Nov 14, 2026

    @alxark

    Facing same problem. I have separate sandbox for most of work I'm doing with agents and shell tool is used only for critical tasks (when credentials needed as an example). Currently models still try to run commands with shell instead of separate sandbox MCP. I want to mark such calls with additional message ( like "this call doesn't require authorization and might be completed with sandbox MCP, use it" ) so model with receive deny with extra information and retry again.

    P.S. I have a recommendations in prompt for model, but still they try to use shell instead of sandbox.

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

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions