feat: add deny-with-reason plugin#33809
Open
mattwwarren wants to merge 2 commits intoanthropics:mainfrom
Open
Conversation
When Claude attempts a tool call that matches a configured pattern,
the plugin denies it and sends the reason as a system message so
Claude understands why and adjusts its approach immediately.
Users configure rules in .claude/deny-reasons.yaml:
rules:
- pattern: "Bash(pnpm *)"
reason: "Use npm instead of pnpm"
Addresses anthropics#29782
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
36 tests covering pattern parsing, rule matching, config loading, response format, and end-to-end subprocess invocation. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This was referenced Mar 13, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
deny-with-reasonplugin that denies tool calls matching configured patterns and sends the reason to Claude as a system message, so it understands why and adjusts immediately.claude/deny-reasons.yamlfile withToolName(glob)pattern syntaxAddresses #29782
How it works
The plugin registers a PreToolUse hook. When Claude attempts a tool call matching a rule:
permissionDecision: "deny"systemMessageExample config:
Scope
This addresses the configuration-based half of #29782. The interactive half (typing a reason at the TUI deny prompt) would require either a core binary change or a new hook event (e.g.,
ToolDenied/PermissionDenied) that plugins could tap into — recommending this as a complementary core enhancement.Test plan
🤖 Generated with Claude Code