anthropics / anthropics/claude-code

CLAUDE.md loads twice on the nested_traversal path when two paths reach the same file

Open
#94,463 0 comments 0 reactions 0 assignees View on GitHub
area:core bug has repro platform:macos
Dominant language
Python
Stars
145k
Forks
23.1k
PR merge metrics
PR metrics pending

Description

Claude Code loads one `CLAUDE.md` file twice when two different path spellings reach it and one of them sits below the working directory. The session-start loader resolves symlinks and dedupes correctly. The `nested_traversal` loader compares literal path strings, so it loads a file the session already holds.

https://github.com/anthropics/claude-code/issues/73335 covers the session-start half (fixed). This issue covers the nested path.

## Environment

- Claude Code 2.1.272
- macOS, Darwin 27.0.0, arm64

## Steps to reproduce

1. Run `mkdir -p /tmp/repro/sub && printf 'hi\n' > /tmp/repro/sub/note.txt`.
2. Write about 27 KB of filler text to `/tmp/repro/sub/CLAUDE.md`. Include the token `UNIQUEMARKER-Q7X` one time.
3. Run `ln -s /tmp/repro/sub/CLAUDE.md ~/.claude/CLAUDE.md`.
4. Change to `/tmp/repro`.
5. Run `claude -p "Use the Read tool on ./sub/note.txt, then reply with only the number of copies of UNIQUEMARKER-Q7X in your context." --model sonnet --output-format json`.

## Result

The model answers `2`. It must answer `1`.

An `InstructionsLoaded` hook records both loads:

```
User session_start ~/.claude/CLAUDE.md
Project nested_traversal /private/tmp/repro/sub/CLAUDE.md
```

The prompt prefix grows from 43,064 tokens before the Read to 56,093 after it. One copy of the fixture measures 12,807 tokens, so the session pays for the file twice.

## Controls

- The same file at the working-directory root loads one time, and the model answers `1`.
- Without a Read inside `sub/`, only the user entry loads.
- A project-root `CLAUDE.md` symlinked to `sub/CLAUDE.md` also loads twice, and costs 12,942 extra tokens.
- A real root `CLAUDE.md` whose `sub/CLAUDE.md` symlinks back to it also loads twice, and costs 12,937 extra tokens.

The last two controls show the defect is not specific to user memory. A symlink on either side defeats the nested loader.

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.