Skip to content

parseAllowedTools() regex pattern order causes wrong flag to be matched with mixed quotes #805

Description

@AlexanderBartash

Issue Title

parseAllowedTools() regex pattern order causes wrong flag to be matched with mixed quotes

Issue Body

Bug Description

parseAllowedTools() in src/modes/agent/parse-tools.ts checks regex patterns in a specific order:

  1. Double-quoted: --allowed-tools "value"
  2. Single-quoted: --allowed-tools 'value'
  3. Unquoted: --allowed-tools value

This means if the input has mixed quote styles, it matches the first occurrence of the quote style checked first, not the first --allowed-tools flag in the string.

Reproduction

const input = `--allowed-tools 'mcp__github_inline_comment__create_inline_comment'
--allowed-tools 'mcp__context7__*'
--allowed-tools "Write,Edit,MultiEdit"`;

parseAllowedTools(input);
// Expected: ['mcp__github_inline_comment__create_inline_comment']
// Actual:   ['Write', 'Edit', 'MultiEdit']

Even though mcp__github_inline_comment__* is the FIRST flag in the string, the double-quoted pattern is checked first and matches "Write,Edit,MultiEdit".

Impact

This breaks the workaround for #800 (putting mcp__github_* tools first). Users must also ensure they use double quotes for the first flag, which is non-obvious.

The MCP server initialization depends on parseAllowedTools() finding mcp__github_* tools. When it finds the wrong value, the github_inline_comment server is not configured, and the tool becomes unavailable.

Workaround

Use double quotes for the mcp__github_* tools:

claude_args: |
  --allowed-tools "mcp__github_inline_comment__create_inline_comment"  # Double quotes!
  --allowed-tools 'mcp__context7__*'
  --allowed-tools "Write,Edit,MultiEdit"

Suggested Fix

Option 1: Find the actual first --allowed-tools in the string regardless of quote style:

const allPatterns = /--(?:allowedTools|allowed-tools)\s+(?:"([^"]+)"|'([^']+)'|([^\s]+))/g;
// Find the match with the smallest index

Option 2: The fix in PR #801 (parsing ALL flags) would also solve this, since all values would be accumulated.

Related Issues

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions