[BUG] Skill tool fails with 'Invalid regular expression: unmatched parentheses' in getPromptForCommand
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
- Create a skill with square brackets in the
argumentsfield (e.g.,[--flag]) - Invoke the skill via the Skill tool
- 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.
This issue has 3 comments on GitHub. Read the full discussion on GitHub ↗