Skip to content
zeeshare.com

writing / FDE and agents

Spec-driven development, for real

Spec-driven development, for realPart 3

Principles and scoped rules

On this page
  1. Monday, 10:15
  2. Rules, from broad to specific
  3. The principles
  4. What Claude has read when it edits
  5. Giving a principle teeth
  6. What belongs in the root file
  7. Which one fits?
  8. In the kit
  9. Three rules of thumb

New to the short codes like REQ, ADR or AC? See the vocabulary in Part 1, or hover over any code.

In short: A small set of numbered principles (P1 to P12) binds the code; breaking one needs a decision record, not a judgement call in a pull request. A short root CLAUDE.md holds what every session needs: commands, working rules and what “done” means. Each module has its own CLAUDE.md with the rules true only there, which Claude reads when it works in that folder. And every rule gets teeth: a test, a hook or a reviewer that notices when it breaks.

Part 2 gave every requirement and decision an ID. This part covers block 2, the rules Claude follows while it builds. The team and product are invented.

Principles Root CLAUDE.md Module CLAUDE.md Checks Claude

Monday, 10:15

Maya has found REQ-041. Before she asks Claude for a plan, she opens the folder the fee will live in: src/billing/. There is a CLAUDE.md in it, eighteen lines long. One line says money is always integer minor units. Another says an open question, OQ-07, decides which ledger account fees post to, and that nobody may guess it.

She realises Claude will read that file too, the moment it opens anything in billing/. The rule will be on its desk before it writes a single line.

Think of it like this: A country has a constitution: a few rules that hold everywhere and change only with a formal process. Each department pins its own rules on the wall of its room: the lab has goggles, the kitchen has allergens. Nobody carries every department’s rules in their head. They read the wall of the room they walk into.

Rules, from broad to specific

principles.mdbinding, numbered, rarely changed P1 config P2 ports P3 access P11 money CLAUDE.md (root)repo-wide, loaded at every start commands plan first done means src/billing/CLAUDE.mdloaded when Claude works there minor units OQ-07 fee formula .claude/rules/*.mdwith paths: only for matching files src/**/serializers*.py
Broad rules at the top, specific ones at the bottom. Each level only says what is true at that level.

The principles

Principles are the constitution. They are few, numbered and binding. Each one is written so a reviewer could tell from the code whether it was broken.

P1 Configuration over customisation

Company-specific behaviour is data. Checked by: review; no if company ==.

P2 Vendors behind ports

Domain code never imports a provider SDK. Checked by: an edit warning on vendor imports.

P3 The server owns access

A hidden field is absent from the response. Checked by: field-security tests.

P5 Rules hold in any order

Invariants do not depend on step order. Checked by: tests with reordered steps.

P8 Contracts are generated

Types come from OpenAPI. Checked by: the CI drift gate.

P11 Money is exact

Integer minor units end to end. Checked by: types and tests.

Rule: going against a principle needs an ADR (Part 4). Not a comment, not “just this once” in a pull request. That sounds heavy. In practice it means exceptions are rare, deliberate, and findable.

What Claude has read when it edits

Session starts root CLAUDE.md principles cited commands known Claude opens src/billing/fees.py billing/CLAUDE.md loads minor units, OQ-07 edit follows both
The root file is on the desk from the start. A module file joins it the moment Claude works in that folder.

Claude Code loads the root CLAUDE.md at the start of every session. A CLAUDE.md in a subfolder loads when Claude reads files in that folder, so the billing rules arrive exactly when they are needed and cost nothing the rest of the time.

Here is the one Maya found:

src/billing/CLAUDE.md
# billing: rules for this module

## What this module owns
Charges, refunds and fees for a rental. Emits ChargeCreated.

## Rules here
- Money is integer minor units. Never a float, never a Decimal
  on the wire (P11).
- Late fees are computed only by terms.late_fee_minor
  (DEF-late-fee). Never inline the formula.
- OQ-07 is open: which ledger account late fees post to.
  accounts.late_fee_account returns None until finance answers.
  Do not pick a default.

## Tests that must exist
- Isolation: company A cannot read company B's charges.
- Field security: a customer's response has no cost_minor.

