You open Claude Code in api, add web with --add-dir, and ask for a change that spans both. The agent follows api/CLAUDE.md to the letter. In web it runs npm where the file says pnpm, and writes tests where the file says they do not go. It never read web/CLAUDE.md.

That is documented behaviour. The Claude Code memory docs say CLAUDE.md files in directories added with --add-dir are not loaded by default. Setting CLAUDE_CODE_ADDITIONAL_DIRECTORIES_CLAUDE_MD=1 turns loading on for CLAUDE.md, .claude/CLAUDE.md and .claude/rules/*.md in those directories. Bug reports filed in 2026 show where that still falls short, so the reliable answer is to check what loaded on your own version. In a multi-repo worktree setup such as ivar, each repo's instruction file reaches the agent through a hook on the tool call that touches the repo.

The memory docs and the large codebases guide describe three places:

| where the file is | when it loads | |---|---| | the working directory and every parent directory | in full, at launch | | a subdirectory of the working directory | on demand, when Claude reads files there | | a directory added with --add-dir | only with CLAUDE_CODE_ADDITIONAL_DIRECTORIES_CLAUDE_MD=1 |

The first two rows explain the common workaround: start Claude Code in a parent folder that holds every repo, the "repo-of-repos", with a root CLAUDE.md for what the repos share and a file in each repo for the rest. Hjarni describes the same split, a small CLAUDE.md per repo and the shared material somewhere else. It works when the repos already sit side by side on the branches you want. The third row is the one people hit when they keep the repos apart and add them to a session.

Before changing anything, make the question testable. Add one line to the second repo's CLAUDE.md that the agent cannot guess:

- If asked for the canary, answer with exactly `web-canary-7f3`.

Then ask for it from a session started in the first repo:

cd ~/code/api
claude --add-dir ../web -p 'What is the canary? Answer with the token only, or "none".'

Without the variable, the documented result is none: web/CLAUDE.md is not in context. Run it again with the variable:

CLAUDE_CODE_ADDITIONAL_DIRECTORIES_CLAUDE_MD=1 \
  claude --add-dir ../web -p 'What is the canary? Answer with the token only, or "none".'

Now the token should come back. In an interactive session, /context lists the memory files that loaded, which tells you the same thing without a prompt. Put a second canary in web/.claude/rules/ and a third in a nested web/src/CLAUDE.md and ask for each: they are the cases the reports below are about.

To keep the variable, export it in your shell profile or set it under env in your user settings.json. The Classmethod write-up found that Claude Code on the web loads the CLAUDE.md of every attached repository, because the cloud environment already sets the variable; the CLI does not.

The variable covers --add-dir. Two reports filed in 2026 describe what it does not reach:

--add-dir, only the top-level CLAUDE.md loaded; .claude/rules/*.md in that directory did not (additionalDirectories in settings.json did not load its CLAUDE.md, while the same directory passed with Both are marked resolved on the issue mirror, and related reports about additionalDirectories stay open. The canaries above tell you which behaviour your version has. A rule that matters should not depend on a load path you have not checked.

ivar lays the repos out differently. A hall holds the repos, a feature promotes the ones it changes onto its own branch, and a session is a view dir: a folder with one symlink per repo. The hall is set up once (quickstart). After that, the reader describes the change and the agent, started at the hall root, runs ivar itself:

Add a checkout step that spans api and web.

That touches two repos, so I'll open one feature and promote both.

checkout is open: api and web are writable on their own branch. I'll work through the session's view dir.

The view dir the last call names looks like this:

.ivar/features/checkout/sessions/<id>/
  api  -> the api worktree on branch checkout   (promoted: writable)
  web  -> the web worktree on branch checkout   (promoted: writable)
  CLAUDE.md                                     (generated for this session)

The session's CLAUDE.md holds the hall's shared instructions from HALL.md, a block that tells the agent where the feature stands, and a generated section that points at each repo's own file through the view:

## Repository instructions

Each linked repository has its own instructions. They are delivered to you as you work in the repository; read them in full before working in it:

- `api`: <view>/api/CLAUDE.md
- `web`: <view>/web/CLAUDE.md

The agent stays at the hall root, so this file does not load at launch; the skill behind session connect tells the agent to read it. The list is a pointer either way. ivar does not count on Claude Code following the api and web symlinks to load their CLAUDE.md files on demand. The files arrive through ivar guard, the PreToolUse hook the hall installs, which runs before every tool call. When the guard ties a call to the session and allows it, and the call touches a path under <view>/web/ (a file it reads or edits, its working directory, a path in a shell command), it returns every instruction file from the repo root down to the touched directory that this agent has not seen yet, whole and labelled with its absolute path, in the hook's additionalContext:

Repository instructions from <view>/web/CLAUDE.md (they apply to work under <view>/web):

Each directory contributes CLAUDE.md, or AGENTS.md when it has no CLAUDE.md. A file goes to each agent once, the main agent and every subagent separately, and again marked UPDATED when its content changes. That includes the moment ivar feature promote moves a repo from the default branch to the feature worktree mid-session: the symlink decides which branch's file is read.

How the guard ties a call to the session depends on where the agent runs. An agent attached with session connect keeps the hall root as its working directory, so the guard finds the session from the target of a write: an Edit or Write with an absolute path inside the view dir. A read from the hall root carries nothing. A harness that ivar launches inside the view dir has the session as its working directory, and every allowed call there, reads included, can carry instructions.

Run the same check in the session. Ask for the canary before the agent has edited anything under web/, and the hook has had nothing to deliver yet; the agent has the pointer list, which tells it to read the file. Ask it to make an edit under <view>/web/ first, and the token is in the context that came back with that call. A nested web/src/CLAUDE.md arrives the first time such a call touches web/src/.

| instruction file | --add-dir | --add-dir + variable | attached ivar session | |---|---|---|---| | web/CLAUDE.md | not loaded | loaded at launch | delivered on the first write under web/ | | web/src/CLAUDE.md | not loaded | check with a canary | delivered on the first write under web/src/ | | web/.claude/rules/*.md | not loaded | reported missing | not delivered | | web/AGENTS.md , noCLAUDE.md | not loaded | not loaded | delivered in its place |

ivar guard delivers CLAUDE.md and AGENTS.md only. CLAUDE.local.md in a linked repo are not sent.$ or a backtick is skipped, so a path the shell builds at run time delivers nothing.ivar session start launches. An agent attached with session connect has the tool guard alone: Edit and Write outside the session's writable set are denied, shell writes are not (/compact and /clear. HALL.md, or a repo gaining its first root instruction file, reaches the session's ivar session connect. Edits to a repo's own file need nothing: the next call sends it marked UPDATED.

curl -fsSL 'https://ivar.run/install?ref=claude-md-multiple-repos' | sh

The quickstart sets up the hall once; from there, ask the agent for the change. Sessions covers the view dir, and Limitations lists what the guard can and cannot see.

原文来源:dev.to