[BUG] EnterWorktree(path) never loads the worktree's root CLAUDE.md / @imports (subdirectory CLAUDE.md files still load)
What's wrong
After EnterWorktree with path: (launch directory = a parent folder containing the repo), the worktree's root CLAUDE.md (and its @AGENTS.md import) is never loaded into context. CLAUDE.md files in subdirectories of the worktree still load as nested memory when files there are read. Without EnterWorktree, reading a file under the same worktree loads the root CLAUDE.md + import normally.
So a session that follows a repo's own "enter the worktree with EnterWorktree path:" instruction loses that repo's main agent instructions for the rest of the session (until compaction reloads instructions).
Minimal reproduction (Claude Code 2.1.288, macOS, hooks disabled)
P=$(mktemp -d) && mkdir -p $P/repo/sub && cd $P/repo && git init -q
printf '@AGENTS.md\n' > CLAUDE.md
printf 'The codeword is PINEAPPLE.\n' > AGENTS.md
printf 'The subword is MANGO.\n' > sub/CLAUDE.md
echo hi > sub/file.txt
git add -A && git -c user.email=t@example.com -c user.name=t commit -qm init
git worktree add -q .claude/worktrees/wt1 -b wt1
cd $P # launch directory = parent of the repo (multi-repo workspace)
Q='Based ONLY on instructions or memory you have been given (do not read any CLAUDE.md or AGENTS.md yourself), answer: "codeword=<X> subword=<Y>", UNKNOWN if not given.'
# A: EnterWorktree, then read a file in a worktree subdirectory
claude -p "Call EnterWorktree with path $P/repo/.claude/worktrees/wt1. Then Read $P/repo/.claude/worktrees/wt1/sub/file.txt. Then: $Q" \
--settings '{"disableAllHooks":true}' --model haiku --permission-mode bypassPermissions
# -> codeword=UNKNOWN subword=MANGO
# B (control): same read, no EnterWorktree
claude -p "Read $P/repo/.claude/worktrees/wt1/sub/file.txt. Then: $Q" \
--settings '{"disableAllHooks":true}' --model haiku --permission-mode bypassPermissions
# -> codeword=PINEAPPLE subword=MANGO
The same thing shows in real (Desktop Code tab) transcripts: after EnterWorktree path:, only nested_memory attachments for <wt>/<subdir>/CLAUDE.md appear. There is no attachment for <wt>/CLAUDE.md or <wt>/AGENTS.md until a post-compaction instructions attachment. Sessions that cd into the worktree via Bash instead get <wt>/CLAUDE.md + <wt>/AGENTS.md as nested_memory as expected.
Expected
After EnterWorktree, the worktree root's CLAUDE.md (with @ imports) is in context, as it would be for a session started in that directory.
Likely cause (inferred)
EnterWorktree moves the project root to the worktree. Root instructions were loaded at session start for the old root, and nested-memory loading only covers directories below the current root, so the new root's own CLAUDE.md falls between the two.
Workaround
A user-level PostToolUse hook on EnterWorktree that returns hookSpecificOutput.additionalContext telling the model to Read <worktree>/AGENTS.md.
Related: #98822 (MCP servers stay bound to the original checkout after EnterWorktree), #80692 (CwdChanged hooks not fired on EnterWorktree).