[BUG] Path-scoped rules and nested CLAUDE.md never load when Write creates a new file
Preflight Checklist
- [x] I have searched existing issues and this hasn't been reported yet. Earlier reports of the same bug were auto-closed as inactive, not fixed: #23478, #63142, #82482. The stale bot asks for a new issue if it's still relevant, and it is.
- [x] This is a single bug report
- [x] I am using the latest version of Claude Code (2.1.280)
What's Wrong?
Path-scoped rules (.claude/rules/*.md with paths:) and nested CLAUDE.md files load only when Claude reads a matching file. Creating a new file with Write loads neither. So a directory's conventions are missing at the moment they matter most: when Claude writes a new file into that directory.
Existing files are mostly unaffected. Write refuses to overwrite a file that hasn't been read, and that read loads the rules. The gap is new files, and a new rule file in .claude/rules/ is one of them.
What Should Happen?
When a Write targets a path that matches a rule's paths:, or that sits under a directory with a CLAUDE.md, those instructions should load before the write is applied. At the latest they should arrive attached to the Write result, so Claude can correct the file right away.
Error Messages/Logs
None. The failure is silent.
Steps to Reproduce
In an empty git repo:
.claude/rules/r1.md: frontmatterpaths: ['r1/**'], bodyCANARY-R1-RULE.claude/rules/cfg.md: frontmatterpaths: ['**/*.cfg'], bodyCANARY-CFG-RULEr2/CLAUDE.md: bodyCANARY-R2-CLAUDEMD
Run each action below in a fresh claude -p session. I checked the result against the harness-written (non-assistant) records in the session transcript, not only against what the model reported.
| Action (fresh session each) | r1/** rule | **/*.cfg rule | r2/CLAUDE.md |
|---|---|---|---|
| Write a new r1/a.txt / top.cfg / r2/a.txt, nothing read first | not loaded | not loaded | not loaded |
| Read the same file | loaded | loaded | loaded |
| Write over the existing r1/a.txt without reading it | refused by Write (must read first) | n/a | n/a |
Claude Model
Not model-specific. Reproduced with claude-haiku-4-5.
Is this a regression?
I don't know.
Claude Code Version
2.1.280 (Claude Code)
Platform
Anthropic API
Operating System
Linux (claude.ai/code remote container)
Terminal/Shell
Non-interactive (claude -p)
Additional Information
- Auto mode makes this worse: its system prompt steers file work through Bash, and neither mechanism ever loads through Bash (#90450, #95083).
- A workaround is a
PostToolUsehook onWritethat tells Claude toReadthe file it just created, which triggers loading, followed by a correctiveEdit. It costs an extra round trip on every new file.
---
_Generated by Claude Code_
This issue has 2 comments on GitHub. Read the full discussion on GitHub ↗