Shattered Vales Studio Inc.

Writing Effective CLAUDE.md & Agent Rules

CLAUDE.md is the briefing an AI coding agent reads at the start of every session in a repository: the commands, conventions, and constraints a new team member would need. A good one makes every agent session faster and more consistent; a bloated or vague one is ignored or misread. This guide is mainly for leads and maintainers who own a repository's rules.

Step 1: Know How the Files Are Loaded

LocationWhen it's readUse it for
CLAUDE.md at the repository rootAt the start of every session in the repository.Team rules for the whole project. Committed.
CLAUDE.md in a subfolderWhen the agent works with files in that folder.Rules for one area, for example src/Billing/CLAUDE.md.
~/.claude/CLAUDE.mdEvery session, in every project.Personal preferences. Never team rules.

A CLAUDE.md can pull in other files with an @ reference on its own line, such as @ARCHITECTURE.md. Use this to reuse existing documents instead of copying them. If other AI tools in the team read AGENTS.md, keep the shared rules there and import it with @AGENTS.md.

Step 2: Put Each Rule in the Right Place

Belongs inContent
CLAUDE.mdHow to work here: build, test, and lint commands; branch and PR workflow; coding conventions that differ from the defaults; hard constraints; known gotchas.
ARCHITECTURE.mdHow the system is designed: scope, components, invariants. Imported or referenced from CLAUDE.md.
The issueWhat to do this time: goal, context, acceptance criteria. See Writing Issues for Agentic AI.
.claude/settings.jsonWhat the agent is allowed to do: permission rules (Step 5).
NowhereSecrets, credentials, customer data, or internal URLs that grant access. CLAUDE.md is committed and sent to the model.

Step 3: Write Rules an Agent Will Follow

  1. Be short. The whole file is loaded into every session and competes with the task for attention. Aim for a screen or two. If it grows past that, move area-specific rules into subfolder files.
  2. Be specific and checkable. "Run dotnet test before every commit" can be followed; "make sure the code is good" can't.
  3. Give exact commands, copy-pasteable, with any required flags.
  4. Explain non-obvious rules in a few words. "Never call GetComponent in Update() (causes GC stutter on Switch)" is followed more reliably than a bare rule, and lets the agent apply the reason to similar cases.
  5. Save emphasis for what matters. Marking one or two rules IMPORTANT or MUST works; marking everything does nothing.
  6. Write what to do, not only what to avoid. Pair each "never" with the right alternative.
  7. Don't duplicate. Link to ARCHITECTURE.md or the README rather than restating them; duplicated rules drift apart.

Vague:

- Write clean code and follow best practices.
- Be careful with the database.
- Test your changes.

Actionable:

- Every repository method takes a TenantId and filters by it. Never
  query a tenant-owned table without it (cross-tenant data leak).
- Schema changes need an EF Core migration: `dotnet ef migrations add <Name>`.
  Never edit an existing migration.
- Before committing, run `dotnet build` and `dotnet test`; both must pass.

Step 4: Start from a Template

Every studio CLAUDE.md shares the same workflow core (shown in Claude Code & GitHub CLI Setup, Step 6), plus a section specific to the repository type. Run /init for a first draft, then edit it against these examples:

Unity game:

## Unity project rules
- Unity version: 6000.0.23f1. Do not upgrade packages or the editor.
- Never edit .unity, .prefab, or .asset files by hand; describe the
  needed editor change in the PR instead.
- Always create or move assets together with their .meta files.
- No allocations in Update/FixedUpdate: cache components in Awake,
  no LINQ or string concatenation in per-frame code.
- Gameplay code lives in Assets/_Project/Scripts/<System>/. Each system
  has an assembly definition; keep references one-directional.
- Tests: Unity Test Framework, EditMode tests in Assets/_Project/Tests/.

Multi-tenant SaaS service:

## Service rules
- Build: `dotnet build` · Test: `dotnet test` · Format: `dotnet format`
- IMPORTANT: every query on tenant-owned data filters by TenantId via
  the repository layer. Never query DbContext directly from controllers.
- Business rules live in src/Domain; controllers only map HTTP to
  application services.
- Schema changes: add an EF Core migration; never edit existing ones.
- Never log request bodies, emails, or payment details.
- Use the test data builders in tests/Builders; never real customer data.

Static website:

## Site rules
- Read ARCHITECTURE.md before changing structure or styles.
- Pure static HTML/CSS/JS: no build tools, frameworks, or npm packages.
- No inline styles or <style> blocks; all CSS in /assets/css using the
  variables in variables.css.
- Pages must work opened directly from file:// (relative paths only).
- Add every new indexable page to sitemap.xml.

Step 5: Back Rules with Permissions and Enforcement

CLAUDE.md is guidance: the agent follows it almost always, but not with certainty. Anything that must never happen needs a hard control as well:

LayerStrengthExample
CLAUDE.mdGuidance"Branch from Dev; open PRs against Dev."
Permission rules in .claude/settings.jsonEnforced by Claude Codedeny reading .env files; ask before git push.
Hooks in .claude/settings.jsonEnforced by your own scriptsRun the formatter after every edit, or block a command that matches a pattern.
GitHub branch protectionEnforced by GitHubNo direct pushes to Dev, QA, or main; required reviews and checks.

A permission example is in Claude Code & GitHub CLI Setup. Branch protection is the guardrail that holds even if every other layer fails; see Repository Standards.

Step 6: Maintain the Rules Like Code