Did it read the file? Plant a sentinel and find out

If you write instruction files for AI agents, like AGENTS.md or CLAUDE.md, you can't ask the agent whether it read them and trust the answer. You can plant a made-up word in the file and see if it comes back. That's a sentinel, and it's how I found out which of my instruction files actually load, in Claude Code and in GitHub's Copilot code review.

The setup

At work we split one big AGENTS.md at the root of a large repo into smaller ones, one per folder, next to the code each one describes. The idea is that an agent working in a folder picks up that folder's notes and doesn't have to load everything.

That only helps if the nested files actually load. So I needed a yes or a no.

Testing Claude Code

I put a unique token in three files:

  • the root AGENTS.md: something like ROOT-KESTREL-4471
  • a nested AGENTS.md in a folder I'd read from
  • a nested one in a folder I would not touch, as a control

A control is the "this should never show up" case. If its token appears, the test is broken.

Then I started a fresh headless session (claude -p, which runs one prompt and exits) with a prompt like this:

Use the Read tool exactly once, on some/folder/file.py. Do not read any other file. Then reply only with every token matching WORD-WORD-DIGITS in your context, one per line, or NONE.

The results:

  • The root token showed up even in a session with no tools at all, so it couldn't have opened the file itself.
  • The nested token showed up only after it read a file in that folder.
  • The control token never showed up.

Two things I learned on the way. First, I ran it again with all my hooks turned off, because the nested file came in looking like a hook had attached it. It still loaded, so Claude Code does this by itself. Second, a CLAUDE.md sitting next to an AGENTS.md hides the AGENTS.md. We had 28 little CLAUDE.md pointer files "to be safe", and they were making things worse. They're gone now.

Also: once, the model answered NONE when a token should have been there. The fix was to check the session transcript directly instead of trusting the answer. The model can be wrong about its own context.

Testing Copilot code review

Copilot reviews our pull requests, and I wanted the per-folder notes to reach it too. This one is harder, because you can't run a local session. So I made throwaway pull requests.

Round one was tripwires: code that breaks rules that only exist in our instruction files. Copilot caught six of seven, quoting the root file by line number. The one it missed was the rule in a nested file. But a miss is ambiguous. Maybe it read the file and didn't care.

Round two used a sentinel. The nested AGENTS.md got a line telling the reviewer to start its comment with a unique token. Same for the root file, as the positive control.

There's a trap here. Copilot reads the diff. If the sentinel line is in the diff, a token in the review only proves it read the patch. So the sentinels went into the base branch of the test pull request, and the code change went on top. That way the token is in the files but never in the diff.

Result: the root token came back. The nested ones didn't. Copilot code review does not load nested AGENTS.md files. What it does load reliably is .github/instructions/*.instructions.md with an applyTo: pattern. It cited one of those by path and line number. So anything a reviewer needs to know goes there now.

One mistake of mine: I kept the test details out of the pull request description and then put "nested instruction loading" in the title. Copilot repeated it back. That could only push toward a false yes, and it still said no, so the result held. Next time I'd use a boring title.

Why I like this trick

It turns "I think it loads" into a fact. The token can only show up if the file was in context, so you don't have to argue about it.

If you try it, a few rules:

  • Always have a control that should never appear.
  • Use a fresh session for every run.
  • Keep sentinels off your main branch. They're instructions sitting in files everyone reads.
  • Check the transcript, not just what the model says.

I have now spent more time making up fake bird-and-number codes than I'd like to admit. Kestrels were involved.

Drafted with an assistant, edited by @wintaru

0 comments