Files
claude-config/CLAUDE.md
T

26 KiB

Global instructions

Shorter is better, none is best — chat output, commit messages, comments, docs and code alike. Never grow any of them by default: adding is a deliberate act to justify, and the fix for a line that has not earned its place is deletion. If the information is already in the code or the project README.md, skip it. Use English everywhere.

Vocabulary

  • chunk — the unit of work: the smallest PR-able change.
  • cycle — one worker run and the judge's verdict on it, in loop-claude.
  • gate — the merge gate: the checks a PR passes before it merges.
  • interrupt — loop-claude handing the terminal to the human, claude --resume, for a decision that is theirs.
  • judge — the headless claude that reads a worker's transcript each cycle and decides whether to interrupt and whether the chunk is finished.
  • pass — one kind of review a chunk may take, run in rounds by its reviewer until clean; larv-review §3 lists them.
  • plan — todo.md.
  • premises — the goals and audience under ## Goals and ## Audience in the project's README.md.
  • release — a semver version the human cuts.
  • reviewer — a reporter of findings: an agent under ~/.claude/agents/, /security-review or a forge's auto-reviewer.
  • round cap — the rounds one pass may take per chunk; larv-review §3 → "Round cap".
  • session — a Claude Code session: one id, what claude --resume continues.
  • trigger — the condition under which a review pass runs on a change it has not seen; larv-review §3 lists them.
  • worker — the headless claude that runs the task in a cycle, in the chunk's session.

Prose

  • Write the thing, not an introduction to it. A sentence announcing what follows, or flagging that it deserves attention, carries nothing — if it matters, it is in what follows. A bare label is fine. BANNED: Here's the new audience text, which is the part that needs your eye:, One thing I changed that deserves your attention., One judgment call I'd flag rather than bury., Three things came along that would otherwise have been left false. GOOD: New audience text:, or the list alone.
  • No contrastive tail. X rather than Y, not Y but X, instead of Y: state X and stop. The rejected alternative is noise unless naming it stops a reader doing Y. BANNED: verified in CI rather than asserted. GOOD: verified in CI.

Maintaining this file

  • When you spot a pattern in how I work that isn't written here — a preference I've repeated, a correction I've given more than once, a convention you inferred from my code — tell me and ask me to write it up here. Don't add it silently, and don't just keep it in a memory file.
  • After every change to this file, re-read the whole thing and restructure it: merge overlapping rules, cut prose that restates a rule, move rules to the section they belong in, drop what's now covered elsewhere. Same information, more compact.

Web research

  • Default to WebSearch/WebFetch. When a page renders client-side and comes back empty/blocked, use the Playwright renderer at ~/code/playwright-for-agents/ — ./pw <url> [options] (see its README). Don't use claude-in-chrome for this.

Compose, do not entangle

The core design rule — it is what keeps a system from turning into spaghetti, in the network, in the code, in the data, and in the tooling. Two things that can stand alone must stand alone, joined by a narrow seam you can name. Never by one reaching through the other.

Apply it as a question to any design that routes A through B, or has A reach into B: does A still work when B is absent, broken, half-deployed, or swapped for something else? If not — and especially if A is what you would use to fix B — the design is wrong however tidy the diagram looks.

  • Services & networking. A deploy trigger, health probe, backup job or admin path gets its own way in. One routed through the application it operates on fails in exactly the state it exists for. BANNED: a deploy webhook reached through the app's own reverse proxy. GOOD: its own listener, answering while the app is down.
  • Code & modules. Dependencies point one way: callers may know the service, the service must never know its callers. Business logic — and its comments — must not name or assume the delivery mechanism (controller, HTTP, request validation, route), because a service may have many consumers (controller, queue worker, CLI, another service). BANNED: // The controller's validator guarantees these fields. GOOD: caller-agnostic phrasing ("callers must supply X"), or just let the guard + type signature speak.
  • Data & state. One owner per piece of state, reached through that owner. Two components writing the same table, file or volume are one component with a seam nobody declared.
  • Tooling & tests. A test, script or pipeline stage that passes only because another one ran first is entangled: state what it needs and get it, or make it independent.
  • Vendors & records. A supplier is a component like any other, so the question above is the whole test: prefer the option tying us to none (~/.claude/principles/technical-principles.md). Documentation the project owns is the case with no excuse. BANNED: the decision log in .claude/rules/, where swapping tools takes the project's reasoning with it. GOOD: docs/decisions.md, with a path-scoped rule pointing at it.
  • Proximity is not a reason. Reusing a listener, config file, table, module or service because it is already there, when the new thing has no relationship to it, is how this gets in. If you cannot name the seam, there isn't one.

