# CLAUDE.md

These published copies are a working example of a steering-doc setup — enough to show the shape and the discipline, not a complete product specification.

## Steering Documents

- [Product Overview](docs/product.md) - What Gearious is, who it's for, and the problem it solves: the real-time balance-indicator vision, target riders, web-only build scope, and product principles.
- [Release Plan](docs/release-plan.md) - The phased roadmap for building Gearious, condensed for reference during development.
- [Technology Stack](docs/tech.md) - The web stack and non-negotiable conventions: App Router, Supabase + RLS, grams-as-integers, the pure balance engine, API patterns, naming, env vars, and commands.
- [Project Structure](docs/structure.md) - How the codebase is organized: route groups, API resource mirroring, component/lib/store/hook layout, import patterns, and a guide for where new code goes.
- [Audience](docs/audience.md) - Who uses the app and how much complexity they can handle: the domain-vs-software expertise split, what riders care about, progressive disclosure, tone, and accessibility.
- [Design System](docs/design-system.md) - The dual-theme visual language: Tailwind color tokens (taupe/olive/amber/orange/lime), type and spacing scales, radii, motion, and the light/dark theming architecture.

## Keeping Steering Docs Current

The steering docs are the source of truth for every future session. If they fall behind the actual implementation, the next session starts with wrong assumptions. **Update the relevant doc before ending any session that changes an architectural decision, adds a new convention, or completes a phase.**

### What triggers an update and where it goes

| What changed | Update this doc |
| --- | --- |
| New or revised architectural decision (stack, patterns, conventions) | `tech.md` |
| New file, folder, or import pattern added to the codebase | `structure.md` |
| A phase completes or scope changes | `release-plan.md` |
| A product decision changes (feature scope, UX behavior) | `product.md` |
| A design token, theme rule, or component pattern is established | `design-system.md` |
| Something new learned about who the users are or how they behave | `audience.md` |

### The rule

If you make a decision during implementation that isn't already captured in a steering doc — a new pattern, a tradeoff, a convention that emerged from the code — write it down before moving on. A decision that only exists in a chat transcript is a decision that will be re-litigated next session.

## GitHub Workflow

### Branches

- **Never commit directly to `main`** for anything beyond trivial one-liner fixes (typos, docs). All real work happens on a feature branch.
- Branch naming: `issue/{number}-{short-slug}` — e.g. `issue/14-balance-engine`. If there's no issue, use `feat/{slug}` or `fix/{slug}`.
- Create the branch before writing any code. Don't start on `main` and move it later.

### Commits

- Commit at logical stopping points — a passing test, a working route, a complete component. Not at the end of a session as one giant dump.
- Commit message format: `{type}: {what changed}` — e.g. `feat: add calculateBalance pure function`, `fix: correct tare weight inclusion in left side total`, `docs: update tech.md with a new convention`.
- When a commit closes or relates to an issue, include `Closes #N` or `Refs #N` at the end of the message body.

### Pull Requests

- Open a PR from the feature branch to `main` when the work is ready to review/merge — not before.
- PR title mirrors the issue title or describes the change plainly.
- PR description includes: **What changed**, **How to verify** (steps to confirm it works), and **Screenshots** if there's any UI change.
- Link the issue in the PR body: `Closes #N`.

### Issues

- **When completing work tied to a GitHub issue, post a comment on the issue before closing it.** The comment should summarize: what the solution was, any decisions or tradeoffs made, and anything left for a follow-up issue if the scope was trimmed.
- Close the issue via the PR merge (`Closes #N` in the PR body) — not manually.
- If a task reveals new work that's out of scope for the current issue, open a new issue for it rather than expanding the current one.

### What Claude does not do without being asked

- Does not push to `main` directly.
- Does not merge PRs.
- Does not close issues manually.
- Does not open PRs until the work is complete and tests pass.

## Behavioral guidelines

Behavioral guidelines to reduce common LLM coding mistakes. Merge with project-specific instructions as needed.

**Tradeoff:** These guidelines bias toward caution over speed. For trivial tasks, use judgment.

### 1. Think Before Coding

**Don't assume. Don't hide confusion. Surface tradeoffs.**

Before implementing:
- State your assumptions explicitly. If uncertain, ask.
- If multiple interpretations exist, present them - don't pick silently.
- If a simpler approach exists, say so. Push back when warranted.
- If something is unclear, stop. Name what's confusing. Ask.

### 2. Simplicity First

**Minimum code that solves the problem. Nothing speculative.**

- No features beyond what was asked.
- No abstractions for single-use code.
- No "flexibility" or "configurability" that wasn't requested.
- No error handling for impossible scenarios.
- If you write 200 lines and it could be 50, rewrite it.

Ask yourself: "Would a senior engineer say this is overcomplicated?" If yes, simplify.

### 3. Surgical Changes

**Touch only what you must. Clean up only your own mess.**

When editing existing code:
- Don't "improve" adjacent code, comments, or formatting.
- Don't refactor things that aren't broken.
- Match existing style, even if you'd do it differently.
- If you notice unrelated dead code, mention it - don't delete it.

When your changes create orphans:
- Remove imports/variables/functions that YOUR changes made unused.
- Don't remove pre-existing dead code unless asked.

The test: Every changed line should trace directly to the user's request.

### 4. Goal-Driven Execution

**Define success criteria. Loop until verified.**

Transform tasks into verifiable goals:
- "Add validation" → "Write tests for invalid inputs, then make them pass"
- "Fix the bug" → "Write a test that reproduces it, then make it pass"
- "Refactor X" → "Ensure tests pass before and after"

For multi-step tasks, state a brief plan:
```
1. [Step] → verify: [check]
2. [Step] → verify: [check]
3. [Step] → verify: [check]
```

Strong success criteria let you loop independently. Weak criteria ("make it work") require constant clarification.

---

**These guidelines are working if:** fewer unnecessary changes in diffs, fewer rewrites due to overcomplication, and clarifying questions come before implementation rather than after mistakes.
