Skip to content

Coding with AI

AI coding tools write a lot of our code. They are fast and confident, and they are wrong often enough that every line still needs an owner. That owner is you: the model writes a draft, you decide what ships.

How AI gets code wrong

Knowing the failure modes is most of the skill. Expect these and look for them every time:

  • It invents things that look real: functions, props, env vars, API options and file paths that do not exist in this repo.
  • It writes code that works but does not match ours: a hand-rolled fetch instead of our helper, a raw colour instead of a theme token, a new pattern next to an existing one.
  • It "fixes" a failing test by weakening the test, or a failing check by disabling it.
  • It says "done" or "all tests pass" without having run anything. Believe output you saw, not claims.
  • It quietly changes more than you asked: reformatting files, renaming things, touching unrelated code.

The loop for every change

These steps are in order. Skipping one is how most bad changes ship.

  1. Start the session by pointing the tool at CLAUDE.md (the repo root) and the CLAUDE.md in the directory you are working in. They hold the rules below and the map of the codebase. Claude Code reads them automatically; other tools need to be told.
  2. Describe the task precisely: what should change, where, and what "done" looks like. "Fix the bug" gets a guess; "the check-in cards on /admin/alarms overlap at 1000px wide, fix the layout without changing their content" gets a fix.
  3. Ask for a plan before code for anything bigger than a few lines. Read it, push back, then let it write.
  4. Keep changes small: one concern per change. A 40-file diff cannot be reviewed, so it will not be.
  5. Run it yourself: the dev server, the page, the test. Then run the commit gate (below).
  6. Read the whole diff (git diff) before committing, using the review checklist at the end of this page.
  7. Commit with a message that says why, push a branch, open a pull request, wait for CI.

Repo rules AI tools break most

CLAUDE.md is the full list. These are the ones to check by hand in anything a model writes:

  • API routes are wrapped in defineHandler (from lib/api/handler.server). It does the session check, rate limit and input validation in the right order. A handler that does those itself is wrong even if it works.
  • Server-only code lives in files named *.server.ts and is never imported from client code. Getting this wrong fails at runtime, not at build time.
  • Every user-facing string goes through the t() function with a defaultValue, then pnpm i18n:extract. Changing the wording of a shipped string means a new key.
  • Colours, radii, shadows and fonts come from the theme tokens (bg-site-surface, rounded-site, …) and shared components in components/ui. No raw colours or hardcoded radii; CI rejects them.
  • Code under server/ imports lib/ with relative paths, never "@/". A wrong import there can ship a service that crashes on start.
  • Never hand-edit generated files (app/routeTree.gen.ts, lib/i18n/resources.*.ts). Regenerate them with their tools.
  • Database changes come with a migration (pnpm db:migrate). Production runs migrations on deploy; db:push is for your local database only.
  • Validate all input with zod, rate-limit writes, and fetch user-supplied URLs only through lib/ssrf-guard.server.

The commit gate

One command checks a change against the rules CI enforces: the design rules on the lines you added, the consistency tests, lint, the typechecker and the generated docs. Run it before every commit:

pnpm hooks:install            # once per clone: runs the gate on git commit
pnpm check:consistency        # the staged change
pnpm check:consistency --base main   # the whole branch, before a PR
pnpm test                     # the test suite

A failing gate is fixed, not bypassed. If a model suggests --no-verify or a skip variable to get past it, say no. If a rule is genuinely wrong for your change, change the rule in the same commit and say why in the message.

What CI/CD does with your change

  • Opening a pull request runs CI: typecheck, lint, the tests, a production build, a dependency audit, an integration suite, and the Go tests when Go code changed. Do not merge until all of them are green.
  • Some pull requests also get an automated LLM "senior engineer" review that can block the merge. Treat its comments like a reviewer’s: fix them or reply with why not.
  • Merging to main deploys to production. There is no staging step in between: merge only what you would ship right now.
  • The deploy runs the tests again, builds the images, migrates the database, then swaps the web servers one colour at a time and watches them for five minutes. If the new version fails its checks, it rolls back on its own and the deploy channel says so.
  • A failed deploy or a failed rollback pages whoever is on call. If yours did, say so in the on-call channel and help fix it; the runbooks in docs/runbooks/oncall explain each alarm.
  • Never commit to main directly, and never force-push to it. Work on a branch; if several AI sessions share one checkout, give each its own git worktree so they cannot switch each other’s branch.

Secrets and AI tools

  • Never paste a token, password, key or webhook URL into an AI chat, a Discord channel or an issue. Chats are logged, and channels are read by everyone in them.
  • Secrets live in environment files on the server and in the GitHub and Cloudflare secret stores, never in the repo (it is public). When a tool needs a secret, have it read it from a file or prompt for it, without printing it.
  • If a secret leaks anyway, rotate it: make a new one, put it where the old one was, delete the old one. Deleting the message is not enough.

Reviewing what the model wrote

Before you commit, every one of these should be a yes:

  • I have read every line of the diff and can explain it.
  • Every function, import and option it uses exists. I searched for it, I did not assume.
  • It reuses our helpers and components instead of adding a second way to do the same thing.
  • I ran it: the page renders, the endpoint answers, the test fails without the fix and passes with it.
  • Input is validated, writes are rate-limited, and nothing new is reachable without the right sign-in.
  • No test was weakened, skipped or deleted to make it pass.
  • Nothing outside the task changed.
  • The commit gate passes, and the commit message says why the change exists.

When you are stuck

Ask the model to explain the code or the error before asking it to fix anything, and check its explanation against the code. If a fix has not worked twice, stop and read the error yourself; the third guess is rarely better. Then ask a person.

The repo’s CLAUDE.md, CONTRIBUTING.md and docs/testing.md go deeper on everything here. Back to Developer

We use essential cookies to run the site and privacy-friendly analytics to improve it. Learn more