23 KiB
Global instructions
Prose
Everything written — chat, commit messages, comments, docs, code — is in English and meets four priorities, in this order. When two pull against each other, the higher one wins.
- Easy to understand. A reader with little time and no context gets it on one read. Write whole sentences: a subject, a verb, at most one condition. 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 done towards it, plan it. - Most important first — in every file, section, list and sentence. The point comes first; detail and reasons follow.
- Default to delete. Keep a sentence only if a reader needs it and the code, the README or another rule does not already say it. Adding words is a deliberate act: name what a reader could not understand without them.
- Short. Cut whatever does not clearly help 1–3. Shortening never breaks 1.
- 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.
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-claudehanding 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
## Goalsand## Audiencein the project'sREADME.md. - release — a semver version the human cuts.
- reviewer — a reporter of findings: an agent under
~/.claude/agents/,/security-reviewor 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 --resumecontinues. - 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.
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.
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.
Technical principles
The design rules every project follows, compose-not-entangle first: ~/.claude/principles/technical-principles.md. Read it before designing or reviewing code.
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.
- No work starts until
README.mdhas a## Goalsand an## Audiencesection. Not even planning intodo.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 asAGENTS.mdordocs/, 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.
- Work one chunk at a time. Split a milestone into items in
todo.mdbefore starting it. Fix a problem found inside the chunk in the chunk; file one found outside it intodo.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 where it belongs, never only in chat: a goal in
README.md, a working rule inAGENTS.md, a standing choice indocs/decisions.md. 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. - 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. - Plan
todo.mdby semver release: every item sits under the release that ships it. Iftodo.mdhas another shape, reshaping it is the chunk, and the human approves it. - When the next release has no items and no work done towards it, plan it. Pick from the unscheduled items, judged 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. - 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.
- 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 toCHANGELOG.mdunder## Unreleased. A changelog is for the public, never for the next agent. Otherwise delete the line; git history is the record.
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.mdfirst for build, test, install, and codegen commands; one that misbehaves is fixed per "A false claim is a bug". RefreshREADME.mdwhenever you change what it describes ("RefreshREADME.mdto 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 onorigin/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, composeimage:, 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:idgoes 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 python3shebang 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, notservice). - 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 forwardssourceon 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 Tand 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 Userchecking each field, thenif (!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 plain and short. 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 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 — the ask rule above says how. An entry working against a goal or a technical principle stands only while it names the todo.md item that ends 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.
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:
- A restatement of the adjacent code. BANNED:
// Sanitized + bounded to 1000 charsabovemb_substr(json_encode(LogSanitizer::body($x)), 0, 1000). - 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.
- A justification of self-evident code (a log line is self-evidently for observing its value).
- 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
## Securityheading, 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/titlefields 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
ghon GitHub remotes andteaon 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, neverABC-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 behindorigin— a merge landed, or a fetch shows it — rungit pull --ff-onlythere 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.