claude-code - 💡(How to fix) Fix Path-scoped rules and subdirectory CLAUDE.md not loaded when creating new files matching the pattern

Official PRs (…)
ON THIS PAGE

Recommended Tools

×6

Utilities matched from this issue’s tags and category — try them while you read without losing context.

GitHub issue graph ai analysis

Paste a GitHub issue URL. We fetch that issue, discover linked issues from bodies/comments/timeline, collect linked pull requests, and produce a structured English report.

The report is written in English Markdown for sharing and archival.

Helpful · Quick feedback

Loading…

Path-scoped rules (.claude/rules/*.md with paths frontmatter) and subdirectory CLAUDE.md files are only loaded when Claude reads a matching file. When Claude creates a new file matching the pattern, the rules are never loaded — because there is no read before a write on a file that doesn't exist yet.

Note: this is not an issue for editing existing files, since Claude always reads a file before modifying it, which triggers rule loading correctly.

Root Cause

Creating new files is the most important case for path-scoped conventions — that's when there's no existing code to follow as a reference and Claude needs the rules most.

RAW_BUFFERClick to expand / collapse

Summary

Path-scoped rules (.claude/rules/*.md with paths frontmatter) and subdirectory CLAUDE.md files are only loaded when Claude reads a matching file. When Claude creates a new file matching the pattern, the rules are never loaded — because there is no read before a write on a file that doesn't exist yet.

Note: this is not an issue for editing existing files, since Claude always reads a file before modifying it, which triggers rule loading correctly.

Steps to reproduce

  1. Create .claude/rules/typescript.md with paths: ["**/*.ts"] and an instruction like "Always report after reading this file"
  2. Ask Claude to create a new .ts file (one that doesn't exist yet)
  3. Observe: the rule is not loaded, the instruction is not followed

Same behavior with subdirectory CLAUDE.md: create src/components/CLAUDE.md, ask Claude to create a new file in src/components/ — rule is not loaded.

Expected behavior

Rules should also load when Claude creates a new file whose path matches the pattern.

Actual behavior

Rules only load on file reads. Since a new file has no prior content to read, rules are never loaded when creating it.

Why this matters

Creating new files is the most important case for path-scoped conventions — that's when there's no existing code to follow as a reference and Claude needs the rules most.

Vote matrix · Quick signals

Works
Did the solution work? Tap to confirm.
Easy Fix
Was it a quick fix?
Time Saver
Did it save you time?
Blocking
Was it severely blocking?
Common Issue
Are others likely hitting this too?
Flaky / Intermittent
Is it intermittent?
Verified / Reproducible
Can you reproduce it reliably?
Loading…

FAQ

Expected behavior

Rules should also load when Claude creates a new file whose path matches the pattern.

Still need to ship something?

×6

Another batch ranked right after the header list — different links, same matching logic.

Back to top recommendations

TRENDING