haac-aikit 0.1.1 → 0.7.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (44) hide show
  1. package/README.md +169 -69
  2. package/catalog/agents/tier1/architect.md +86 -0
  3. package/catalog/agents/tier1/debugger.md +64 -0
  4. package/catalog/agents/tier1/pr-describer.md +57 -0
  5. package/catalog/agents/{researcher.md → tier1/researcher.md} +1 -1
  6. package/catalog/agents/tier2/changelog-curator.md +60 -0
  7. package/catalog/agents/tier2/dependency-upgrader.md +67 -0
  8. package/catalog/agents/tier2/evals-author.md +65 -0
  9. package/catalog/agents/tier2/flake-hunter.md +57 -0
  10. package/catalog/agents/tier2/prompt-engineer.md +58 -0
  11. package/catalog/agents/tier2/simplifier.md +57 -0
  12. package/catalog/ci/aikit-rules.yml +55 -0
  13. package/catalog/docs/claude-md-reference.md +316 -0
  14. package/catalog/hooks/block-dangerous-bash.sh +0 -0
  15. package/catalog/hooks/block-force-push-main.sh +0 -0
  16. package/catalog/hooks/block-secrets-in-commits.sh +0 -0
  17. package/catalog/hooks/check-pattern-violations.sh +137 -0
  18. package/catalog/hooks/compaction-preservation.sh +0 -0
  19. package/catalog/hooks/file-guard.sh +0 -0
  20. package/catalog/hooks/format-on-save.sh +0 -0
  21. package/catalog/hooks/hooks.json +38 -0
  22. package/catalog/hooks/judge-rule-compliance.sh +197 -0
  23. package/catalog/hooks/log-rule-event.sh +80 -0
  24. package/catalog/hooks/session-start-prime.sh +0 -0
  25. package/catalog/husky/commit-msg +0 -0
  26. package/catalog/husky/pre-commit +0 -0
  27. package/catalog/husky/pre-push +0 -0
  28. package/catalog/rules/AGENTS.md.tmpl +28 -7
  29. package/catalog/rules/aikit-rules.json +37 -0
  30. package/catalog/rules/claude-rules/example.md +38 -0
  31. package/catalog/skills/tier1/software-architect.md +42 -0
  32. package/dist/cli.mjs +1516 -173
  33. package/dist/cli.mjs.map +1 -1
  34. package/package.json +4 -2
  35. /package/catalog/agents/{devops.md → tier1/devops.md} +0 -0
  36. /package/catalog/agents/{implementer.md → tier1/implementer.md} +0 -0
  37. /package/catalog/agents/{orchestrator.md → tier1/orchestrator.md} +0 -0
  38. /package/catalog/agents/{planner.md → tier1/planner.md} +0 -0
  39. /package/catalog/agents/{reviewer.md → tier1/reviewer.md} +0 -0
  40. /package/catalog/agents/{security-auditor.md → tier1/security-auditor.md} +0 -0
  41. /package/catalog/agents/{tester.md → tier1/tester.md} +0 -0
  42. /package/catalog/agents/{backend.md → tier2/backend.md} +0 -0
  43. /package/catalog/agents/{frontend.md → tier2/frontend.md} +0 -0
  44. /package/catalog/agents/{mobile.md → tier2/mobile.md} +0 -0
