[BUG] @import directives inside path-scoped rule files load eagerly, ignoring the paths: frontmatter scope

Open 💬 2 comments Opened Jun 7, 2026 by lijok

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?

  A rule file in .claude/rules/ with paths: frontmatter is expected to only contribute to context when a file matching one of its globs is in play. However, if the rule body contains an @relative/path import
  directive, that import is resolved eagerly and inlined into context at session start, regardless of the paths: scope. The path scoping silently does not apply to imported content.

What Should Happen?

Because no .py file is in play, neither the rule body nor its imported content should be in context. The @import should be resolved only when the paths: glob matches.

Error Messages/Logs

Steps to Reproduce

  1. Create a path-scoped rule file .claude/rules/python.md:
  ---
  paths:
    - "**/*.py"
  ---

  @../../docs/python-conventions.md
   
   
  2. Create the imported target docs/python-conventions.md with some identifiable content.
  3. Start a session in the repo and touch no .py files.
  4. Ask Claude what is in its context / inspect the loaded context.

Claude Model

Opus

Is this a regression?

I don't know

Last Working Version

_No response_

Claude Code Version

2.1.168

Platform

Anthropic API

Operating System

macOS

Terminal/Shell

Terminal.app (macOS)

Additional Information

  Title: @import directives inside path-scoped rule files load eagerly, ignoring the paths: frontmatter scope

  Claude Code version: 2.1.168
  OS: macOS 15.7.3
  
  Summary

  A rule file in .claude/rules/ with paths: frontmatter is expected to only contribute to context when a file matching one of its globs is in play. However, if the rule body contains an @relative/path import
  directive, that import is resolved eagerly and inlined into context at session start, regardless of the paths: scope. The path scoping silently does not apply to imported content.

  Steps to reproduce
  
  1. Create a path-scoped rule file .claude/rules/python.md:
  ---
  paths:
    - "**/*.py"
  ---

  @../../docs/python-conventions.md
  2. Create the imported target docs/python-conventions.md with some identifiable content.
  3. Start a session in the repo and touch no .py files.
  4. Ask Claude what is in its context / inspect the loaded context.

  Expected behavior

  Because no .py file is in play, neither the rule body nor its imported content should be in context. The @import should be resolved only when the paths: glob matches.

  Actual behavior
  
  The full contents of docs/python-conventions.md are inlined into context at session start, before any .py file is touched. Every @import across all path-scoped rule files loads this way, so a repo with
  several scoped rules (Python, components, docs categories, etc.) ends up with all referenced documents loaded into every session — defeating the purpose of the path scoping and consuming significant
  context.
  
  Apparent cause

  @path import resolution (the CLAUDE.md memory-import mechanism) appears to run globally/eagerly and is not gated by the containing rule file's paths: frontmatter. The two mechanisms compose incorrectly: the
  frontmatter scopes the rule body, but the import escapes that scope.

  Impact
  
  - Path-scoped rules give a false sense of context economy; imported content is always loaded.
  - Hard to notice — the frontmatter looks correct and the leak is only visible by inspecting loaded context.

  Workaround

  Replace @import directives in scoped rule files with prose pointers (e.g. Read `docs/python-conventions.md` ...) so content is read on demand rather than inlined. This restores scoping but weakens the
  guarantee — the referenced doc is only read if the model follows the pointer.

  Suggested fix
  
  Either gate @import resolution by the containing rule file's paths: scope, or document explicitly that @imports in scoped rules are always global and warn/lint when an @import appears in a file with paths:
  frontmatter.

View original on GitHub ↗

This issue has 2 comments on GitHub. Read the full discussion on GitHub ↗