[PR #11908] feat: add regex support for bash permissions #13979

Open
opened 2026-02-16 18:18:48 -05:00 by yindo · 0 comments
Owner

Original Pull Request: https://github.com/anomalyco/opencode/pull/11908

State: open
Merged: No


What does this PR do?

Fixes https://github.com/anomalyco/opencode/issues/11397

This adds regex pattern support to the permission system for more flexible pattern matching. Previously, the permission system only supported simple wildcards (* and ?). This enhancement allows users to define more complex patterns using regular expressions by wrapping them in forward slashes (e.g., "/pattern/").

The changes include:

  • Modified the Wildcard.match function to detect and handle regex patterns (patterns starting and ending with "/")
  • Added comprehensive tests for regex patterns including alternation, wildcards, and whitespace matching
  • Updated documentation in both agents.mdx and permissions.mdx to explain regex usage with examples

This allows users to write more precise permission rules, such as:

  • "/brew (install|info|list)/" to allow specific brew commands
  • "/git\s+(status|log|diff)/" to match git commands with proper whitespace handling

How did you verify your code works?

I copied all of my regex patterns from my vscode github copilot extension settings over to my opencode.json permissions. All my bash allow/ask/deny rules worked perfectly in opencode. I also tested the original wildcard rules and they still work.

**Original Pull Request:** https://github.com/anomalyco/opencode/pull/11908 **State:** open **Merged:** No --- ### What does this PR do? Fixes https://github.com/anomalyco/opencode/issues/11397 This adds regex pattern support to the permission system for more flexible pattern matching. Previously, the permission system only supported simple wildcards (* and ?). This enhancement allows users to define more complex patterns using regular expressions by wrapping them in forward slashes (e.g., "/pattern/"). The changes include: - Modified the `Wildcard.match` function to detect and handle regex patterns (patterns starting and ending with "/") - Added comprehensive tests for regex patterns including alternation, wildcards, and whitespace matching - Updated documentation in both agents.mdx and permissions.mdx to explain regex usage with examples This allows users to write more precise permission rules, such as: - "/brew (install|info|list)/" to allow specific brew commands - "/git\\s+(status|log|diff)/" to match git commands with proper whitespace handling ### How did you verify your code works? I copied all of my regex patterns from my vscode github copilot extension settings over to my opencode.json permissions. All my bash allow/ask/deny rules worked perfectly in opencode. I also tested the original wildcard rules and they still work.
yindo added the pull-request label 2026-02-16 18:18:48 -05:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: anomalyco/opencode#13979