Topic 4 of 5 · 5 min read
Testing whether a memory file changes behaviour
Goal: Design a before-and-after check that shows whether a memory file changed an agent's behaviour, and fix a rule the agent ignored.
Treat a memory file like code: write a rule, run a small task that should trigger it, and compare the agent's behaviour with and without the rule. A rule that reads well but changes nothing is a line you are paying context for.
Check yourself · 1 of 3
What is the best first step to test whether a new rule changes an agent's behaviour?
Why it matters
Models can drop instructions, misread them or follow them only sometimes, and they sound equally sure in all three cases. Reading your own file back tells you nothing, because you already know what you meant. The Claude Code docs list "Claude isn't following my CLAUDE.md" as a common problem and suggest checking that the file is loaded and that the wording is specific and not in conflict with other instructions.
A simple test loop
- Pick one rule and a task that would break it. Rule: "Money is integer cents." Task: "Add a 10% discount function."
- Run it without the rule. Start a fresh session with the line removed or with the file off. Save the result. This is your baseline. If the agent already does the right thing, the rule is not earning its place.
- Run it with the rule. Same task, new session, same model. Compare. Does the output now follow the rule?
- Repeat two or three times. One run can be luck either way.
- Ask for a restatement. In a new session, ask: "Which rules from the project instructions apply to this task?" If the agent leaves out a rule, it was not loaded or was lost in a long file. If it states it wrongly, the wording is ambiguous.
- Check what loaded. Most tools have a command to show loaded instructions. In Claude Code,
/memorylists the memory files. A rule in a file that did not load cannot work.
Before and after
A rule that failed the test:
- Try to keep functions small and avoid unnecessary duplication where possible.
The agent still wrote a 90-line function. The rule is vague and has no pass or fail. Rewrite it so it can be checked:
- Functions over 40 lines must be split. Before finishing, list any function you wrote over 40 lines.
Now a reviewer can see in one run whether it was followed. If it still fails, move the rule higher in the file, shorten the file, or turn it into a check a tool runs, such as a lint rule or a pre-commit hook.
What goes wrong
- Judging from one run. Agents vary; a single pass proves little.
- Testing in a session that already knows the rule. An earlier chat message can make the file look effective when it is not.
- Fixing by adding more words. A longer file often lowers adherence. Shorten and sharpen first.
- Using memory for what must never fail. If breaking a rule is costly, enforce it with a hook, a permission rule or CI, not a sentence.
Examples
A baseline that shows the rule is unnecessary
You add "Use async/await, not callbacks." On the baseline run without it, the agent already writes async/await because the codebase does. The rule changes nothing. Delete it and save the context.
A rule that is loaded but misread
The file says "Do not touch migrations." Asked to restate, the agent says "I should not create new migrations." Your meaning was "do not edit existing ones". Reword: "Never edit an existing file in db/migrations/. Add a new one."
Key points
- Test each rule with a task that would break it, run with and without the rule in fresh sessions.
- Repeat the run two or three times, because one result can be luck in either direction.
- Ask the agent to restate which rules apply; a missing or wrong rule shows a loading or wording problem.
- Rewrite vague rules so they have a clear pass or fail, and shorten the file before adding more words.
- Enforce rules that must never fail with a hook, permission rule or CI check, not with prose alone.
Common mistakes
- Concluding a rule works after one successful run.
- Testing in a long session where the rule was already mentioned in chat.
- Responding to a missed rule by adding capital letters and more rules.
- Never checking which memory files the tool actually loaded.
Check yourself · 2 of 3
In a new session you ask the agent which project rules apply, and it omits an important one. What does this most likely show?
Check yourself · 3 of 3
A rule says 'try to keep functions small'. The agent writes a 90-line function. What is the best rewrite?
Practice items, not counted towards your mastery.
Start here
- AGENTS.md (opens in a new tab)DocsFree
The open format for a plain-markdown instruction file that many coding agents read, with examples.
- How Claude remembers your project (Claude Code docs) (opens in a new tab)DocsFree
Where CLAUDE.md files load from, the under-200-lines target, imports, rules and troubleshooting.
- Custom instructions with AGENTS.md (OpenAI Codex docs) (opens in a new tab)DocsFree
How Codex finds and layers AGENTS.md files from the global folder down to the working directory.