Files
claude-config/CLAUDE.md
T

22 KiB
Raw Blame History

Global instructions

Working loop

How work proceeds in any repo, unless the repo's AGENTS.md says otherwise. The next release is the earliest one not yet cut. Other words, such as chunk, are defined under "Vocabulary" at the end of this file.

  • Until README.md has a ## Goals and an ## Audience section, writing them is the only work. Not even planning in todo.md. Both are public: an outside reader judges a project by where it is heading and who it is for. Goals or an audience written anywhere else, such as AGENTS.md or docs/, do not count.
    • Goals are the project's aims, not promises: one line each, in priority order, like slogans — "1. Blazing fast performance. 2. Correctness is more important than many features." A goal rarely names an implementation; how a goal is met goes further down the README and names the goal it serves.
    • Audience names who depends on the project and what they may rely on.
  • Plan todo.md by semver release: every item sits under the release that ships it. If todo.md has another shape, reshaping it is the chunk, and the human approves it.
  • When the next release has no items and no work has landed towards it, plan it as this chunk. Weigh the unscheduled items against the goals, put them in order, and get the human's approval before writing any code.
  • When the next release has no items left and work has landed towards it, it is finished: stop. Report what it holds and that it is ready to cut. Under /loop, this ends the loop. Until the human cuts it, only a security fix lands, into that release; never start a later release's items or plan a new one.
  • Open every chunk with one line: the last version cut, what is unreleased (CHANGELOG.md → ## Unreleased, or else the log since the last tag), and the release this chunk ships into. A repo that publishes nothing says so once.
  • Work one chunk at a time, and make it as large as one purpose allows. Every review has a fixed cost, so a chunk takes the next plan item plus every other item for which three things hold: one PR title states what they achieve together, without listing them; they sit under one release; and they fire the same review passes (larv-review §3). Tiny items, a few lines of change each, need neither a shared purpose nor the same passes: bundle up to ten from one release into one chunk. Split a milestone into items in todo.md before starting it. Fix a finding in the chunk's own change within the chunk. File a finding about anything else in todo.md, under a release.
  • Ask, don't guess. First check whether the goals already answer the question. If they nearly do, propose a change to the goals and show how it answers this case: an answer settles one question, a goal settles every question like it. Write every answer once, where it belongs, never only in chat: a goal in README.md, a working rule in AGENTS.md, a standing choice in a comment at the one place it governs, or in docs/decisions.md once it recurs. If an answer is a goal and something else too, write the goal, and record a decision only for what the goal leaves open.
  • Ship every chunk with /larv-review.
  • Remove a finished item from todo.md; keep its release heading until the version is cut. If the repo publishes something others consume — a package, an image, an API — reword the line for them and move it to CHANGELOG.md under ## Unreleased. A changelog is for the public, never for the next agent. Otherwise delete the line; git history is the record.
  • Releases are the human's. The version bump and the publishing credentials are theirs, whatever another rule says. Prepare everything else, so cutting a release is one decision.
  • Releases follow semver read strictly (~/.claude/principles/technical-principles.md).

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.

Quality

Quality is proven by review. Every change is reviewed as a diff. The whole project is measured when a change carries an architectural decision, and before each release, because a project can drift from the principles one clean diff at a time. larv-review §3 says which review runs when. Quality has four parts. When two pull against each other, the earlier one wins.

  1. Correct. The work does what the goals and the plan say, and tests prove it.
  2. True to the technical principles (~/.claude/principles/technical-principles.md).
  3. Easy to comprehend. A reader new to the project understands it. The comprehension-panel skill scores the project; a score under the comprehension floor (larv-review §3 → "Architecture") blocks a merge, and the aim is always higher.
  4. Plainly written, per "Prose".

Prose

Everything written — chat, commit messages, comments, docs, code — is in English. Prose meets four priorities, in this order. When two pull against each other, the higher one wins.

  1. Easy to understand. A reader with little time gets it on one read. Keep each sentence to one idea. Explain a term before using it, or use a plainer word. Never fold a clause into a noun phrase to save words. BANNED: An empty earliest unreleased release with nothing shipped toward it is planned as this chunk. GOOD: When the next release has no items and no work has landed towards it, plan it.
  2. Most important first, judged by what this document's reader wants to know first. Put the most important section first. Within each section, put the most important paragraph first, and within each list the most important item. Order matters most in long documents; in a short one, don't spend a fix on it.
  3. Default to delete. Keep a line, of prose or code, only if a reader needs it and nothing else already says it. Adding words is a deliberate act: name what a reader could not understand without them.
  4. Short. Cut whatever does not clearly help 1–3.
  • 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.

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

What earns a place

The reader is a competent reader of THIS codebase. A comment or a paragraph earns its place by saying what that reader could not infer and the repo cannot say for itself: a surprising WHY, a footgun, an invariant, an external constraint. Fix a redundant one by deleting it, never by trimming it: two copies drift, and the doc copy is the one nobody updates. 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.

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.

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.

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.

Decisions: one home, each linked to a goal or a technical principle

A choice that shapes what the code does, made in one place, is a comment there, with its reason. Made in more than one place, it is a decision, and the decision log owns it. Its rejected alternative, or what it deliberately does not cover, stays out of every call site. The decision log has one home: docs/decisions.md, or docs/decisions/ split by area once it outgrows one file. A title states the whole decision in one line: what holds at the commit it ships in, in words a reader finds in the code or the plan. AGENTS.md lists every title, so a session works by the decisions without loading their background. A session reads the entry under a title only to question, revise or add a decision. The entry holds the background: its date, who made it, the reasoning, and the premise it rests on ("valid while X") so it can expire honestly when that premise dies. A choice found anywhere else — an AGENTS.md body, a comment, or a README section that is neither a goal nor how one is met — moves: to a comment at its one place, or, once it recurs, to the log, leaving its title in AGENTS.md's list. A goal stays a goal in the README; the log records only what the goal leaves open.

Every decision links to a goal or a technical principle. An entry names the goal it serves or the technical principle under ~/.claude/principles/ it applies; one that can do neither is a missing goal, and an entry already in the repo with neither behind it is a finding. Propose the goal, never a reason of your own — "Ask, don't guess" under "Working loop" says how. An entry working against a goal or a technical principle stands only while it names the todo.md item that ends it.

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. 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.

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.
  • Sections, in order: 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. Each quick start opens with a line or two that links its in-depth section.
  • Keep every documented behaviour, as 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.
  • 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.

Working with the codebase

  • 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.
  • 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.
  • Run a project's language runtime, package manager, and task runner through its container/tooling setup, never directly on the host unless a decision puts them there. Example: docker compose run --rm app <tool> ….
  • Tear down test containers after a run.
  • Give a subagent only the access its job needs, and state the limits in its prompt. One that only reads, such as a prose review, gets no shell and no edits. One that probes a build tags the image as throwaway and removes it afterwards, writes only to the session scratchpad, and removes no image or file it did not create.
  • 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").
  • 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.
  • 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.)

