Repository navigation
Description
- 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
- [FEATURE]: Plugin API:
permission.replyhook to adjust the decline message before the reply settles the request #62689:permission.replyhook, ask path - permission: rejection feedback is replaced by generic tool errors #50157: fix, rejection feedback dropped on the ask path
- permissions: external_directory check misses directory flags (git -C, make -C, npm --prefix, …) #59564, permissions: external_directory ask is skipped for shell #56288: shell commands evading permission checks
Activity
opencodejr commentedon Nov 10, 2026
Thanks for the detailed write-up! To restate it: you'd like a permission rule, especially a
deny, to carry amessagethat the model sees instead of (or as well as) the fixedPermission 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.evaluatehook 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.evaluatehook can do the deny itself and setmessage, 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 resolvedexternal_directoryresources, which look like/abs/dir/*, so path-based checks work. This plugin type-checks against@opencode/pluginondev, but I haven't run it in a live session:One catch: take the matching
denyout 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:
permission.replyhook to adjust the decline message before the reply settles the request #62689:permission.replyhook (ask path)Nautigsam commentedon Nov 10, 2026
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:
{"error":{"type":"permission.rejected","message":"Permission denied: external_directory"}}.event.effect = "deny"andevent.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:
assertpath, not justask.external_directoryauthorization goes throughassert, so this covers file-access checks.@opencode/pluginimport is needed. A plain{ id, setup(ctx) }export withctx.permission.hook("evaluate", ...)loads fine, including withnode:imports in the file.I have adopted this for my own worktree setup: a global plugin now owns the
external_directorydeny, 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
messageon a config deny rule, so the steering is declarative and does not depend on plugin code that can fail to load.Sadrak2017 commentedon Nov 10, 2026
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.
alxark commentedon Nov 14, 2026
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.