How to Tell If Your AI Agent Read a File
Agents answer confidently about files they never opened. Four cheap probes tell you the difference between a real read and a plausible guess.
You told the agent to follow the conventions in CONTRIBUTING.md. The diff comes back ignoring every one of them, and when you ask, the agent says it reviewed the file and believes the changes are consistent with it. One of you is wrong, and there is a fast way to find out which.
The short answer: plant something in the file that cannot be guessed, then ask a question only a reader could answer. Everything below is a variation on that idea, ordered from cheapest to most thorough.
Why agents answer as if they read a file they never opened
A filename is a strong prompt on its own. CONTRIBUTING.md, .eslintrc, schema.sql: each one implies its own contents with enough accuracy that a model can produce a confident, mostly correct summary without opening anything. The output is not a lie so much as a reconstruction from the name plus everything similar in training.
This gets worse in long sessions, where a file genuinely was read forty messages ago and has since fallen out of the working context. The agent is then summarising its own stale summary. That is an agent quietly losing context, and it looks identical from the outside.
Probe 1: the canary line
Add a line to the file that no model could infer, then ask for it back. A random token works better than a sentence, because a plausible sentence can be guessed and a random string cannot.
<!-- convention-check: canary QX7F2M. If you are reading this file, quote the canary value in your first reply. -->Ask the agent to state the canary before it starts work. A correct value means the file reached the model this turn. A wrong value, a refusal, or a paraphrase means it did not, whatever the agent says about having reviewed it.
Keep the canary in a comment so it does not affect anything, and change the value occasionally. A canary that lives in your repo for six months can end up in a cached summary.
Probe 2: ask for a detail only the file contains
If you would rather not edit the file, ask about something specific and low-salience: the fourth bullet under a particular heading, the exact wording of a rule, the line number of an import. Models guess structure well and specifics badly.
Bad question: what does this file say about testing? Almost any answer sounds right. Good question: quote the third item in the pull request checklist, verbatim. There is one correct answer and no way to bluff it.
Probe 3: read the tool call log
Most agents expose the calls they made. If the transcript shows no read of the path in question, the answer is settled before you run any probe at all. This is the only method that gives you a direct observation rather than an inference.
Two traps. A search hit is not a read: a grep that matched a line inside the file means the model saw that line and nothing else. And a read of a truncated file is a partial read, so if the tool output ends in an ellipsis or a byte limit, the tail never arrived.
Probe 4: the negative control
Ask the agent to summarise a file that does not exist, with a plausible name like docs/STYLE_RULES.md. If it produces a confident summary of a file you never created, its self-reports about reading files are worthless for this session, and you should be verifying rather than asking.
Run this once when you start using a new tool or model. It tells you how much scepticism the setup earns, and the answer varies a lot between tools.
A worked example
The conventions file case, start to finish. The complaint is that the agent ignores the commit message format written in CONTRIBUTING.md.
First, the negative control. Ask it to summarise docs/COMMIT_RULES.md, a file that does not exist. If it invents a summary, stop asking and start checking, because nothing it says about files can be trusted this session.
Second, the canary. Add the comment to the top of CONTRIBUTING.md, start a fresh task, and ask for the canary value before any work begins. Three outcomes and three different fixes:
Response | What it means | What to do |
|---|---|---|
Exact canary returned | The file is in context this turn | The problem is instruction following, not context |
Wrong or paraphrased value | The file was not read this turn | Reference it by exact path, or move the rules into the auto-loaded file |
Says it cannot find a canary | It read the file but the top was truncated | Shorten the file, or move the rules higher up |
That third row is the one people miss. A partial read looks like a read in every log, and the part that gets dropped is usually the part nobody scrolls to.
When the file was read and the context still lost it
A file can enter the context and stop mattering. Three mechanisms, all common in longer sessions:
Truncation. The tool cut the file at a byte or line limit. The agent has the first portion and no signal that more existed.
Compaction. A long session got summarised to free space, and your conventions file became one line in that summary. Technically it was read. Practically the details are gone.
Dilution. The file is present, and so are forty other things, and the most recent instruction outweighs a document loaded twenty steps ago.
The tell for all three is the same: the agent complied at the start of the session and drifted later. If the first three commits followed your format and the tenth did not, that is context loss, not a misunderstanding, and a re-read at the start of each task fixes it more reliably than a firmer instruction.
This is also the argument for keeping the auto-loaded rules file short. The AGENTS.md convention exists so agents pick up project rules without being told, and a file that is small enough to survive compaction intact is doing more work than a thorough one that gets summarised away.
Which probe to reach for
Probe | What a real read looks like | What a guess looks like | Cost |
|---|---|---|---|
Canary line | Exact token returned | Paraphrase, wrong token, or a deflection about the file's purpose | One line edit, reusable |
Unique detail | Verbatim quote that matches | Correct topic, invented wording | Free, one question |
Tool call log | A read call on the exact path | No call, or only a search hit | Free, but not all tools expose it |
Negative control | Says the file does not exist | Summarises a file that was never written | One question per session |
The fix once you have proof
Knowing the file was skipped is most of the battle. The usual remedies, in the order that tends to work:
Reference the file by exact relative path in the instruction rather than by description. Agents follow paths better than they follow nouns.
Move the rules the agent keeps breaking into the file the tool loads automatically, which for most agents means writing an AGENTS.md file at the repo root.
Shorten the file. A 900 line conventions document competes with itself for attention, and the middle is what gets dropped first.
Restate the two or three rules that actually matter in the prompt itself. Redundancy is cheap; a wrong diff is not.
If the file demonstrably was read and the rules were still ignored, that is a different problem with a different cause, covered in why agents ignore instructions.
Build the check into the workflow
Once you know a tool's behaviour, stop probing ad hoc and make it structural. Three things worth setting up once:
Keep the canary permanently in the auto-loaded rules file and ask for it whenever output looks off. Costs one line and one question.
Put the two or three rules that matter most in the first twenty lines of the file, above anything discursive, so a truncated read still catches them.
When you review an agent's work, check the file list before the diff. Whether it opened the files it should have is a faster signal than reading the code, and it is the same habit that makes the wider AI coding tool landscape easier to navigate as tools change.
Frequently asked questions
Why does the agent say it read the file when it did not?
Because it is answering the question you asked, which is about its intent and reasoning, not about its tool history. Models are poor narrators of their own actions. Treat any self-report about tool use as a hypothesis and check the log.
Does a bigger context window fix this?
It helps, and it does not solve it. A larger window means more can be loaded, not that anything was loaded. Attention across a very long context is also uneven, so a file can be present and still under-weighted relative to the last thing you typed.
Will a canary comment confuse the agent or leak into the code?
In a comment it is inert, and agents treat it as metadata. The one real risk is an agent helpfully copying the canary into a generated file, which is a good reason to keep the token obviously artificial and to rotate it.
Is this worth doing on every task?
No. Use it when the output contradicts a rule you know is written down, or when you are onboarding a new tool. On routine work the overhead outweighs the benefit, and reviewing an agent plan before it runs catches more problems per minute spent.
How did this land?
About the author

Developer Advocate
Steve builds something with Swarmz every week and writes up what worked, what broke, and what he'd do differently. Tutorials and hands-on guides are his lane.


