anthropics / anthropics/claude-code
Path-scoped .claude/rules only load via the Read tool, while auto mode instructs the model to prefer Bash
- Dominant language
- Python
- Stars
- 145k
- Forks
- 23.1k
- PR merge metrics
- PR metrics pending
Description
### What's Wrong?
Path-scoped rules (`.claude/rules/*.md` with `paths:` frontmatter) only enter context when a matching file is opened with the **`Read`** tool. Reading or changing the same file through **Bash** (`cat`, `head`, `sed -i`, a heredoc) does not load the rule.
On its own that would be an understandable limitation. It turns into a real problem because **auto mode injects a system-prompt instruction that steers the model to exactly that path**. Verbatim, as it appears in the system prompt when auto mode is active:
> While auto mode is active:
>
> Do your work through the Bash tool wherever it can accomplish the job: read files with cat, head, or sed -n, search with grep and find, and make file changes with sed, heredocs, or short scripts, rather than using the dedicated Read, Edit, or Write tools. Fall back to a dedicated tool only when Bash genuinely cannot do the job.
So in auto mode the model is told to prefer the one form of file access that never triggers path-scoped rules. A project's coding conventions, security guardrails and per-directory instructions silently stop applying. Nothing in the transcript shows that a rule was skipped, so the user cannot see it happening.
For completeness: `Write` to a new file at a matching path does not load the rule either. That half overlaps with #82482, which reports the file-creation gap. This issue is about Bash access and about the interaction with auto mode's tool preference, which I could not find reported.
### What Should Happen?
Path-scoped rules should load when Claude accesses a matching path, not only when it happens to use `Read`. Any of these would fix it:
- Match file paths that appear in Bash commands against rule `paths:` and inject the matching rules before the command runs.
- Do not steer the model away from the file tools in auto mode while those tools are the only rule trigger.
At the very least the two mechanisms should not contradict each other the way they do now.
### Steps to Reproduce
In a project with one path-scoped rule:
```markdown
# .claude/rules/probe.md
---
paths:
- "config/demo/**"
---
PROBE: this rule loaded.
```
and an existing file `config/demo/thing.yml`. In a session that has not loaded the rule yet:
1. Run `head -3 config/demo/thing.yml` through the **Bash** tool. The rule is **not** injected.
2. Open the same file with the **`Read`** tool. The rule **is** injected, as a `Contents of .../.claude/rules/probe.md` system reminder.
3. Create `config/demo/other.yml` with the **`Write`** tool. The rule is **not** injected.
I observed this with two independent, unrelated path-scoped rules in one session, with the same result each time.
### Claude Code Version
2.1.267
### Claude Model
Opus 5 (`claude-opus-5`)
### Platform
Claude Code desktop app, macOS, zsh.
### Is this a regression?
Not sure. I have not tested an earlier version.
Contributor guide
No contributing guide indexed for this repository
Research direction
Reproduce the issue with .claude/rules/probe.md and config/demo files, comparing Bash access with the Read tool and the auto-mode instruction. Trace the path-scoped rule loading and auto-mode tool-selection entry points to understand where Bash paths are handled. Done means matching rules apply during the reported access paths, or auto mode no longer bypasses the only trigger.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- bash, python
- Domain
- cli, developer-experience, tooling
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Active
- Clarity
- Mostly clear
- Newbie friendliness
- 48/100