[BUG] CLAUDE.md/AGENTS.md reloaded and re-injected when cd revisits a directory via a different relative path (worktree round-trip)
Environment
- Claude Code CLI, Linux, working from
/rootwhich is a container directory (not itself a git repo) for a monorepo cloned at/root/skuvelo, with ~34git worktreecheckouts as siblings under/root/sk-*//root/skuvelo-*.
Repro
- Start a session with cwd somewhere that has
CLAUDE.md/AGENTS.mdin its ancestor chain (e.g./root/skuvelo). - Do work that touches a subdirectory with its own memory files, e.g.
apps/web/CLAUDE.md+apps/web/AGENTS.md— these load once, as expected. cd(via the Bash tool) into a sibling worktree, e.g.../sk-hero-trial-cta, whose root also carriesCLAUDE.md/AGENTS.md— these load, as expected.cdback intoapps/web(e.g.../../skuvelo/apps/webor an equivalent relative path back to a directory already visited in step 2).
Observed: apps/web/CLAUDE.md and apps/web/AGENTS.md are reloaded and re-injected, even though the exact same directory was already loaded once earlier in the same session:
Loaded CLAUDE.md
Loaded AGENTS.md
Loaded apps/web/CLAUDE.md
Loaded apps/web/AGENTS.md
Loaded ../sk-hero-trial-cta/CLAUDE.md
Loaded ../sk-hero-trial-cta/AGENTS.md
Loaded apps/web/CLAUDE.md <- duplicate of an already-loaded file
Loaded apps/web/AGENTS.md <- duplicate of an already-loaded file
Expected behavior
Memory-file loading during a session should dedupe by canonical/resolved absolute path, not by the literal cd argument or per-command relative cwd string. Once a directory's CLAUDE.md/AGENTS.md has been loaded in a session, revisiting that same resolved path — including via a different relative path, or after a cd through an unrelated worktree — should not reload or re-inject it.
Cost
In this project the repo-root CLAUDE.md + AGENTS.md pair is ~26KB combined, and the project's normal workflow involves an agent moving between the main clone and multiple worktree siblings in a single session. Each directory revisit that re-triggers a load adds real, avoidable token cost on top of everything downstream in that turn.
This looks like the same root-cause class as #75931 (dedup during memory-file loading is not keyed to a canonical/resolved path) but with a different trigger — plain worktree cd traversal rather than a symlinked dotfiles tree — so filing separately rather than as a duplicate.
Workaround
Avoid cd-ing back and forth between the main repo and worktrees within one session; do work in one directory to completion before moving to the next, or spawn a separate subagent per worktree instead of one agent hopping between directories.