Skip to content

PermissionDenied error echoes the entire effective bash ruleset into the tool result #53446

Closed as not planned

Description

@xavierfonsecaphd

Description

On a permission deny, opencode builds a PermissionDeniedError whose message embeds the entire effective permission.bash ruleset, not just the rule that matched. That message is stored on the tool part's state.error and replayed to the model on every subsequent request in the session.

With a large but legitimate policy, one denial can exceed the context window. With about 5,500 bash rules, a single denied compound command produced a ~384,000-character (~96k-token) error string. Session input jumped from ~32k to ~193k tokens in one turn, forcing repeated compactions. After compaction the agent re-read files, was denied again, and looped.

The denial happens before tool.execute.after, so a plugin can't cap it there. experimental.chat.messages.transform can rewrite state.error, which works as a local workaround, but the fix belongs upstream.

Related: #42437 (denial records pruned from context). Here, the denial's payload is itself the context hazard.

Plugins

No response

OpenCode version

1.18.34. Also observed on 1.18.16 at smaller scale; the echo size tracks the ruleset size, not the version.

Steps to reproduce

Steps to reproduce
Configure a permission.bash ruleset. Even a small one shows it: with 15 rules, the denial message contains all 17 effective rules.
Have an agent run a command its ruleset denies, e.g. a compound command where one segment isn't allowed.
Inspect the tool part: state.error reads "The user has specified a rule which prevents you from using this specific tool call. Here are some of the relevant rules [ … every rule … ]".
Send any next prompt. The full ruleset is replayed in the request.
Expected

The denial names only the matched rule and the denied command, e.g.
PermissionDenied: matched rule {"permission":"bash","pattern":"head *","action":"deny"} for command "…".

Actual

The entire effective ruleset is serialized into the tool result on every denial and replayed across requests. The cost grows linearly with policy size.

Suggested fix

Build the error from the single rule returned by the evaluator (the last matching rule) plus the command, optionally with a rule count, instead of serializing the full ruleset.

Screenshot and/or share link

No response

Operating System

Ubuntu latest LTS

Terminal

Reproduced headless via opencode serve; also occurs in the TUI.

Activity

  1. github-actions commented on Oct 5, 2026

    @github-actions
    Contributor

    This issue might be a duplicate of an existing issue. Please check:

    • #44521: Requests showing only the specific permission rule responsible for a denied tool call, rather than dumping the full active ruleset.
  2. thdxr commented on Oct 11, 2026

    @thdxr
    Member

    Thanks for the report! OpenCode 2.0 is now out and development is focused on V2, so we're closing issues filed against OpenCode 1. Please upgrade (opencode upgrade --major, details: https://anoma.ly/notes/opencode-2-0), and if this is still relevant on 2.0, reopen this issue or open a new one with your 2.0 version.

    — from 𝕺𝖕𝖊𝖓𝕮𝖔𝖉𝖊

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

Metadata

Metadata

Assignees

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