Naming files & folders

  • Name by what's inside. BANNED: scripts, utils, helpers, misc, common, lib, stuff. GOOD: 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/.

Technical principles

The rules every project follows, compose-not-entangle first: ~/.claude/principles/technical-principles.md. Read it before writing, designing or reviewing code.

Git, commits, and PRs

  • 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.
  • 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).
  • When the work has a ticket, read it before starting: verify the change matches it and pull useful context from it.
  • Branch for a ticket: exactly the ticket ID, nothing more. ABC-123, never ABC-123-some-description.
  • 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 in this section applies to both.

Handoffs

  • Write no handoff document. The repo holds everything the next session needs: the plan, the decisions, and every script, sketch or measurement those depend on. A file outside the repo is unreachable from another machine's checkout.
  • Keep four kinds of fact out of the repo, in a memory file: a secret's value; where this machine keeps its copy of one; a quirk of the agent's own environment that a human contributor does not share; data the repo may not publish, unlicensed or holding PII.

Web research

  • A list or threshold a consumer relies on is sourced. Deny-lists, defaults, limits: follow a published standard or a widely deployed tool, and cite it in the decision recording the choice; where none exists, ask. Never assemble one from names that seem plausible.
  • 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.

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, easier to read and shorter.

Vocabulary

  • chunk — the unit of work, shipped as one PR; "Working loop" says what it holds.
  • 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 reviewers 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.