[BUG] Skill tool fails with 'Invalid regular expression: unmatched parentheses' in getPromptForCommand

Status Fixed / completed
Reported on v2.1.85
Maintainer reply ✓ Yes — claude[bot]
Activity 3 comments · opened Mar 27, 2026 · closed May 11, 2026
💡 Likely answer: A maintainer (claude[bot], contributor) responded on this thread — see the highlighted reply below.

Description

Skill invocations via the Skill tool fail with Invalid regular expression: unmatched parentheses when the arguments frontmatter field contains square brackets [].

Root Cause

The arguments field value is compiled as a RegExp inside getPromptForCommand without escaping special regex characters. Square brackets like [--mode MODE] (common notation for optional arguments) create an invalid regex character class.

Minimal Reproduction

Fails:

---
name: my-skill
description: A test skill.
arguments: --vault PATH --session ID [--mode MODE]
---

Works:

---
name: my-skill
description: A test skill.
arguments: --vault PATH --session ID --mode MODE
---

Error Message

Skill tool error (6ms): Invalid regular expression: unmatched parentheses
SyntaxError: SyntaxError: Invalid regular expression: unmatched parentheses
    at <parse> (:0)
    at RegExp (unknown)
    at OyH (/$bunfs/root/src/entrypoints/cli.js:3223:870)
    at getPromptForCommand (/$bunfs/root/src/entrypoints/cli.js:3227:17)

Steps to Reproduce

  1. Create a skill with square brackets in the arguments field (e.g., [--flag])
  2. Invoke the skill via the Skill tool
  3. Error occurs immediately (6ms)

Skills without brackets in arguments work fine. Skills without an arguments field work fine.

Environment

  • Claude Code version: 2.1.85
  • Platform: macOS (Darwin 25.3.0, arm64)

Fix Suggestion

Escape the arguments field value before compiling it as a RegExp in getPromptForCommand / OyH, e.g.:

const escaped = args.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
new RegExp(escaped);

Workaround

Remove square brackets from the arguments frontmatter field. Use plain listing instead of [--optional] notation.

View original on GitHub ↗

3 Comments

Cloudy-Avalon · 5 months ago

Bumping the issue :)

Have encountered it today as well. Quite annoying (since the square brackets notation is a valid YAML syntax) and, by the looks of it, easily fixable indeed.

claude[bot] contributor · 5 months ago

This issue was fixed as of version 2.1.139.

github-actions[bot] · 3 months ago

This issue has been automatically locked since it was closed and has not had any activity for 7 days. If you're experiencing a similar issue, please file a new issue and reference this one if it's relevant.