Skip to content

[BUG] Path-scoped rules in .claude/rules/ not automatically loaded when working with matching files #16853

@BlondeLegion

Description

@BlondeLegion

Preflight Checklist

  • I have searched existing issues and this hasn't been reported yet
  • This is a single bug report (please file separate reports for different bugs)
  • I am using the latest version of Claude Code

What's Wrong?

Rules with paths: frontmatter in .claude/rules/ subdirectories are never automatically loaded into context when reading or editing files that match the specified glob patterns.

Setup:

  • Global rules in .claude/rules/general/ (no paths: frontmatter) load correctly
  • Path-scoped rules in other subdirectories like .claude/rules/api/, .claude/rules/services/ have paths: frontmatter but never load

Example rule file at .claude/rules/api/api-rules.md:

---
paths: src/api/**, lib/api/**
---

# API Rules

- Always validate request parameters
- Use structured error responses

Observation:
When running /context, only the general rules appear under "Memory files":

Memory files
└ .claude/CLAUDE.md: 3.8k tokens
└ .claude/rules/general/architecture.md: 2.5k tokens
└ .claude/rules/general/coding-standards.md: 535 tokens

The path-scoped rules (e.g., .claude/rules/api/api-rules.md) don't appear at all - not even as "available but not loaded."

When I then read a file that matches the path pattern (e.g., src/api/routes.ts), the path-scoped rule is still not injected into context.

What Should Happen?

When I read or edit a file matching a rule's paths: glob pattern, that rule should automatically be loaded into context. For example:

  • Reading src/api/routes.ts should load .claude/rules/api/api-rules.md (matches src/api/**)
  • The /context command should show path-scoped rules as available (perhaps with their path patterns)

Error Messages/Logs

No error messages. The rules are silently not loaded.

Steps to Reproduce

  1. Create a project with Claude Code initialized

  2. Create a global rule (works correctly):

    mkdir -p .claude/rules/general
    echo "# Global Rules\n\n- Always use TypeScript" > .claude/rules/general/global.md
  3. Create a path-scoped rule:

    mkdir -p .claude/rules/api
    cat > .claude/rules/api/api-rules.md << 'EOF'
    ---
    paths: src/api/**
    ---
    
    # API Rules
    
    - Always validate input parameters
    - Return structured JSON errors
    EOF
  4. Create a matching source file:

    mkdir -p src/api
    echo "export function handler() { return 'hello'; }" > src/api/routes.ts
  5. Start Claude Code: claude

  6. Run /context - observe that only the global rule appears under "Memory files", not the path-scoped rule

  7. Ask Claude to read the matching file: "Read src/api/routes.ts"

  8. Expected: The api-rules.md content should now be in context
    Actual: The rule is still not loaded; Claude has no awareness of the API rules

Claude Model

Opus

Is this a regression?

No, this never worked

Last Working Version

No response

Claude Code Version

v2.1.1

Platform

Anthropic API

Operating System

macOS

Terminal/Shell

VS Code integrated terminal

Additional Information

This also does not work in the standard macOS terminal.

Metadata

Metadata

Assignees

No one assigned

    Labels

    area:corebugSomething isn't workinghas reproHas detailed reproduction stepsmemoryplatform:macosIssue specifically occurs on macOSstaleIssue is inactive

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions