|
| 1 | +# CLAUDE.md |
| 2 | + |
| 3 | +## Non-Negotiables |
| 4 | + |
| 5 | +- Strict TDD is mandatory: Write failing test first (test-as-documentation, one-at-a-time, regression-proof, table-driven, test-doubles) -> minimal code to pass -> refactor -> using linters & formatters. |
| 6 | +- Always research the latest and up-to-date information and official documentation before implement any thing to prevent hallucinated syntax. |
| 7 | +- Adversarial Cooperation: Rigorously check against linters and hostile unit tests or security exploits. If complexity requires, utilize parallel Tasks, Consensus Voting, Synthetic and Fuzzy Test Case Generation with high-quality examples and high volume variations. |
| 8 | +- Only trust independent verification: Never claim "done" without test output and command evidence. |
| 9 | +- Commits & Comments: No watermarks. No `Co-Authored-By` lines. Only plain simple text, maybe with unordered dash list or numbered list, avoid em/en dashes or bolting or italicizing or emojis. For comments, always in my humble voice and stay as unconfrontational as possible and phrase most things as constructive questions. |
| 10 | + - Conventions: Use Conventional Commits (feat, fix, docs, refactor, test, chore). |
| 11 | + - Granularity: Atomic commits. If the logic changes, the test must be committed in the same SHA. |
| 12 | + - Security: Never commit secrets. If a test requires a secret, it must use environment variables or skipped if the variable is missing. |
| 13 | + |
| 14 | +## Core Workflow |
| 15 | + |
| 16 | +### Requirements Contract (Non-Trivial Tasks) |
| 17 | + |
| 18 | +#### Before coding, define |
| 19 | + |
| 20 | +1. Goal: What are we solving? |
| 21 | +2. Acceptance Criteria: Testable conditions for success. |
| 22 | +3. Definition of Done: Explicitly state what files will **NOT** be touched to prevent scope creep. |
| 23 | +4. Non-goals & Constraints: What are we avoiding? |
| 24 | +5. Verification Plan: How will we prove it works? |
| 25 | +6. Security Review: Briefly scan input/output for injection risks or PII leaks. |
| 26 | + |
| 27 | +If you cannot write acceptance criteria, pause and clarify. |
| 28 | + |
| 29 | +#### Tool Usage |
| 30 | + |
| 31 | +- Repomix: Use to explore and pack the repository for full-structure views. |
| 32 | +- Context7: Use to acquire up-to-date, version-specific documentation for any library/API. |
| 33 | +- Vision MCP: Use for image understanding. |
| 34 | +- Playwright: Use for interactive browser-based E2E tests and UI debugging. |
| 35 | +- Web Search MCP or Web Reader MCP: Use to acquire latest documentations or information. |
| 36 | +- ZRead MCP: Use for documentation search, repository structure exploration, and code reading on GitHub. |
| 37 | +- GitHub CLI: Use `gh` for PR/Issue operations. |
| 38 | +- Offline Docs: Use `go doc` or `x --help` or `man x` or equivalences for accurate command references. |
| 39 | + |
| 40 | +### Verification Minimum |
| 41 | + |
| 42 | +Detect the environment and run the **strict** verification chain. If a `Makefile`, `Justfile`, or `Taskfile` exists, prioritize the below first and then apply standard targets after (e.g., `make check`, `just test`). |
| 43 | + |
| 44 | +E.g. Go Verification |
| 45 | + |
| 46 | +```bash |
| 47 | +go mod tidy && golangci-lint fmt && golangci-lint run --no-config --timeout=5m && CGO_ENABLED=1 go test ./... -race -cover --coverprofile=coverage.out && go tool cover -func coverage.out && CGO_ENABLED=1 go test -bench |
| 48 | +``` |
| 49 | + |
| 50 | +And for UI tasks: |
| 51 | + |
| 52 | +- If there's a `make screenshots` run it and check the output images in `./assets/` to verify the work with Vision MCP |
| 53 | +- If there's no such mechanism for self-verification, make such script using Playwright and do the check with Vision MCP |
| 54 | + |
| 55 | +### Context Hygiene |
| 56 | + |
| 57 | +If a conversation exceeds 64 turns or context becomes stale: |
| 58 | + |
| 59 | +1. Summarize: Create `checkpoint.md` capturing: Current Goal, Recent Changes, Next Immediate Step, List of Open Questions. |
| 60 | +2. Verify: Ensure `checkpoint.md` is committed. |
| 61 | +3. Reset: Instruct user to `/compact` (or clear context) and read `checkpoint.md`. |
| 62 | + |
| 63 | +### When Stuck (3 Failed Attempts) |
| 64 | + |
| 65 | +1. Stop coding. Return to last green state (git reset). |
| 66 | +2. Re-read requirements. Verify you are solving the RIGHT problem. |
| 67 | +3. Decompose into atomic TDD increments: Recursively break the feature into smallest testable units—one behavior or assertion per test. Each subtask targets a single red-green-refactor cycle (<10 lines of code), starting from the leaves (e.g., simplest function) and building up, to maintain steady progress and isolate failures. |
| 68 | +4. Constraint: You are forbidden from modifying the test logic to force a pass unless the Requirements Contract has changed. |
| 69 | +5. Spawn 2-8 parallel diagnostic tasks via Task tool. |
| 70 | +6. If still blocked → escalate to human with findings. |
| 71 | + |
| 72 | +### Parallel Exploration (Task Tool) |
| 73 | + |
| 74 | +Use for: uncertain decisions, codebase surveys, implementing and voting on approaches. |
| 75 | + |
| 76 | +- Cleanup: Use Git Worktree if necessary, but strictly ensure cleanup (`git worktree remove` and branch deletion) occurs regardless of success/failure via a `defer` or `trap` mechanism, or just standard branching if sufficient. |
| 77 | +- Independence: Paraphrase prompts for each agent to ensure cognitive diversity. |
| 78 | +- Voting: Prefer simpler, more testable proposals. |
| 79 | +- Consensus Protocol: When agents disagree, prioritize the solution with the fewest dependencies and highest test coverage. Discard "clever" solutions in favor of "boring" standard library usage. |
| 80 | + |
| 81 | +### Workflow Exception: Trivial Edits |
| 82 | + |
| 83 | +For simple typo fixes, comment updates, or one-line non-logic changes: |
| 84 | + |
| 85 | +1. Skip the "Requirements Contract." |
| 86 | +2. Run the linter/formatter only. |
| 87 | +3. Commit immediately. |
| 88 | + |
| 89 | +## Beware Language Specific Pitfalls |
| 90 | + |
| 91 | +E.g. Go |
| 92 | + |
| 93 | +- CGO_ENABLED=1: Always prefix Go commands with this (SQLite and Race Detection require CGO). |
| 94 | +- Gen Directories: Never edit `gen/`. Run `go generate`, `protoc`, or `sqlc` to regenerate. |
0 commit comments