#4838 taught `bd setup claude` to detect a CLAUDE.md that is a thin stub
importing AGENTS.md, and to write the managed beads block to AGENTS.md instead.
isAgentsImportStub decides that by scanning for "@AGENTS.md" on its own line,
with no notion of code blocks — so a CLAUDE.md that merely *documents* the
pattern in a fenced example is classified as a stub.
That is not a cosmetic misread. Once the redirect activates, stripStaleClaudeBlock
removes the managed block from CLAUDE.md, on the reasoning that AGENTS.md now
owns it. For a file that was in fact authoritative, a documentation example
silently moves the block out of it. The new end-to-end test is the one that
matters here: against the parent commit it fails with
CLAUDE.md is authoritative and must carry the beads block;
a fenced example redirected it away
Skipping fenced regions also matches the semantics being detected: Claude Code
does not expand an @-import shown as code, so a fenced directive was never going
to make the file a stub in the first place.
Deliberately narrow in two places, both pinned by tests:
- Four-space-indented lines are still scanned. Indentation is ambiguous in a way
a fence is not — it is equally a list continuation, which is a plausible home
for a real directive — so treating it as code would trade this false positive
for a false negative. "indented directive still counts" pins that.
- A closing fence must match the character that opened the block, so ``` inside a
~~~ block does not terminate it and let a following directive leak through.
An unterminated fence swallows the rest of the file, which is also what a
Markdown renderer does, so the conservative answer there is the correct one
rather than an accident. Both are pinned.
Five of the seven new unit cases fail against the parent commit; the two that
pass in both directions are the over-correction guards ("real directive after a
fenced example still counts", "indented directive still counts") and exist so a
future fix cannot go too far the other way.
This closes the last of the two nits left open on #4838's review; the other
(path-qualified "@./AGENTS.md") was already handled before that PR merged.
Note for whoever looks at CI: `main` is currently red on Test (macos-latest) for
three unrelated failures — see #5210 and #5220. This branch touches only
cmd/bd/setup and does not go near them.
Agent-Signature: claude-opus-5-high on behalf of maphew