@@ -0,0 +1,65 @@
1
+ ---
2
+ name: evals-author
3
+ description: Builds eval datasets (golden examples, edge cases, regressions) and a runner. Reports pass-rate deltas across prompt or model changes. Use when a feature has no eval coverage; pair with `prompt-engineer` for tuning.
4
+ model: claude-sonnet-4-6
5
+ tools:
6
+ - Read
7
+ - Edit
8
+ - Write
9
+ - Grep
10
+ - Bash
11
+ ---
12
+
13
+ # Evals Author
14
+
15
+ You build the regression net for LLM-powered features. Without you, prompt-engineer is flying blind.
16
+
17
+ ## Protocol
18
+
19
+ 1. **Map the feature.** Read the prompt, its inputs, and its callers. What does the feature claim to do? What's the contract?
20
+
21
+ 2. **Sample real-world inputs.** Look for:
22
+ - Inputs in test fixtures
23
+ - Logged inputs (with sensitive data redacted)
24
+ - Edge cases the team has hit (search commit messages and issue tracker)
25
+
26
+ 3. **Write the dataset.** A good eval set has:
27
+ - 5-10 golden examples (clear correct answers)
28
+ - 5-10 edge cases (ambiguity, incomplete input, hostile input)
29
+ - 1-3 known-bad cases that historically regressed
30
+
31
+ 4. **Build a runner.** It should:
32
+ - Read the dataset
33
+ - Call the feature
34
+ - Score each output (exact match, regex, LLM-as-judge — pick the cheapest scorer that works)
35
+ - Report pass-rate, per-case results, and a diff against the previous run
36
+
37
+ 5. **Wire it into CI** if the team is ready. If not, document how to run it locally and stop.
38
+
39
+ ## Constraints
40
+
41
+ - Datasets are checked into the repo. Sensitive inputs MUST be redacted.
42
+ - Runner must be deterministic (or pinned to a seed) so re-runs are comparable.
43
+ - Pass-rate alone is not enough — always preserve per-case results so regressions are findable.
44
+
45
+ ## Output format
46
+
47
+ ```
48
+ Eval set: [feature]
49
+
50
+ Cases: [N total — G golden, E edge, R regression]
51
+ Runner: [path]
52
+ Current pass-rate: X/N
53
+
54
+ Schema: [how a case is structured — input, expected, scorer]
55
+ ```
56
+
57
+ ## Handoff format
58
+
59
+ ```
60
+ [evals-author] → [prompt-engineer | orchestrator]
61
+ Summary: Built eval set for [feature], N cases
62
+ Artifacts: dataset path, runner path
63
+ Next: Tune prompt against this set
64
+ Status: DONE
65
+ ```
@@ -0,0 +1,57 @@
1
+ ---
2
+ name: flake-hunter
3
+ description: Identifies intermittent test failures, reproduces them via repeated runs, classifies the root cause (race, env-dependent, order-dependent), and recommends quarantine or fix. Use when a test fails non-deterministically; use `debugger` for reproducible bugs.
4
+ model: claude-sonnet-4-6
5
+ tools:
6
+ - Read
7
+ - Grep
8
+ - Glob
9
+ - Bash
10
+ ---
11
+
12
+ # Flake Hunter
13
+
14
+ You diagnose flaky tests. You do not edit code unless adding a `.skip` or quarantine annotation.
15
+
16
+ ## Protocol
17
+
18
+ 1. **Reproduce the flake.** Run the test 10-50 times with `for i in {1..50}; do <command>; done` and record pass/fail counts.
19
+
20
+ 2. **Classify the cause:**
21
+ - **Race condition** — pass-rate drops when run in parallel; passes serialised
22
+ - **Order-dependent** — fails only after specific other tests; passes when isolated
23
+ - **Env-dependent** — fails on certain machines, locales, or timezones
24
+ - **Time-dependent** — fails near minute/hour/day boundaries
25
+ - **External dependency** — requires network or other unstable resource
26
+
27
+ 3. **Recommend the smallest mitigation:**
28
+ - Race: add explicit await/synchronisation
29
+ - Order-dependent: reset shared state in `beforeEach`
30
+ - Env: pin the env in the test or skip on offending platforms
31
+ - Time: freeze the clock
32
+ - External: mock or move to integration suite
33
+
34
+ 4. **Quarantine if no fix is available.** Add `.skip` or `it.skip` with a comment linking to a tracking issue. Never delete the test silently.
35
+
36
+ ## Output format
37
+
38
+ ```
39
+ Flake report: [test name]
40
+
41
+ Pass rate: X/N runs ([percentage])
42
+ Classification: [race | order | env | time | external]
43
+ Evidence: [file:line — what shows it]
44
+
45
+ Recommended action: [fix | quarantine + issue]
46
+ Diff sketch: [the smallest change that helps]
47
+ ```
48
+
49
+ ## Handoff format
50
+
51
+ ```
52
+ [flake-hunter] → [implementer | orchestrator]
53
+ Summary: Classified flake in [test], pass-rate X%
54
+ Artifacts: report (inline)
55
+ Next: Apply recommended fix or quarantine
56
+ Status: DONE | DONE_WITH_CONCERNS
57
+ ```
@@ -0,0 +1,58 @@
1
+ ---
2
+ name: prompt-engineer
3
+ description: Authors and optimises prompts for LLM-powered features. Runs A/B comparisons against an eval set if one exists; documents the rationale. Use when a prompt is unreliable or new; pair with `evals-author` to build a regression net first.
4
+ model: claude-opus-4-7
5
+ tools:
6
+ - Read
7
+ - Edit
8
+ - Write
9
+ - Grep
10
+ - Bash
11
+ ---
12
+
13
+ # Prompt Engineer
14
+
15
+ You write and tune prompts. Your work is high-leverage and silent failures are common — small wording changes can shift quality without surfacing in tests. Discipline matters.
16
+
17
+ ## Protocol
18
+
19
+ 1. **Define the goal.** What should the prompt produce, given which inputs, with which constraints? If unclear, ask before writing.
20
+
21
+ 2. **Find the eval set.** Look for `evals/`, `tests/prompts/`, or similar. If none exists, hand back to `evals-author` to build one before optimising — tuning without an eval is dead reckoning.
22
+
23
+ 3. **Write the candidate prompt.** Apply 2026 best practices:
24
+ - Lead with role and goal
25
+ - Be specific about output format (JSON schema, line-by-line structure, etc.)
26
+ - Use examples when patterns are non-obvious
27
+ - Show, don't tell — `<example>...</example>` beats "be concise"
28
+ - Avoid negation when possible — "respond in 3 bullets" beats "don't be verbose"
29
+
30
+ 4. **A/B test against the current prompt.** Run both against the eval set. Report pass-rate delta, regressions, and the most informative diff (where they disagree).
31
+
32
+ 5. **Document the rationale.** Append a comment block to the prompt explaining why it's worded the way it is. Future readers (including future you) need to know what's load-bearing.
33
+
34
+ ## Output format
35
+
36
+ ```
37
+ Prompt change: [feature]
38
+
39
+ Pass-rate: old [X%] → new [Y%] (Δ = +/-Z%)
40
+ Regressions: [list of cases that newly fail]
41
+ Cost change: [approx tokens/call before vs after]
42
+
43
+ Diff: [old → new, with rationale]
44
+ ```
45
+
46
+ ## Handoff format
47
+
48
+ ```
49
+ [prompt-engineer] → [user | reviewer]
50
+ Summary: Optimised [feature] prompt, +Z% pass-rate
51
+ Artifacts: prompt file, eval results
52
+ Next: Review and merge
53
+ Status: DONE | DONE_WITH_CONCERNS
54
+ ```
55
+
56
+ ## Rules
57
+ - Never ship a prompt change without an eval result. "Looks better to me" is not evidence.
58
+ - Document every load-bearing choice. Wording that seems arbitrary is the first thing that gets reverted.
@@ -0,0 +1,57 @@
1
+ ---
2
+ name: simplifier
3
+ description: Finds DRY violations, dead exports, and over-abstraction. Proposes diffs with before/after; verifies tests still pass. Use when code feels heavy; use `reviewer` to flag issues without editing.
4
+ model: claude-sonnet-4-6
5
+ tools:
6
+ - Read
7
+ - Edit
8
+ - Grep
9
+ - Glob
10
+ - Bash
11
+ ---
12
+
13
+ # Simplifier
14
+
15
+ You reduce code without changing behaviour. Tests are your safety net.
16
+
17
+ ## Protocol
18
+
19
+ 1. **Find redundancy.** Look for:
20
+ - Repeated logic across 3+ sites that could be a helper
21
+ - Functions called only from one place that could be inlined
22
+ - Dead exports (re-exports never imported, deprecated wrappers)
23
+ - Boilerplate that can be replaced with a library primitive
24
+
25
+ 2. **Estimate the size of the win.** Before editing, count: lines removed, files touched, test changes required. If the win is < 5 lines or > 100 lines, reconsider — the first is too small, the second is a refactor that needs its own plan.
26
+
27
+ 3. **Apply the smallest change.** One simplification per commit. Do not bundle.
28
+
29
+ 4. **Verify the test suite still passes.** Run the full suite. If a test breaks, you may have changed behaviour — revert, do not adjust the test.
30
+
31
+ ## Constraints
32
+
33
+ - Behaviour must not change. If a simplification would alter return values, error messages, or timing, stop and flag it.
34
+ - Do not rename public APIs.
35
+ - Do not delete code marked with `// keep` or referenced in `AGENTS.md` / `CLAUDE.md`.
36
+
37
+ ## Output format
38
+
39
+ ```
40
+ Simplification: [scope]
41
+
42
+ Removed: [N lines across M files]
43
+ Net behaviour change: none (verified by [test command])
44
+
45
+ Diffs:
46
+ - file:line — [what + why]
47
+ ```
48
+
49
+ ## Handoff format
50
+
51
+ ```
52
+ [simplifier] → [reviewer | orchestrator]
53
+ Summary: Simplified [scope], -N lines, tests green
54
+ Artifacts: [files modified]
55
+ Next: Review for regressions
56
+ Status: DONE | DONE_WITH_CONCERNS
57
+ ```
@@ -0,0 +1,55 @@
1
+ name: aikit rule observability
2
+
3
+ # Posts (or updates) a sticky PR comment with the aikit rule-adherence report.
4
+ # Requires .aikit/events.jsonl to be present in the PR branch (or downloadable
5
+ # from a previous job artifact). Customise the "Fetch telemetry" step to suit
6
+ # how your team aggregates events across runs.
7
+
8
+ on:
9
+ pull_request:
10
+ branches: [main]
11
+
12
+ permissions:
13
+ contents: read
14
+ pull-requests: write
15
+
16
+ jobs:
17
+ rule-report:
18
+ runs-on: ubuntu-latest
19
+ steps:
20
+ - uses: actions/checkout@v4
21
+
22
+ - uses: actions/setup-node@v4
23
+ with:
24
+ node-version: "20"
25
+
26
+ - name: Install haac-aikit
27
+ run: npm install -g haac-aikit
28
+
29
+ # CUSTOMISE: point this at wherever your team stores rolled-up telemetry.
30
+ # Examples: download an artifact, restore from cache, pull from S3.
31
+ - name: Fetch telemetry
32
+ run: |
33
+ mkdir -p .aikit
34
+ if [ -f .aikit/events.jsonl ]; then
35
+ echo "Using committed telemetry."
36
+ else
37
+ echo "No telemetry found — report will say 'no_telemetry'."
38
+ touch .aikit/events.jsonl
39
+ fi
40
+
41
+ - name: Generate rule-adherence report
42
+ id: report
43
+ run: |
44
+ aikit report --format=markdown > /tmp/aikit-report.md
45
+ {
46
+ echo 'report<<HAAC_EOF'
47
+ cat /tmp/aikit-report.md
48
+ echo HAAC_EOF
49
+ } >> "$GITHUB_OUTPUT"
50
+
51
+ - name: Post or update sticky PR comment
52
+ uses: marocchino/sticky-pull-request-comment@v2
53
+ with:
54
+ header: aikit-rule-observability
55
+ message: ${{ steps.report.outputs.report }}
@@ -0,0 +1,316 @@
1
+ # CLAUDE.md & Memory Configuration Reference (2026)
2
+
3
+ > A condensed, citation-backed reference for everything Anthropic's official docs say
4
+ > about `CLAUDE.md`, auto memory, `.claude/rules/`, and related settings. Pulled from
5
+ > the canonical 2026 sources listed at the bottom. Shipped by `haac-aikit` so your
6
+ > contributors have one place to look up how Claude Code reads your project's rules.
7
+
8
+ ---
9
+
10
+ ## 1. The two memory systems
11
+
12
+ Claude Code has two complementary persistence layers, both loaded at session start:
13
+
14
+ | | **CLAUDE.md** | **Auto memory** |
15
+ |---|---|---|
16
+ | Author | You | Claude |
17
+ | Content | Instructions, rules, conventions | Learnings, patterns Claude infers |
18
+ | Scope | Project / user / organisation | Per working tree (per git repo) |
19
+ | Loaded | Every session, in full | Every session, first 200 lines / 25 KB of `MEMORY.md` |
20
+ | Use for | Coding standards, workflows, project architecture | Build commands, debugging insights, preferences Claude discovers |
21
+
22
+ > "Use CLAUDE.md files when you want to guide Claude's behavior. Auto memory lets
23
+ > Claude learn from your corrections without manual effort." — *memory docs*
24
+
25
+ Source: [memory docs §CLAUDE.md vs auto memory](https://code.claude.com/docs/en/memory)
26
+
27
+ ---
28
+
29
+ ## 2. CLAUDE.md scopes (highest specificity first)
30
+
31
+ | Scope | Location | Shared? | Use for |
32
+ |---|---|---|---|
33
+ | **Managed policy** | macOS `/Library/Application Support/ClaudeCode/CLAUDE.md` · Linux/WSL `/etc/claude-code/CLAUDE.md` · Windows `C:\Program Files\ClaudeCode\CLAUDE.md` | Org-wide; cannot be excluded | Compliance, security policies |
34
+ | **Project** | `./CLAUDE.md` **or** `./.claude/CLAUDE.md` | Team via git | Architecture, code style, workflows |
35
+ | **User** | `~/.claude/CLAUDE.md` | You only (every project) | Personal preferences |
36
+ | **Local** | `./CLAUDE.local.md` | You only (gitignored) | Sandbox URLs, test data |
37
+
38
+ All discovered files are **concatenated** (not overridden). Within each directory,
39
+ `CLAUDE.local.md` is appended after `CLAUDE.md`, so personal notes win on conflict.
40
+
41
+ Source: [memory docs §Choose where to put CLAUDE.md files](https://code.claude.com/docs/en/memory)
42
+
43
+ ---
44
+
45
+ ## 3. How files are discovered (the load order)
46
+
47
+ 1. Walk **up** the directory tree from the working dir; load every `CLAUDE.md`
48
+ and `CLAUDE.local.md` along the way **at launch**.
49
+ 2. Files in **subdirectories** below the working dir are discovered too, but load
50
+ **on demand** when Claude reads a file in that subdir.
51
+ 3. **Imports** (`@path`) are expanded transitively, max **5 hops** depth. Relative
52
+ paths resolve to the file containing the import, not the cwd.
53
+ 4. Block-level `<!-- HTML comments -->` are **stripped before injection** — free
54
+ maintainer notes that don't cost tokens. (Comments inside fenced code blocks are kept.)
55
+
56
+ Source: [memory docs §How CLAUDE.md files load](https://code.claude.com/docs/en/memory#how-claude-md-files-load)
57
+
58
+ ---
59
+
60
+ ## 4. Imports (`@path` syntax)
61
+
62
+ ```markdown
63
+ See @README.md for project overview and @package.json for npm commands.
64
+
65
+ # Additional Instructions
66
+ - Git workflow: @docs/git-instructions.md
67
+ - Personal overrides: @~/.claude/my-project-instructions.md
68
+ ```
69
+
70
+ - Both relative and absolute paths allowed; `~/` expands.
71
+ - Recursive imports allowed up to **5 hops**.
72
+ - ⚠️ **Imports do NOT reduce context size** — imported files load in full at
73
+ launch. Use imports for *organisation*, not for token savings. For real
74
+ load-on-demand, use `.claude/rules/` with `paths:` frontmatter (§6) or skills.
75
+ - First time Claude encounters external imports, an approval dialog appears.
76
+
77
+ Source: [memory docs §Import additional files](https://code.claude.com/docs/en/memory#import-additional-files)
78
+
79
+ ---
80
+
81
+ ## 5. AGENTS.md interop (cross-tool)
82
+
83
+ Claude Code reads `CLAUDE.md`, **not** `AGENTS.md`. The official pattern when you
84
+ already use `AGENTS.md` for Cursor/Copilot/Codex/etc.:
85
+
86
+ ```markdown
87
+ # CLAUDE.md
88
+ @AGENTS.md
89
+
90
+ ## Claude Code
91
+ Use plan mode for changes under `src/billing/`.
92
+ ```
93
+
94
+ This is exactly what `haac-aikit` writes by default: `AGENTS.md` is canonical
95
+ (under BEGIN/END markers so re-runs are idempotent), and `CLAUDE.md` is a thin
96
+ shim that imports it plus an empty override block for Claude-specific rules.
97
+
98
+ Source: [memory docs §AGENTS.md](https://code.claude.com/docs/en/memory#agents-md)
99
+
100
+ ---
101
+
102
+ ## 6. `.claude/rules/` — modular, optionally path-scoped
103
+
104
+ The 2026 successor to monolithic CLAUDE.md for larger projects. Place markdown
105
+ files in `.claude/rules/`; each covers one topic.
106
+
107
+ ```text
108
+ your-project/
109
+ ├── .claude/
110
+ │ ├── CLAUDE.md
111
+ │ └── rules/
112
+ │ ├── code-style.md # always loaded
113
+ │ ├── markers.md # path-scoped — only loads when relevant
114
+ │ └── frontend/api.md # nested dirs supported
115
+ ```
116
+
117
+ ### Path-scoped rules (the killer feature)
118
+
119
+ ```markdown
120
+ ---
121
+ paths:
122
+ - "src/api/**/*.ts"
123
+ - "test/api/**/*.test.ts"
124
+ ---
125
+
126
+ # API rules
127
+ - All endpoints must validate input at the boundary...
128
+ ```
129
+
130
+ Rules without `paths:` frontmatter load unconditionally. Path-scoped rules load
131
+ **only when Claude reads a matching file**, saving context. Glob patterns and
132
+ brace expansion supported.
133
+
134
+ Symlinks work (and circular symlinks are detected) — useful for sharing rules
135
+ across multiple repos.
136
+
137
+ User-level rules in `~/.claude/rules/` apply to all projects on your machine.
138
+
139
+ `haac-aikit` ships a starter `example.md` at `.claude/rules/example.md` (when
140
+ `claude` is selected and scope ≥ standard) — customise or delete it.
141
+
142
+ Source: [memory docs §Organize rules with .claude/rules/](https://code.claude.com/docs/en/memory#organize-rules-with-claude/rules/)
143
+
144
+ ---
145
+
146
+ ## 7. Auto memory
147
+
148
+ - **Storage**: `~/.claude/projects/<project>/memory/MEMORY.md` + topic files.
149
+ `<project>` is derived from the git repo, so all worktrees share one dir.
150
+ - **Loaded**: first 200 lines or 25 KB of `MEMORY.md` (topic files load on demand).
151
+ - **Toggle**: `/memory` command, `autoMemoryEnabled: false` in settings, or
152
+ `CLAUDE_CODE_DISABLE_AUTO_MEMORY=1`.
153
+ - **Custom location**: `autoMemoryDirectory` (user/local/policy settings only —
154
+ **not** project settings, to prevent shared repos redirecting writes).
155
+ - **Requires** Claude Code v2.1.59+.
156
+ - Files are plain markdown — edit or delete freely.
157
+
158
+ Source: [memory docs §Auto memory](https://code.claude.com/docs/en/memory#auto-memory)
159
+
160
+ ---
161
+
162
+ ## 8. Settings & flags reference
163
+
164
+ | Setting / flag | Where | What it does |
165
+ |---|---|---|
166
+ | `claudeMdExcludes` | any settings layer | Glob list of CLAUDE.md paths to skip (managed policy CLAUDE.md cannot be excluded). |
167
+ | `autoMemoryEnabled` | project / user / local | Boolean. Toggle auto memory. |
168
+ | `autoMemoryDirectory` | user / local / policy (not project) | Custom auto-memory dir. |
169
+ | `CLAUDE_CODE_DISABLE_AUTO_MEMORY` | env var | Disable auto memory. |
170
+ | `CLAUDE_CODE_NEW_INIT=1` | env var | Enable interactive multi-phase `/init`. |
171
+ | `CLAUDE_CODE_ADDITIONAL_DIRECTORIES_CLAUDE_MD=1` | env var | Load CLAUDE.md from `--add-dir` paths. |
172
+ | `--append-system-prompt` | CLI flag | System-prompt-level instructions (must pass each invocation). |
173
+ | `--setting-sources` | CLI flag | Control which settings layers apply at startup. |
174
+ | `InstructionsLoaded` hook | `.claude/settings.json` | Fires when instruction files load — useful for debugging. |
175
+ | `/init` | slash command | Auto-generate starter CLAUDE.md from codebase analysis. |
176
+ | `/memory` | slash command | List loaded memory files; toggle auto memory. |
177
+ | `#` prefix | prompt shortcut | Quick-add a memory entry from the prompt line. |
178
+
179
+ Source: [memory docs](https://code.claude.com/docs/en/memory) · [settings docs](https://code.claude.com/docs/en/settings) · [best-practices](https://code.claude.com/docs/en/best-practices)
180
+
181
+ ---
182
+
183
+ ## 9. Writing effective CLAUDE.md (Anthropic best practices, 2026)
184
+
185
+ ### Size
186
+ > "target under 200 lines per CLAUDE.md file. Longer files consume more context
187
+ > and reduce adherence."
188
+
189
+ ### Specificity
190
+ > "Use 2-space indentation" beats "format code properly". Concrete, verifiable
191
+ > rules outperform abstract ones.
192
+
193
+ ### Emphasis
194
+ > "You can tune instructions by adding emphasis (e.g., 'IMPORTANT' or 'YOU MUST')
195
+ > to improve adherence."
196
+
197
+ ### What to include vs exclude
198
+
199
+ | ✅ Include | ❌ Exclude |
200
+ |---|---|
201
+ | Bash commands Claude can't guess | Anything Claude can figure out by reading code |
202
+ | Code style rules that differ from defaults | Standard language conventions |
203
+ | Test runner & how to run a single test | Detailed API docs (link to docs instead) |
204
+ | Repo etiquette (branches, PR conventions) | Information that changes frequently |
205
+ | Architectural decisions specific to project | Long explanations or tutorials |
206
+ | Dev-environment quirks (required env vars) | File-by-file descriptions of the codebase |
207
+ | Common gotchas / non-obvious behaviors | Self-evident practices like "write clean code" |
208
+
209
+ ### The pruning test
210
+ > "For each line, ask: *Would removing this cause Claude to make mistakes?* If
211
+ > not, cut it. Bloated CLAUDE.md files cause Claude to ignore your actual
212
+ > instructions."
213
+
214
+ ### Compaction
215
+ - **Project-root CLAUDE.md / AGENTS.md survives `/compact`** — re-injected from disk.
216
+ - **Nested CLAUDE.md files are NOT re-injected** until Claude reads a file in
217
+ that subdir again.
218
+ - You can hint preservation explicitly:
219
+ > `When compacting, always preserve the full list of modified files and any test commands`
220
+
221
+ Sources: [best-practices §Write an effective CLAUDE.md](https://code.claude.com/docs/en/best-practices#write-an-effective-claude-md) · [memory docs §Write effective instructions](https://code.claude.com/docs/en/memory#write-effective-instructions) · [context-window §What survives compaction](https://code.claude.com/docs/en/context-window#what-survives-compaction)
222
+
223
+ ---
224
+
225
+ ## 10. What `haac-aikit` ships by default
226
+
227
+ When you run `npx haac-aikit init` and select `claude` as a tool:
228
+
229
+ | File | Always | Standard+ scope only | Notes |
230
+ |---|---|---|---|
231
+ | `AGENTS.md` | ✓ | | Canonical, marker-managed, idempotent on `sync`. |
232
+ | `CLAUDE.md` | ✓ | | 5-line `@AGENTS.md` shim with empty override block. |
233
+ | `.claude/settings.json` | ✓ | | Permissions allow/deny/ask matrix. |
234
+ | `docs/claude-md-reference.md` | | ✓ | This file. Reference for your team. |
235
+ | `.claude/rules/example.md` | | ✓ | Starter path-scoped rule — customise or delete. |
236
+ | `.claude/aikit-rules.json` | | ✓ | Pattern-check config for the observability hooks. |
237
+ | `.claude/hooks/log-rule-event.sh` | | ✓ | InstructionsLoaded telemetry — logs which rule IDs loaded. |
238
+ | `.claude/hooks/check-pattern-violations.sh` | | ✓ | PostToolUse pattern check — logs violations from `aikit-rules.json`. |
239
+ | `.claude/hooks/judge-rule-compliance.sh` | | ✓ | Opt-in LLM judge (Stop/SubagentStop). Requires `AIKIT_JUDGE=1` + `ANTHROPIC_API_KEY`. |
240
+
241
+ `AGENTS.md` is the single source of truth, automatically read by Cursor,
242
+ Copilot, Codex, Aider, Gemini CLI, Windsurf, and Claude Code.
243
+
244
+ ---
245
+
246
+ ## 11. haac-aikit extensions on top of Anthropic's standard features
247
+
248
+ The standard CLAUDE.md / `.claude/rules/` mechanism is one-way: you write rules, Claude reads them, you hope. haac-aikit adds three feedback loops on top.
249
+
250
+ ### 11.1 Rule IDs
251
+
252
+ Add a stable HTML-comment ID next to any rule:
253
+
254
+ ```markdown
255
+ - <!-- id: code-style.no-any --> Use `unknown` and type guards, not `any`.
256
+ ```
257
+
258
+ The ID format is `topic.slug`: must start with a letter and contain at least one dot. The HTML comment is stripped before injection (zero context cost). The shipped hooks reference these IDs to log when each rule loaded and when it was violated.
259
+
260
+ Optional metadata (read by the dialect translators, not by Claude itself):
261
+
262
+ - `emphasis=high` — translators wrap the rule in **bold** for tools that respond to emphasis tokens (Claude, Cursor).
263
+ - `paths=src/**/*.ts,test/**` — translators surface this as Cursor's `globs:` frontmatter or Claude's `paths:` frontmatter. Comma-separated globs.
264
+
265
+ ```markdown
266
+ - <!-- id: code-style.no-any emphasis=high paths=src/**/*.ts --> Use `unknown` and type guards, not `any`.
267
+ ```
268
+
269
+ ### 11.2 The `.aikit/events.jsonl` telemetry log
270
+
271
+ Three hooks append to this file (auto-gitignored):
272
+
273
+ - `log-rule-event.sh` runs on `InstructionsLoaded`. Scans loaded files for rule IDs and writes one `{event:"loaded"}` per ID per session.
274
+ - `check-pattern-violations.sh` runs on `PostToolUse(Edit|Write)`. Reads `.claude/aikit-rules.json` and writes `{event:"violation"}` per pattern hit.
275
+ - `judge-rule-compliance.sh` runs on `Stop` and `SubagentStop`. **Opt-in**: requires both `AIKIT_JUDGE=1` and `ANTHROPIC_API_KEY`. Calls Claude Haiku and writes `{event:"cited"}` or `{event:"judged_violation"}` per loaded rule per turn (~$0.001/turn).
276
+
277
+ Run `aikit doctor --rules` to see hot/disputed/dead/unmatched buckets, or `aikit report` for a Markdown summary.
278
+
279
+ ### 11.3 Adherence semantics
280
+
281
+ `aikit report --format=json` returns one of two shapes.
282
+
283
+ When the LLM judge has produced `cited` events:
284
+
285
+ ```json
286
+ { "adherence_score": 87, "adherence_basis": "judge", ... }
287
+ ```
288
+
289
+ The score is `cited / (cited + violations + judged_violations)` percent.
290
+
291
+ When no `cited` events exist (judge disabled or never fired):
292
+
293
+ ```json
294
+ { "adherence_score": null, "adherence_basis": "no-evidence", ... }
295
+ ```
296
+
297
+ `loaded` events are **not** counted as positive evidence. A file being scanned isn't proof a rule was followed.
298
+
299
+ ### 11.4 Privacy
300
+
301
+ All telemetry is local. `.aikit/events.jsonl` is auto-added to `.gitignore`. Nothing leaves your machine unless you explicitly opt into the LLM judge — and even then, the judge calls the Anthropic API only with your own key, only on `Stop` events, with the assistant transcript capped at 8000 chars.
302
+
303
+ Errors from the judge land in a sibling `.aikit/judge-errors.log` so you can see why a turn produced no verdicts (HTTP status, parse failure, etc.).
304
+
305
+ ---
306
+
307
+ ## Sources
308
+
309
+ - [How Claude remembers your project (memory docs)](https://code.claude.com/docs/en/memory) — primary canonical reference for CLAUDE.md, auto memory, `.claude/rules/`, imports, scopes, load order, settings.
310
+ - [Best Practices for Claude Code](https://code.claude.com/docs/en/best-practices) — `/init`, emphasis tuning, include/exclude table, pruning heuristic.
311
+ - [Settings reference](https://code.claude.com/docs/en/settings) — `autoMemoryEnabled`, `autoMemoryDirectory`, `claudeMdExcludes`, env vars.
312
+ - [Context window](https://code.claude.com/docs/en/context-window) — what survives `/compact`.
313
+ - [Skills](https://code.claude.com/docs/en/skills) — when to use a skill instead of CLAUDE.md content.
314
+ - [Hooks](https://code.claude.com/docs/en/hooks) — `InstructionsLoaded` hook for debugging memory loads.
315
+
316
+ _Shipped by haac-aikit. Last refreshed: 2026-04-29._
File without changes
File without changes
File without changes