One spelling per goal

  • When two spellings reach the same result, make one work and reject the other. Supporting both needs a stated reason, written down.
  • Reject the redundant spelling as early as possible — at load, parse or compile, not at use — and have the error name the spelling to use instead: token {p} renders a level that {p.first} reads a path into; name the fields you want instead.
  • Where the two spellings can disagree, this is a correctness rule. A caveat in the README does not close it.
  • One spelling in two places is two spellings: reject the copied value at load and name the place that keeps it.
  • Applies to data formats, config, CLI flags, public APIs and prose alike, a CHANGELOG line included.

Working loop

How work proceeds in any repo, unless that repo's AGENTS.md says otherwise.

  • README.md states the goals and the audience under literal ## Goals and ## Audience headings — and until it does, nothing else proceeds. Two different things, both required, both public: an outside reader judges the project by where it is heading and who it is for. Goals are priority-ordered aims, one line each, reading like slogans — "1. Blazing fast performance. 2. Correctness is more important than many features." A goal never describes what the code does today; how it is met lives further down the README and names the goal it serves. The audience names who depends on this and what they may rely on. The check is those two headings in README.md, run at the start of every chunk: the same content in AGENTS.md, in docs/, or in a decision log does not satisfy it, and neither does an earlier chunk having passed it. A repo missing either has no premises and gets one chunk that writes them and takes approval before any planned work, todo.md included.
  • Without premises nothing merges and no work is reported as done: the only output is that chunk, or a statement that the premises are missing. Without them only: a security fix — which passes even where it alters an interface — a bot's dependency bump, and a repair restoring behaviour the repo already claims: a red gate, a failing build, a false claim fixed per "A false claim is a bug". None of them decides direction. Anything else that adds capability, alters an interface, or picks between options is planned work and waits. Once written they stand; a later question they do not settle is the ask rule below, never reopened premises.
  • The plan is ordered as semver releases — every item sits under the release that ships it. A todo.md in any other shape gets that shape as this chunk, approval taken.
  • An empty earliest unreleased release with nothing shipped toward it is planned as this chunk: weigh the unscheduled items against the goals, write the order, take approval before any code.
  • An empty earliest unreleased release with work shipped toward it is finished, and stops all work: report what it holds and that it is ready to cut, and stop; under /loop, that stop ends the loop. Only a security fix still lands, into it. Never roll forward into a later release's items, and never plan a new release, while it waits — the bump is the next decision.
  • A release is the human's. The version bump and the publishing credentials are the human's whatever any other rule says; prepare everything around it so the release is one decision.
  • Open every chunk with one line: the last version cut, what is unreleased (CHANGELOG.md's ## Unreleased, else the log since the last tag), and the release this chunk ships into; a repo that publishes nothing says so once.
  • One chunk at a time; split a milestone into sub-items in todo.md before starting it. A finding inside the chunk is fixed in the chunk; outside it, it becomes a todo.md item under a release.
  • A done item leaves todo.md; its release heading stays until the version is cut. Where the repo publishes something a consumer takes — a package, an image, an API — the line is reworded for that consumer and moves to CHANGELOG.md under ## Unreleased; a CHANGELOG is written for the public, never for the next agent. Everywhere else the line is simply deleted, because git history is already the record.
  • Ship every chunk with /larv-review.
  • Ask, don't guess — and fix the goals rather than the question. Before asking, check whether the goals already settle it; where they nearly do, propose the goal change and show what falls out of it for the instance, because one answered question settles one instance and a goal settles the class. Every answer lands where its kind belongs, and nowhere else: a goal in README.md, a working rule in AGENTS.md, a standing choice in docs/decisions.md. Where an answer is more than one of these, the goal wins — write the goal, and record a decision only for what it still leaves open. Never in chat alone.

Working with the codebase

  • Run a project's language runtime, package manager, and task runner through its container/tooling setup, never directly on the host. Example: docker compose run --rm app <tool> ….
  • Check README.md first for build, test, install, and codegen commands; one that misbehaves is fixed per "A false claim is a bug". Refresh README.md whenever you change what it describes ("Refresh README.md to match").
  • Always start a new git worktree when doing something in a codebase, and clean it up when done. Unless told otherwise, branch it off a freshly-updated default branch (git fetch origin, then base on origin/main), not whatever happens to be checked out.
  • Pin GitHub Actions to semver tags (@v3, @v3.1.2), not commit SHAs — including third-party actions. SHA-pin only in special pipelines that test our own specific builds.
  • Pin container images to the full patch version everywhere they're referenced — Dockerfile FROM, compose image:, base images in test fixtures: node:24.18.1-bookworm-slim, mysql:8.4.7, alpine:3.23.3. Never a floating major or minor (node:24, node:24.18, :latest, :lts): the same commit then builds a different image on different days, so a green pipeline says nothing about the next run, a base change lands with no diff to review, and any size or performance figure measured against it silently goes stale. Let a bot (Renovate/Dependabot) raise the bumps as reviewable PRs — that is where a base change belongs. (Actions are the exception above: a semver tag is fine there, because the action's own release is the reviewable unit.)

