By Abhijith N M · Reviewed 24 October 2026 · Editorial standards
Your monorepo has two halves. api/ is Python and runs pytest. web/ is TypeScript and runs npm test. A year ago someone added one line to the root CLAUDE.md: always run the test suite with pytest before you finish.
That line was true for the person who wrote it. Now every front-end change ends with Claude Code trying to run pytest inside web/, hitting a missing module, and writing an apology into its summary. Nothing is broken. The instruction sits at the wrong scope.
A CLAUDE.md file is a plain markdown file of standing instructions that Claude Code reads at the start of a session. It is not a prompt you type. It is context you keep.
Hold your answer for one section. The rule is not that the newest instruction wins. Every applicable file loads at once, so both lines reach the model, and the instruction closer to the file you are editing is the one it should follow. A conflict still costs you: it spends attention and makes the result unreliable. Delete the losing line instead of trusting a rank order.
A directory file does not replace the project file. It adds to it. That is why the placement of a line matters more than its wording: the same sentence can be helpful in one folder and noise in another.
| Level | Path | In git | Best for |
|---|---|---|---|
| User | ~/.claude/CLAUDE.md | No | Your own defaults: tone, editor commands, review habits |
| Project | ./CLAUDE.md | Yes | Build, test and lint commands, the repo map, review rules |
| Directory | any subdirectory/CLAUDE.md | Yes | Conventions that are true only in that subtree |
The test is one sentence: store a rule at the narrowest scope where it stays true. A habit that suits every repository belongs in the user file. A command that works for one repository belongs in the project file. A convention that holds in one folder belongs in that folder's file.
ruff check before you report done" can.Good instructions share three properties. They fit in one pass of the eye. They start with a verb the model can act on. And a reviewer can tell afterwards whether the instruction was followed.
# Project notes
We use pytest for the backend, and the frontend uses npm, and someone
should probably check the fixtures. Generally try to be careful with
the database and use good naming. Also remember the deploy process,
which is described somewhere on the wiki.# api/CLAUDE.md
## Tests
- Run `pytest -q` from `api/` before you report a change as done.
- A test file sits beside the module it tests: `test_<module>.py`.
- Do not mock the repository layer. Use the fixtures in `tests/conftest.py`.
## Style
- A public function gets a one-line docstring in the imperative mood.
- Raise `ValueError` for bad input that arrives from outside the service.
## Reference
@docs/testing.mdThe second file is not much shorter. Every line earns its place, because each one changes what the model does and leaves evidence that it did it.
The @path syntax imports another file into the same context. Imports are how you keep the root file to a page. Put the testing guide in docs/testing.md and import it from the project file. Two services can then share one copy.
Two cautions. An import that points at a missing file adds nothing and raises nothing, so check the paths when you move files. And an import is still context: three imported files of 200 lines cost the same as one file of 600 lines.
Open the CLAUDE.md of a repository you work in, or create one at its root. You need about ten minutes and no API key.
CLAUDE.md.Definition of done: every instruction sits at the narrowest scope where it is true, and no file is longer than about one screen.
Key takeaways
User, project and directory files all load together; none replaces another.
When instructions conflict, the closer scope should win, but you should remove the conflict.
Store a rule at the narrowest scope where it stays true.
Short, imperative and verifiable beats thorough and vague.
Imports (@path) keep the root file small and share guides across services.
Written and edited by the nexGenCoders team. Spotted a mistake? Tell us and we will fix it.
Don't lose this lesson
Create a free account to save your progress, keep your streak, and work toward a shareable certificate.