@import in an ancestor CLAUDE.md does not expand (subdirectory launch)
@import in an ancestor CLAUDE.md does not expand (subdirectory launch)
Summary
When Claude Code loads a CLAUDE.md as an ancestor — i.e. the session is launched from a
subdirectory and the file is discovered by walking up the tree — the file's own body text loads,
but its @path import directives do not expand. Imports appear to expand only for the CLAUDE.md
in the launch directory itself. /context (the authoritative loaded-files view) confirms this, so it
is not a model self-report artifact.
This silently breaks the officially recommended pattern (memory docs) of a thin CLAUDE.md whose
first line is @AGENTS.md: from any subdirectory session, the AGENTS.md content never loads and the
developer gets an almost-empty CLAUDE.md, with no warning.
Environment
- Claude Code CLI, version 2.1.x (reproduced today), macOS, model claude-opus-4-8[1m].
Minimal repro
mkdir -p demo/sub && cd demo && git init -q
printf '@RULES.md\n\n## local\n(local note)\n' > CLAUDE.md
printf '# Rules\nUNIQUE_CANARY_PHRASE_12345\n' > RULES.md
- From the repo root
demo/, runclaudeand/context→ the@RULES.mdimport expands;
RULES.md appears as a loaded memory file (canary present).
- From
demo/sub/, runclaudeand/context→ the ancestordemo/CLAUDE.mdloads (its## local
body is present) but RULES.md is absent — the @RULES.md import did not expand.
Observed (via /context, authoritative)
In a real repo with CLAUDE.md = @AGENTS.md + a small body:
- Launched from repo root:
/contextlistsAGENTS.mdas its own loaded entry (~1.9k tokens) —
import expanded. ✅
- Launched from a subdirectory:
/contextshows the rootCLAUDE.mdat only ~335 tokens (its
body alone) and no AGENTS.md entry at all — import did not expand. ❌
- Cross-checked by asking the model to quote the imported section back: "NOT IN CONTEXT" (3/3);
and a present/absent probe: 10/10 absent from the subdirectory, present from root.
Expected
Either an ancestor CLAUDE.md's @imports expand the same way the launch-directory file's do, or the
docs explicitly state ancestor imports are not expanded (the recommended @AGENTS.md pattern relies on
it, so this is a silent, surprising failure).
Impact
Common in monorepos / plugin repos where developers launch Claude from a subpackage. They silently
lose all imported canonical rules. Workaround: duplicate the content into both files (what we did), or
always launch from the repo root.
This issue has 1 comment on GitHub. Read the full discussion on GitHub ↗