Handoffs

  • One document per project: ~/code/claude-handoffs/<project>_<YYYY-MM-DD>.md, with its supporting files (scripts, probes, saved sessions) under ~/code/claude-handoffs/<project>/<YYYY-MM-DD>/, dated the day they were written.
  • Each document stands alone — projects move in parallel, so never reference another project's handoff. A fact two of them share (a test site, where credentials live) is stated in each, or kept in a memory file and named there.
  • Content: only what the repo cannot hold — probe results, where credentials live. What is done and the next step live in the plan; goals, audience and decisions in README.md/AGENTS.md. A handoff never restates them: the repo's copy travels with the code and this one does not.

Tests

  • Write tests first for the behaviour we want, then implement until they pass.
  • Changing tests and changing other code are two separate processes — be very careful about doing both at once.
  • Use properly randomised UUID v7s — never aaaa-0000-style placeholders.
  • Tear down test containers after a run.

Code style

  • Indent with hard tabs by default. A project's own settings win: .editorconfig, linter/formatter config (Prettier, rustfmt.toml, …), or the surrounding file's existing indentation.
  • Reuse before adding. Extend an existing test with an assertion rather than writing a new one.
  • Sort wherever order carries no meaning (~/.claude/principles/technical-principles.md) — attributes, array and object keys, enum members, imports, table rows, and line-based file lists such as .gitignore/.dockerignore. Exception: id goes first.
  • Sort a compound line on the name it introduces, never on an incidental field: an import on its first binding, not its path, so moving or renaming a module reorders nothing. Where lines already group by kind — type imports, host packages — the key sorts within each group.
  • Prefer a standalone Python script with a #!/usr/bin/env python3 shebang over a shell script — it runs identically across systems where shell dialects/builtins differ. Read config (credentials, hosts, paths) from CLI params or env vars, never hardcoded.
  • DTOs, enums, and value objects are pure data — no logic. They stand in for the structs/records a language lacks.
  • Prefer explicit, descriptive names over generic ones (invoiceRowsService, not service).
  • Keep delivery-layer entrypoints thin: inject services, validate + hand off the request data, map the service's return to a response. Domain decisions and branching belong in the service layer — an entrypoint reaching into a payload to decide what to do is the smell. BANNED: if (body.tx.source === 'notification') { /* drop, skip enqueue */ } in a route handler. GOOD: the entrypoint forwards source on the event → the service decides drop-vs-process and returns a result → the entrypoint maps that result to a status code.
  • Signal failures with a result value carrying an optional error, not by throwing. A function that both returns a result and throws for some inputs has two error channels; collapse to one. Reserve exceptions for truly unrecoverable states at boundaries, never for control flow the caller is meant to handle.
  • A cast (x as Foo) asserts what the compiler could not check and stops it checking — so when the type later changes, nothing tells you. Derive the real type instead: infer it, name the return type, or parse the input once into a typed shape. Where a value genuinely arrives untyped (HTTP body, JSON.parse, DB row), the boundary owes a type guard validating the fields it claims; past that boundary everything is typed. as unknown as T and non-null ! are the same defect wearing a hat. BANNED: const user = body as User — one rename and it is a silent lie. GOOD: function isUser(v: unknown): v is User checking each field, then if (!isUser(body)) return { error: … }.

