r/ClaudeCode • • 8h ago

Tips & Workflows Our first Claude Code A/B test was worthless because Claude read files outside the test folder

We were comparing two memory setups in Claude Code, same questions, one folder per side. The first run looked good. Then we checked which files it actually read. In both arms Claude had left its test folder and read notes from the real project, so neither side was what we said it was. We threw the result out and kept it on record (disclosure, minniai.com/evidence is our site).

If you're testing a CLAUDE.md, rules or skills setup against another one, a few things we'd check now.

- Block reads outside the folder with a PreToolUse hook. Match Read, Grep, Glob and Bash, check the path, and refuse anything outside the test folder. Exit code 2 blocks the call and tells Claude why.

- Bash is the hard one, since a path can hide anywhere in a command. Leave it out of the test if the task doesn't need it.

- Put the absolute path of the test folder in the prompt, so Claude doesn't go looking.

- Watch what loads before the first message. Claude Code also loads CLAUDE.md files from the folders above where you start it, and your own ~/.claude/CLAUDE.md, so both arms can share memory you didn't mean to test.

- Log every path it read and count the ones outside the folder. One escaped read and the run doesn't count.

Has anyone else caught Claude reading somewhere it shouldn't during a test?

0 Upvotes

7 comments sorted by

•

u/AutoModerator 8h ago

Hey! Thanks for posting to r/ClaudeCode

While participating in this thread, please follow our community rules. Keep discussions constructive. Attack the idea, not the person.

For help, project discussions, tips, and general chat, join the ClaudeCode Discord.

I am a bot, and this action was performed automatically. Please contact the moderators of this subreddit if you have any questions or concerns.

1

u/Starks1293 8h ago

good list. two ways the PreToolUse path check itself gets bypassed, both of which i hit building a write guard for a mac app

compare real paths, not the string. a symlink inside the test folder pointing out (notes -> ../../real-project/notes) passes a "does the path start with the test folder" check, because the string does. resolve with realpath before comparing, and for a file that doesnt exist yet resolve its parent

on a mac the disk is case insensitive and realpath doesnt fix the case. /Users/me/Test and /users/me/test are the same folder but a plain string compare says no, and the other way round a path u meant to block can slip past in different case. lowercase both sides before the compare on macOS

and for the memory leaking in from above, the cleanest fix i found is to start each arm from a fresh temp folder outside ur home tree with only the files under test copied in. then theres no parent CLAUDE.md to pick up, and u can diff the two folders to prove the arms only differ where u meant them to

1

u/MinniLabs 8h ago

both great catches, especially the symlink one, a "starts with" check looks fine until something inside the folder points out. windows has the same case problem, plus forward and back slashes, so we normalize both before comparing. and diffing the two arms after copying them to a fresh temp folder is a nice touch, stealing that. the thing we test with this setup is MinniMemoryMCP, it's ours, the latest run is on minniai.com/evidence if you want to see what came out of it

1

u/ainexfinder 7h ago

That's a common trap, since the agent treats anything it can reach as context, so one arm can pick up notes or memory files meant for the other. Running each arm in its own fresh checkout or container with only the files it should see, and logging which files each session actually opened, makes contamination easy to spot before comparing results. Also worth running the same fixed prompt set a few times per arm, because one run each is mostly noise.

1

u/tristan_laroubine 4h ago

One more leak a path check won't catch: MCP servers from your user config load in both arms. For a memory comparison that matters twice, since a memory server you use day to day could answer in both, and every server's tool definitions get sent with each request, which skews the cost numbers. In my own benchmark runs each agent gets --strict-mcp-config with only the servers under test, and the run log records which ones actually loaded.

1

u/AryanThakor 3m ago

one more leak: ~/.claude/CLAUDE.md and any user level skills load in both arms too. i'd run each arm with its own CLAUDE_CONFIG_DIR so the only difference is the thing you're actually testing