## Handoff
docs/modules/billing.md
Short, specific to this folder, and enough on its own. It names the open question so Claude cannot "helpfully" answer it.
Under the hood: how Claude Code loads these files
  • At launch, Claude Code walks up from the working folder and loads every CLAUDE.md it finds, plus ~/.claude/CLAUDE.md for personal rules.
  • A CLAUDE.md in a subfolder loads on demand, when Claude reads a file in that folder.
  • Rules in .claude/rules/*.md with a paths list load only when Claude reads a matching file; without paths they load at the start.
  • The docs advise keeping each CLAUDE.md under about 200 lines: longer files use more context and are followed less reliably. The real repositories this series comes from had root files over 600 lines. That worked, but it is the first thing worth trimming.
  • /memory lists which files are loaded right now. See the memory docs.

Giving a principle teeth

A principle nobody checks drifts within a month. Each one should have at least one mechanism that notices:

  1. 1 · Write it as a rule you can check

    "Domain code never imports a payment SDK" can be checked. "Keep things decoupled" cannot.

  2. 2 · Number it

    P2. Reviews, ADRs and code comments now cite it in two characters.

  3. 3 · Teach the alarm

    An edit warning in spec-kit.json tells Claude the moment an edit breaks it, with the reason.

    {
      "files": "src/{rentals,billing}/**/*.py",
      "pattern": "^(from|import)\\s+(stripe|paymentsdk)",
      "message": "vendor import in domain code (P2): depend on the port."
    }
  4. 4 · Write the test

    Where a rule can be tested, test it. Field security, isolation and money all have tests.

  5. 5 · Exceptions need an ADR

    A pull request that goes against P2 links the decision record that allows it (Part 4). No record, no merge.

The edit warning in step 3 is a real hook from the kit, edit-warnings. After every edit it checks the file against your patterns and tells Claude, with the rule’s reason, while Claude still has the context to fix it. Part 10 covers it in full.

What belongs in the root file

Keep in CLAUDE.md
  • Commands to build, test and export the contract.
  • The working rules: plan first, read the handoff, cite IDs.
  • What "done" means here.
  • Pointers: where principles, ADRs and handoffs live.
Move out of CLAUDE.md
  • Long explanations: link the doc instead.
  • Rules for one folder: put them in that folder’s CLAUDE.md.
  • Procedures: make them skills (Part 9).
  • History: that is what ADRs and context drops are for.

Which one fits?

  • It must hold everywhere, always: A principleNumbered in principles.md, checked by a test, hook or review, and changed only by an ADR.
  • Every session in this repo needs it: Root CLAUDE.mdCommands, working rules, the definition of done. Under about 200 lines.
  • It is only true in one module: That module’s CLAUDE.mdLoaded when Claude works in that folder. Write it to stand on its own.
  • It applies to one kind of file anywhere: A path rule.claude/rules/ with a paths list, for example every serializers file.
  • It is a procedure with steps: A skillLoaded only when used (Part 9).

In the kit

Three rules of thumb

Rules you can check

If nobody could tell from the code whether a rule was broken, it is advice, not a rule.

Closest file, most specific rule

Repo-wide rules at the root, module rules in the module. Never repeat one in the other.

Short beats complete

A long CLAUDE.md is followed less reliably. Link out; do not paste in.

QuizThe billing team wants every fee rounded down to whole minor units. Where does that rule go?

Show the answer

Answer: src/billing/CLAUDE.md, and a test in billing

It is true only in billing, so it belongs in billing’s own rules, where Claude reads it exactly when it works there. The test makes sure it stays true.

Words in this post:

  • Principle: a numbered, binding rule for the whole codebase, like P2.
  • Root CLAUDE.md: the repo-wide rules file, loaded at every session start.
  • Scoped CLAUDE.md: a rules file in a subfolder, loaded when Claude works there.
  • Path rule: a rule file that loads only for matching file paths.
  • Teeth: the test, hook or review that notices a broken rule.

Next, Part 4: Decision records handles the exceptions: one file per decision, with the option you rejected and why.

Setting up Claude Code or AI agents for your team?

I help teams build this: agents, RAG search and Claude Code setups that hold up in production.

See services
Next in this seriesSpec-driven development, for realDecision records4 min read