Naming files & folders

  • Name by what's inside, not by catch-all. BANNED: scripts, utils, helpers, misc, common, lib, stuff. Use explicit names: e2e-tests/, db-migrations/, release-tooling/.
  • Group related artifacts by purpose — e2e compose files, e2e Dockerfile, and e2e test scripts all belong in e2e-tests/.

Comments and documentation (README.md, AGENTS.md, docs/, API specs)

One bar for all of it. A comment or a paragraph earns its place by saying what a competent reader of THIS codebase could not infer and the repo cannot say for itself: a surprising WHY, a footgun, an invariant, an external constraint. The fix for a redundant one is deletion, not trimming — two copies drift, and the doc copy is the one nobody updates. Once it has earned its place, make it short and information-dense. GOOD: // Loud-fail: missing amount used to coerce to '0' = phantom "0 SEK reversal" in api-4. — records a past prod bug the code can't show.

A false claim is a bug — fix it where you find it. Docs, comments and what a program prints — --help, an error, a log line — assert checkable things: a command, a resolution rule, a path, a limit. Verify one before you repeat or build on it. When it is wrong, correct it in the same change: the claim — or the code, when consumers already rely on what the claim promises. Never work around it or record the discrepancy elsewhere.

Negation, history and limitations: name the action, or say nothing. Prose describing the code as it stands — a comment, a README, an AGENTS.md, an API spec — may narrate what is not done (a removed step, a call we don't make, a superseded version we used to X, now Y, a limitation) in one shape only: where a reader would otherwise do something harmful, and the sentence says what to do instead. GOOD: wrap a direct ./tests/run.sh to put it under the same lock. BANNED: run.sh takes no host lock. A limitation with nothing to do instead belongs in the PR or ticket, because documenting a limitation is not fixing it.

The inversion: a decision record owns what a call site may not say. A rejected alternative, or what something deliberately does not cover, is banned beside the code precisely because the decision record holds it — a standing choice a future reader would otherwise relitigate, where a CHANGELOG holds what changed in a release. The decision log has one home: docs/decisions.md, or docs/decisions/ split by area once it outgrows one file. AGENTS.md carries a one-line index of the titles, so a session or a reviewer sees that a decision exists without loading its reasoning. An entry states the decision, its date, who made it, and the premise it rests on ("valid while X") so it can expire honestly when that premise dies. A decision found anywhere else — an AGENTS.md body, a comment, or a README section that is neither a goal nor how one is met — moves there and leaves its index line behind. A goal stays a goal in the README; the log records only what the goal leaves open.

Every decision links to a goal. An entry names the goal it serves; one that cannot is a missing goal, and an entry already in the repo with no goal behind it is a finding. Propose the goal, never a reason of your own — the ask rule above says how.

Link, don't inline — and keep the link bare. A mechanism identical across call sites or repos is documented once in the canonical source and pointed at with a one-line bare link. Don't summarize what's behind the link or restate the identifier's own name.

A pointer is not a definition. A definition the reader needs to follow the code — what a unit counts, what a term means, what invariant a cache rests on — sits at the code in one line. A pointer to it (see AGENTS.md §11) cannot be checked against the code beside it, so it rots invisibly. A pointer carrying rationale — a rejected alternative, the premise behind a standing choice — is correct and stays.

Comments

The rules below govern prose comments; doc comments a tool consumes — docstrings, godoc, JSDoc types — are outside them.

Default to NO comment. Delete one that is any of:

  1. A restatement of the adjacent code. BANNED: // Sanitized + bounded to 1000 chars above mb_substr(json_encode(LogSanitizer::body($x)), 0, 1000).
  2. A cross-cutting convention used elsewhere (sanitization, the 1000-char Loki cap, "log so the source is recoverable"). Project-wide facts live in ONE doc, never repeated at call sites.
  3. A justification of self-evident code (a log line is self-evidently for observing its value).
  4. A file preamble or arrangement rationale: what a file holds, why it exists, why two things share it, why a check sits beside what it judges, why an order was chosen. The file name and the declarations are the index; a choice with no effect on the running program belongs in the commit that made it.

What stays is one terse line, and only where the code cannot show it. GOOD: # Pinned to 7.x: hurl 8's jsonpath change breaks the nth-filter asserts. A second line belongs in the commit message or the ticket. The one exception is a paragraph for an invariant a reader must hold before touching the code below; it stays with the code it guards.

Density is a review signal. Prose comment lines much past ~10% of a file's non-blank lines mean something is wrong — narrating comments, or code that fails to carry its own meaning. A defect to investigate, not a style preference.

README

A README covers what a reader needs before opening the code: how it meets its goals, how to build, test, run, and deploy it, and cross-cutting decisions no single file owns. It does not narrate an individual symbol, file, or test case — whoever wants to know what a test asserts opens the test, where the answer is exact and cannot drift.

"Refresh README.md to match" means keep it true, not longer. A change that alters a build/test/run/deploy step, a required env var, or a prerequisite makes the README a false claim by omission, fixed per "A false claim is a bug". Otherwise most changes need no README edit at all, and adding a section is a deliberate act you must justify. GOOD: run-tests.sh gained a required --profile flag → update the documented command. BANNED: the change added a test case → add a paragraph describing it.

Todo items (todo.md, tickets, plans)

  • Open each item with a bold one-sentence tagline, so the taglines alone say what a release holds; detail follows it. The tagline states the target state, checkable when done: an imperative verb plus what holds afterwards. A present-tense fact reads as the current state and says nothing about what to do. Add "today X" only where the direction is otherwise ambiguous. GOOD: **Accept undefined in MetadataValue and drop such keys on output.** BANNED: MetadataValue accepts undefined; such keys are dropped on output.
  • A security finding — a leaked credential, secret or PII, an auth bypass, an injection — is filed the moment it is found, at the top of the list under its own ## Security heading, naming the exposure and the path it reaches. Never among additive or nice-to-have items, never only in a chunk's summary, and never as a question about where it belongs: file it, say you did, and I will move it down if I disagree. Fixing it inside an unrelated change is a separate call — say whether it is in the blast radius.

Package README (what someone finds on npm or GitHub)

  • The public API is the contract, so the README documents it: options, results, events, everything exported. The rule against narrating a file or test case still holds.
  • Order sections by what a new developer wants first: install, the main task, the next task, and so on. The reference half — options tables, in-depth behaviour, low-level API, development — goes below the quick starts.
  • Headline plus short, clear instruction, nothing else. No meta-prose ("things to keep in mind", "you may want to know"). An intro is a line or two that points at the in-depth section.
  • Keep every documented behaviour, as terse facts, bullets and tables rather than paragraphs. Where the README is the only record of a behaviour, cutting it is a decision to ask about, not a tidy-up.
  • Write for the app developer using the package; gloss a domain term once, on first use.
  • Top: badges (package version, CI), a one-line tagline that is also the package manifest's description, a feature list, a one-line table of contents. Near the bottom: a table of everything exported.
  • A guide for migrating from an older major goes in MIGRATION.md, linked from one line in the README.

Public API specs

  • Text in public API specs (OpenAPI description/title fields and the generated api-docs) is read by external consumers. Never leak internal references: no ticket IDs, internal URLs, repo/system code-names, "see ticket X". Describe behaviour in consumer terms. GOOD: Deprecated alias for paymentAccountId. BANNED: …will be removed (ABC-123).
  • The opposite of internal code comments, which may cite a ticket for a footgun/constraint.

Git, commits, and PRs

  • Use gh on GitHub remotes and tea on Gitea remotes (e.g. gitea.larvit.se) — same command shape: tea pr list|create, tea issue, tea release, tea api. Everything below applies to both.
  • Branch for a ticket: exactly the ticket ID, nothing more. ABC-123, never ABC-123-some-description.
  • When the work has a ticket, read it before starting: verify the change matches it and pull useful context from it.
  • Commit message and PR title: one line, prefixed with the ticket ID when the work has one. Example: ABC-123 - Regression tests for GET /v4/clients. Never include the repo/project name (like "twu-4") — we're already in that context.
  • PR summary: short and concise. No test plan (it lives in the ticket), no link to the ticket (it's in the title).
  • Keep the project's main checkout (e.g. ~/code/log, never a worktree) current: when it is behind origin — a merge landed, or a fetch shows it — run git pull --ff-only there instead of reporting the lag, never with --autostash: a dirty checkout is a finding to report, not to carry along.
  • Releases follow semver read strictly (~/.claude/principles/technical-principles.md).
  • Never add Co-Authored-By: Claude ..., 🤖 Generated with Claude Code, or any Claude/Anthropic/Agent marker in commits, PR bodies, issue comments, or anywhere else.