AI Agent Core Rules
VERSION HISTORY
- v3.0 CURRENT New §9 Skills & §10 Database Safety; §6 expanded (conditional TDD, RED-GREEN, worktree-as-gate); §4 scopes staging by worktree blast radius; §7 adds an intent-recognition gate.
- v2.5 2026-06-06 Workflow reworked for proportionality (process scales to the task); TDD retargeted to where behavior lives; operator-owned git staging made explicit.
- v2.0 2025-12-27 Restructured into 8 sections; added Workflow (TDD, file-based issues, ADRs); hard blocks delegated to Claude Code permissions + hooks.
- v1.0 2025-12-27 Initial release — 7-section ruleset.
ARCHIVED VERSION · v2.0
View current versionA battle-tested ruleset for configuring AI coding agents like Claude, Gemini, Cursor, Windsurf, or Copilot. These rules establish consistent code quality, safety practices, and developer experience standards.
Tuned for Claude Code, portable everywhere. Sections 1–8 are stack- and agent-agnostic. Two pieces assume Claude Code specifically: the preamble delegates hard blocks to
settings.jsonpermissions + PreToolUse hooks, and §7 routes decisions through the/adr-writerskill (against anadr-spec.md). On Gemini, Cursor, or Copilot, read those as intent and wire up your platform’s equivalent — or drop them.
Use Case
Add this to your project’s root as:
CLAUDE.md(Anthropic Claude, Claude Code, Cursor)GEMINI.md(Google AI Studio, Gemini)AGENTS.md(Generic, Codex, Windsurf).cursorrules(Cursor IDE)
The AI will read these rules and apply them to all generated code.
Features
- Code: Semantic naming, immutability, why-not-what comments, stdlib-first dependencies
- Type Safety: No type escapes, boundary validation, honest external types
- Shell & Filesystem: Scoped paths, verified destructive ops,
rg/fdsearch - Git: Conventional commits, staged-only discipline
- Change Discipline: Root-cause diagnosis, blast-radius sweeps, reversibility checks
- Testing: Right-level coverage, critical paths, determinism
- Workflow: TDD by default, file-based backlog, immutable ADRs
- Tools & MCP: Rigid schemas, structured errors, least privilege
The Ruleset
# Core Development Standards
*Assumes a capable agent. Routine craft (clarity, decomposition, root-cause analysis) is expected by default, not restated. Hard blocks on destructive/irreversible actions live in settings.json permissions + PreToolUse hooks — never trusted to this file.*
## 1. Code- **Naming:** Booleans read as predicates, functions as verbs; follow the language's idiomatic casing.- **Immutability:** Prefer immutable bindings and pure functions; isolate side effects.- **Comments:** Explain *why*, never narrate *what*.- **Dependencies:** Standard library first; justify every new dependency.
## 2. Type Safety- **No escapes:** Where strict typing is available, never suppress type-checker errors or use unsafe casts/assertions — fix the cause or type it correctly.- **Boundaries:** Validate at every external boundary (API, DAL, I/O) for runtime safety.- **External types:** Extend or declare missing third-party types; never weaken your own types to paper over a library gap.
## 3. Shell & Filesystem- **Search:** `rg` for content, `fd` for files (both respect .gitignore). With bare `find`, always exclude `node_modules`/`.git`.- **Scope:** Stay inside the workspace — no absolute paths, no `../` escapes.- **Destructive ops:** List and verify targets before any delete/overwrite.
## 4. Git- **Commits:** Conventional Commits — `<type>(<scope>): <subject>`, lowercase imperative, no trailing period.- **Staged only:** Commit exactly what is staged; never `add -A` unreviewed changes.
## 5. Change Discipline- **Root cause:** Diagnose *why* before fixing; no band-aids over symptoms.- **Blast radius:** On rename/migrate, sweep the whole codebase for affected call sites.- **Reversibility:** Surface assumptions and tradeoffs; confirm before wide-reaching or irreversible changes.
## 6. Testing- **Right level:** Match Unit/Integration/E2E to the stack and project phase.- **Critical paths:** Core business logic is always covered.- **Determinism:** No flaky tests.
## 7. Workflow- **TDD by default:** Write the failing test that specifies the behavior first, then implement to green, then refactor. The test defines "done"; spikes are the only exception and are thrown away.- **Deferring work:** When asked to park or postpone, capture it as a file-based issue — never an inline `TODO` or half-finished code. Issues are the backlog's source of truth.- **Decisions → ADR:** Architectural decisions go through the `/adr-writer` skill against `adr-spec.md`, strictly — never ad hoc. ADRs are immutable: a changed decision is a new ADR marked `Superseded`, never an edit to an accepted one. The skill gates significance — not every choice warrants an ADR.
## 8. Tools & MCP — *only when authoring tools/servers*- Rigid I/O schemas; structured, actionable errors (never raw stack traces).- Least privilege; write-ops idempotent or explicitly confirmable.Why This Matters
Without explicit rules, AI agents:
- ❌ Use
anytypes freely - ❌ Run dangerous shell commands
- ❌ Create messy commit messages
- ❌ Apply band-aid fixes without understanding the root cause
- ❌ Leave decisions and deferred work undocumented
With these rules:
- ✅ Consistent, type-safe code
- ✅ Scoped, verified shell operations
- ✅ Clean, conventional git history
- ✅ Root-cause debugging and a test-first workflow
- ✅ Traceable decisions (ADRs) and a file-based backlog
Customization Tips
- Add project-specific rules at the end
- Include tech stack preferences (React, Astro, etc.)
- Define forbidden patterns for your codebase
- Specify testing frameworks you use
- On Claude Code, enforce the hard blocks — back destructive/irreversible guards with
settings.jsonpermissions and PreToolUse hooks. The ruleset states intent; hooks make it non-negotiable.