CLAUDE.md Rules for Claude Code That You Can Check
Write a short CLAUDE.md with observable project rules, safe boundaries, and commands you can run to verify each change.
A long list of preferences does not make Claude Code predictable. A useful project rule says what the agent may do, what it must avoid, and which command or diff proves the result. Put architecture notes in docs/; keep the project contract short.
Start with a small contract
Goal
- Keep changes limited to the requested feature.
Before editing
- Read package.json and the files named in the task.
- Do not read or print .env files.
Checks
- Run
npm testafter code changes. - Run
npm run lintwhen TypeScript files change. - Report each command, its exit code, and every changed file path.
Scope and conflicts
- Rules in
packages/payments/CLAUDE.mdapply only underpackages/payments/. - Inside that directory, the local rule wins when it directly conflicts with this root file.
- Root security and secret-handling rules always apply.
Forbidden
- Do not run deploy, publish, or destructive Git commands.
Separate goals, boundaries, checks, and style
Use a goal for the requested outcome, a boundary for files or commands that are off limits, a check for a reproducible command, and a style rule only when it affects review. If a command is not present in package.json, do not invent it. Move long explanations and exception lists to documentation with a link from CLAUDE.md.
Keep secrets out
CLAUDE.md is part of the repository and is read with the project. Never put API keys, CI tokens, real personal data, or copied API responses in it. State the boundary instead:
Pass a real key through an environment or secret store when a test needs one. Do not paste it into a prompt or handoff.
Resolve scope and conflicts
Keep repository-wide rules in the root file and package-specific rules close to the package. When two files disagree, inspect the instructions visible to the target file, remove the duplicate, and keep the narrower rule local. Do not add another paragraph to hide a conflict.
Test one rule on a reversible task
Test one rule with a reversible task:
- Ask Claude Code to rename one local variable in a test file.
- Run
git diff --checkand inspectgit diff --stat. - Execute the test command from
CLAUDE.md. - Reject the result if another file changed or the command was not run. This isolates the rule from a large project plan.
Connect the API workflow without mixing secrets
For Claude Code API work, use your own key and check the current Base URL and model in BetterToken’s Claude Code documentation. BetterToken provides API access and usage data; it does not turn CLAUDE.md into a secret store or replace Claude Code settings.