Skip to content

Permission denied messages should clearly name the matched deny rule #51046

Closed as duplicate

Description

@bluelovers

Summary

When a command is blocked by a deny rule in opencode.json, the agent only receives a generic Permission denied: shell message. This makes it hard for the agent (and the user) to understand why the command was rejected, leading the agent to retry the same failing command or draw incorrect conclusions.

Reproduction

  1. Add a deny rule to opencode.json, e.g.:
{
  "permissions": {
    "npm *": "deny"
  }
}
  1. Ask the agent to run a command such as npm install.
  2. Observe the response returned to the agent.

Actual behavior

The agent only sees:

Permission denied: shell

There is no information about which rule caused the denial.

Expected behavior

The denial message should clearly state that execution was blocked because the command matched a deny rule, and include the matched pattern. For example:

Permission denied: shell — command matched denied pattern "npm *"

(Or similar wording that surfaces the offending rule, e.g. denied by rule "npm *".)

Why this matters

Without an explicit reason, the agent cannot distinguish between:

  • "this command is forbidden by policy", vs.
  • "the shell tool is unavailable / misconfigured".

As a result, the agent may repeatedly attempt the blocked command, try alternate (still-blocked) invocations, or incorrectly conclude that an environment/tooling problem exists rather than a policy restriction. A precise message lets the agent adapt (e.g. pick a different, allowed approach) instead of looping on errors.

Suspected source

The relevant logic appears to live in packages/core/src/permission.ts, where the deny/allow decision is made and the error message is produced. The error returned there should be enriched with the matched rule pattern.

Suggestion

When a deny rule matches, include in the returned error:

  • the denied pattern (e.g. npm *),
  • optionally the tool/permission key that was checked,
  • a short hint that this is a policy denial rather than a tooling failure.

This keeps the message machine-readable (so agents can branch on it) while remaining human-readable.

Activity

  1. zonemeen commented on Sep 24, 2026

    @zonemeen

    I'd like to work on this issue.
    I'll update the permission denial message to include the matched deny rule, respecting the existing rule precedence and preserving any custom denial reason. I'll keep the change focused on error reporting and add regression tests for overlapping rules, multiple resources, and custom reasons.

  2. Tarquinen commented on Oct 20, 2026

    @Tarquinen
    Member

    We're tracking this in #44521, so I'm closing this as a duplicate. Please follow that issue for updates.

    — from 𝕺𝖕𝖊𝖓𝕮𝖔𝖉𝖊

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