Rules for the Tests Folder Only
Why This Matters
Testing conventions matter when Claude Code edits a test, and are noise when it edits a prompt. Path-scoped rules load only when the agent works with matching files, so each rule is there when it is relevant and costs nothing otherwise.
Rules in .claude/rules/
Every Markdown file in .claude/rules/ is a rule. Without frontmatter, a rule loads in every session, just like CLAUDE.md. With a paths field in the frontmatter, it loads only when Claude works with files matching those patterns.
---
paths:
- "tests/**/*.ts"
---
# Testing rules for TestPilot
- Use the fake client (`fakeClient`, `scriptedClient`). Tests never call the real API.
- One behaviour per test; the test name says the behaviour.
- For agent loops, assert on the requests your code sends, not only on the final result.
- A new fixture gets a short comment saying what it represents.
Quote glob patterns, and keep them narrow: tests/**/*.ts, not **/*.
A rule for the golden set
---
paths:
- "fixtures/golden/**"
---
# Golden set rules
- Never change an existing label without a reason in the commit message.
- New cases: add the fixture, the label and a one-line "why".
- After any change, run `npm run eval` and include the scorecard diff in the pull request.
Check what is loaded
In a real session you can see the moment it happens. Asked to add a test to tests/runs.test.ts, Claude Code makes the edit, and only then reports Loaded .claude/rules/tests.md: the rule costs nothing until Claude touches a matching file. The new test follows it, too: one behaviour, and a name that says what and why.
/memory lists the memory files you can open and edit. To see what is actually loaded in the current session, use /context, or watch for the line Loaded .claude/rules/tests.md when Claude touches a matching file, as in the session below.
When a path rule is the wrong tool
| Need | Better tool |
|---|---|
| A step-by-step procedure (“add a golden case”) | A skill (lesson 45) |
| Something that must never happen | A permission or hook (lesson 46) |
| A rule for the whole project | CLAUDE.md |
Exercise
Add the two rules above to TestPilot. Ask Claude Code to add a test for failureRate with an empty history and check that the testing rule was loaded (the Loaded … line, or /context).
Compare with solution/lesson-52-claude-code, which has the Claude Code setup for lessons 42–52. Its docs/claude-code-demo.md walks you through all of module 6 in one session.
