[BUG] paths: frontmatter with multiple patterns only matches first pattern; globs: has no scoping at all

Resolved 💬 4 comments Opened Apr 9, 2026 by nappa0326 Closed May 23, 2026

Summary

Two related issues with rules frontmatter scoping:

  1. paths: with multiple patterns: Only the first pattern is evaluated. Second and subsequent patterns are silently ignored.
  2. globs: field: Provides no scoping at all — rules are loaded unconditionally at session start regardless of glob patterns.

Environment

  • Windows 11 Pro
  • Claude Code latest (tested across multiple recent versions)
  • Tested at both user-level (~/.claude/rules/) and project-level (.claude/rules/)

Bug 1: paths: multiple patterns — only first matches

Reproduction

  1. Create .claude/rules/test.md:
---
paths:
  - "**/*.ts"
  - "**/*.js"
---
# MULTI_PATTERN_TEST
This rule should load for both .ts and .js files.
  1. Start a new interactive session (not resume)
  2. Read a .ts file → rule loads ✅
  3. Start another new session
  4. Read a .js file → rule does NOT load ❌

Pattern swap test

Swapping list order (.js first, .ts second):

  • .js now matches ✅
  • .ts no longer matches ❌

→ Always only the first pattern is evaluated.

All tested formats (same behavior)

| Format | 1st pattern | 2nd pattern |
|--------|-------------|-------------|
| YAML list: - "**/*.ts" + - "**/*.js" | ✅ | ❌ |
| CSV: paths: **/*.ts,**/*.js | ✅ | ❌ |
| Brace expansion: paths: **/*.{ts,js} | 1st expansion only ✅ | ❌ |
| Space-separated: paths: **/*.ts **/*.js | ❌ | ❌ |

Tested at both project-level and user-level — same result.

Expected behavior

All patterns in the list should be evaluated with OR logic. The v2.1.84 CHANGELOG states "Rules and skills paths: frontmatter now accepts a YAML list of globs", implying full support.

Bug 2: globs: field has no scoping

Reproduction

  1. Create .claude/rules/test-globs.md:
---
globs: **/*.ts, **/*.js
---
# GLOBS_TEST
This rule should only load for .ts and .js files.
  1. Start a new interactive session
  2. Without reading any file, ask if the rule is visible → rule IS loaded ❌

The rule is loaded unconditionally at session start, regardless of glob patterns. Tested with:

  • Quoted: globs: "**/*.ts, **/*.js" — same behavior (always loaded)
  • Unquoted: globs: **/*.ts, **/*.js — same behavior (always loaded)
  • Project-level and user-level — same behavior (always loaded)

Expected behavior

globs: should scope rules to matching files only, similar to paths:.

Test methodology

  • Each test performed in a fresh interactive session (not resume, not -p batch mode)
  • One file read per session to avoid cross-contamination
  • Unique keywords embedded in test rules (e.g., MULTI_PATTERN_TEST) to detect loading via Claude's response
  • Confirmed that single paths: pattern works correctly (control test)

What works correctly (control tests)

| Condition | Behavior |
|-----------|----------|
| paths: single pattern + project-level | ✅ Lazy-loads on matching file Read |
| paths: single pattern + user-level | ✅ Lazy-loads on matching file Read |
| No frontmatter (no scoping) | ✅ Loads at session start |

Related issues

  • #13905 — YAML syntax issues (partially addressed in v2.1.84)
  • #17204 — Documentation vs implementation mismatch
  • #21858 — User-level rules paths ignored (single pattern now works, but multiple still broken)
  • #23478 — Write operation doesn't trigger paths rules (NOT_PLANNED)

View original on GitHub ↗

This issue has 4 comments on GitHub. Read the full discussion on GitHub ↗