[BUG] Rules with glob patterns not applied when creating new files
Preflight Checklist
- [x] I have searched existing issues and this hasn't been reported yet
- [x] This is a single bug report (please file separate reports for different bugs)
- [x] I am using the latest version of Claude Code
What's Wrong?
Rules defined in .claude/rules/ with glob patterns are only surfaced as system-reminders when reading or
editing existing files, but not when creating new files with the Write tool. This means rules are
silently ignored during file creation.
Actual Behavior
Rules are only triggered on file reads/edits. New file creation bypasses the rules entirely, leading to
inconsistent and hard-to-catch issues.
What Should Happen?
Rules with matching glob patterns should be surfaced when creating new files via the Write tool, not only
on reads/edits. This would ensure rules are applied consistently from the start.
Error Messages/Logs
Steps to Reproduce
.claude/rules/javascript.md:
---
paths:
- "**/*.js"
---
In each function you create add a `console.log("Called {function-name}.")` at the end of the function.
Scenario 1: Create file, then read and apply rule
- Ask Claude to create a new JS file with a
helloWorldfunction - Claude creates the file without applying the rule — no
console.logis added - Ask Claude to read the file — the rule now appears as a system-reminder
- Only after reading does Claude become aware of the rule and can retroactively apply it
Result: The rule is missed on creation and only discovered on a subsequent read, requiring a manual
follow-up to fix the file.
Scenario 2: Create file, then add a second function
- Ask Claude to create a new JS file with a
helloWorldfunction - Claude creates the file without applying the rule — no
console.logis added tohelloWorld - Ask Claude to add a second function (e.g.
sayHallo) to the same file - Claude reads the file to edit it — the rule now appears as a system-reminder
- Claude applies the rule to the new
sayHallofunction but the originalhelloWorldfunction remains
non-compliant
Result: The same file ends up with inconsistent behavior — new functions follow the rule, but the
original function created before the rule was surfaced does not.
Claude Model
Opus
Is this a regression?
I don't know
Last Working Version
_No response_
Claude Code Version
2.1.37
Platform
Anthropic API
Operating System
Ubuntu/Debian Linux
Terminal/Shell
Other
Additional Information
_No response_
This issue has 3 comments on GitHub. Read the full discussion on GitHub ↗