Skip to content

[BUG] Bash permission patterns with wildcards don't match commands with flags (e.g., "kill *" doesn't match "kill -9 PID") #6676

@ramarivera

Description

@ramarivera

Description

Bash permission patterns using wildcards appear to not match commands that include flags or arguments in certain positions.

Configuration:

"permission": {
  "bash": {
    "kill *": "ask",
    "pkill *": "ask"
  }
}

Expected behavior: Running kill -9 44165 should prompt for permission ("ask")

Actual behavior: The command executes immediately without prompting, even though the pattern "kill *" should match kill -9 44165

Possible cause (unconfirmed): After investigating the codebase, we noticed that the bash tool in packages/opencode/src/tool/bash.ts uses a whitelist of treesitter node types when extracting command tokens for permission matching:

if (
  child.type !== "command_name" &&
  child.type !== "word" &&
  child.type !== "string" &&
  child.type !== "raw_string" &&
  child.type !== "concatenation"
) {
  continue;
}

It's possible that flags like -9 are parsed as argument nodes by treesitter, which would cause them to be skipped during extraction. This could result in the command string being truncated to just "kill", which wouldn't match the pattern "kill *" (due to the literal space). The system might then fall back to the default "*": "allow" rule.

Note: This is speculative based on code review - we haven't confirmed this is the definitive root cause.

OpenCode version

1.0.224

Steps to reproduce

  1. Add this to opencode.json:
"permission": {
  "bash": {
    "kill *": "ask",
    "pkill *": "ask"
  }
}
  1. Start OpenCode and ask the agent to kill a process by PID
  2. Observe that kill -9 <PID> executes without prompting for permission

Screenshot and/or share link

No response

Operating System

macOS

Terminal

Ghostty


🤖 This content was generated with AI assistance using Claude Opus 4.5 (Thinking).

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