diff --git a/.claude/memory/journal.md b/.claude/memory/journal.md
index bb16c1f..5ecd879 100644
--- a/.claude/memory/journal.md
+++ b/.claude/memory/journal.md
@@ -661,3 +661,4 @@ rules:
## 2026-10-27
- Phase 0 split STEP 6: opus/xhigh review 0 Critical 2 Important 8 Minor (extract rc 0 on failed rewrite; `###` granularity for faunosteo = 0b decision, TODO) → 0b59687, re-review 0 open, make test all GREEN. Capitalized BDR-128, LRN-232/233, EVAL-051. Next: doc-sync, merge on user go; user step still pending: `claude mcp remove -s user higgsfield`.
+- /feat rules-h3-extract (feature/rules-h3-extract): extract takes `'### title'`, sections --depth 3, split S4/S0 rows; 3 lenses SOLID/CONCERNS(2)/CONCERNS(1) + confirmation FATAL(2) (LC_COLLATE glob order, re-emission leaked to ##) → r3; feater DONE 116/116; GATE 0 MET; verifier ECARTS(1 floor: SC2016 suppression) → CONFORME 8/8; auditor PASS (3 pre-existing MEDIUM queued); ab5049e. LRN-234. Merge on user go, then 0b.
diff --git a/.claude/memory/learnings.md b/.claude/memory/learnings.md
index 0a5c7b0..0578dba 100644
--- a/.claude/memory/learnings.md
+++ b/.claude/memory/learnings.md
@@ -249,6 +249,7 @@ rules:
| LRN-227 | 2026-10-23 | Root-commit author ≠ name the user remembers: check `git log --max-parents=0`; every root email the user ever used goes in `claude.identity` | code-origin claims, identity lists |
| LRN-232 | 2026-10-27 | Path rules load inside sub-agents (agent_id in hook log); a "does X load" proof prompt must name the Read tool call | per-repo split pass, any load proof |
| LRN-233 | 2026-10-27 | Bash under pipefail: head after producer = rc 141, blanked PATH hides bash (rc 127), unchecked mktemp+rewrite chain = rc 0 with source unchanged; compgen -G no braces, dotglob over-matches, globstar skips symlinks under ** | any bash lib with pipes, temp files, globs |
+| LRN-234 | 2026-10-27 | Bash glob order follows LC_COLLATE, make test pins no locale: tests count or name files, never assert a listing; a new-case behaviour fix is gated on the case and proven by an old-vs-new differential on real files | any test listing a dir; any change to a lib with an existing output contract |
---
@@ -1917,3 +1918,7 @@ Rule: when editing a doctrine file under structure locks, grep the test's lock s
## LRN-233 — Bash under pipefail: `head` after a producer, blanked PATH, unchecked temp-file rewrite
- **Context**: `lib/project-rules.sh` 2026-10-26, caught by plan challenger r2 + opus review after 2 sonnet reviews. (1) `compgen -G '**/*' | head -3` → producer SIGPIPE on > pipe buffer of hits, pipeline rc 141 under `pipefail`. (2) `PATH=/nonexistent bash hook.sh` → rc 127: blank PATH applies to the lookup of `bash` itself. (3) `tmp=$(mktemp); f > "$tmp" && cat "$tmp" > src` unchecked → `TMPDIR=/nonexistent` gives rc 0, "moved" printed, src unchanged (I/O failure path untested by 5 reviewers). (4) `compgen -G`: no brace expansion; dotglob matches dotfiles the engine skips; globstar never descends a symlink met under `**` (`top/link/**` finds, `top/**` misses).
- **Apply**: a bounded reader after a producer is awk, reads to the end: `awk 'NR <= 3 { print } END { exit NR == 0 }'`. `"$BASH"` when PATH is blanked in a test. `tmp=$(mktemp) || return 2`; rewrite as `if ! { f > "$tmp" && cat "$tmp" > src; }; then rm -f "$tmp" "$out"; return 2; fi` (SC2015 forbids `a && b || c`). Plan Review Focus: one failure-path test per file-rewriting function (`TMPDIR=/nonexistent`, `chmod a-w`; root ignores chmod). One glob per extension; test names say what they prove (a guard the final `exit 0` swallows is unobservable). Links [[BDR-128]], [[LRN-096]].
+
+## LRN-234 — Glob order follows LC_COLLATE; gate a new-case fix on the case, prove the old contract by differential
+- **Context**: feat rules-h3-extract 2026-10-27. Confirmation challenger ran the planned suite under en_US.UTF-8: `printf '%s ' *` gave `sub2.md sub.md `, want `sub.md sub2.md ` (punctuation ignored in UTF-8 collation; C order differs). `make test` (Makefile) pins no `LC_ALL`. Same pass: `###` separator re-emission written as `RLENGTH - 1 < lvl` also fired for `##` ended by an H1 → 5 of 2,162 `##` extracts on this repo's md files changed vs develop, against the immutable REQUEST "`##` behaviour unchanged"; the suite (T7-T13) stayed green either way.
+- **Apply**: a test never asserts a glob listing order: count (`printf '%s\n' * | wc -l`), name files, or pin `LC_ALL=C` in the recipe. A fix for a new case is gated on that case (`lvl == 3 && …`) so the existing contract stays byte-identical, and the proof is an old-vs-new differential on real inputs (every `##` of every tracked md), not the suite alone. Also: a `# shellcheck disable` in a diff trips the floor guard unless the contract authorizes it; build the offending literal instead (`printf '\140\140\140'` for backticks). Links [[LRN-233]], [[BDR-128]], [[LRN-096]].
diff --git a/.claude/tasks/TODO.md b/.claude/tasks/TODO.md
index 2f3eff3..e9ae187 100644
--- a/.claude/tasks/TODO.md
+++ b/.claude/tasks/TODO.md
@@ -22,7 +22,8 @@ Shared rules for every phase:
- [ ] User step: `claude mcp remove -s user higgsfield` (user-scope MCP, no toggle ownership, no doctor check; phase 5 `.mcp.json` owns it).
- [ ] Phase 2 folds: narrow the pre-commit `.claude/**` exemption so a rules-only commit cannot land on develop/main (deferred 2026-10-26).
- [ ] **Phase 0b, per-repo pass** (after phase 0 merges; via `/onboard split`, one `chore/claude-md-split` per repo off develop, approval per repo, never an automatic merge; `/context` before/after in that repo's journal). Order by size: faunosteo 52,322 chars (on feature/v1-1-clients-animals with 5 dirty files: finish or stash first, S1 refuses otherwise), zenquality 23,378, game 14,918 (on feature/replay-hint), robin_petier 12,895, config 4,990, integration_alphalink 4,249. None has `.claude/rules/` yet; all use the `.claude/*` file form (BDR-003). Sections a sub-agent needs stay always-on unless the phase 0 sub-agent proof says path rules load there (proof 2026-10-26: they do; verify per repo).
- - [ ] Before faunosteo: decide `###` granularity (STEP 6 review 2026-10-26). Its path-bound content (i18n, Schemas, Stores, PDF, Supabase, Storage, 12.6 KB) sits in `###` subsections of the always-on `## Project conventions`; `##`-only extract moves ~1.5% of the file. Option: `extract` accepts a `###` heading (section ends at the next heading of the same or higher level), `sections --depth 3`. User decides; `game` also has a `'` in `## 4. POINTS D'ATTENTION…` (S4 refuses it until renamed, or extract by index).
+ - [x] Before faunosteo: `###` granularity shipped 2026-10-27 (feature/rules-h3-extract ab5049e: `extract '### title'`, `sections --depth 3`, split rows `###
`). Was: decide `###` granularity (STEP 6 review 2026-10-26).
+ - [ ] /hotfix after 0b, lib/project-rules.sh `extract` (security gate 2026-10-27, pre-existing, non-blocking): check the `> "$out"` group and `mkdir -p` rc before rewriting `$src` (today a failed rule write still removes the section, rc 0); `[ -e "$out" ] || [ -L "$out" ]` and refuse `..`/absolute ``; onboarder S0.3 says `####x` is a bare title but the lib rejects it (align the prose). Its path-bound content (i18n, Schemas, Stores, PDF, Supabase, Storage, 12.6 KB) sits in `###` subsections of the always-on `## Project conventions`; `##`-only extract moves ~1.5% of the file. Option: `extract` accepts a `###` heading (section ends at the next heading of the same or higher level), `sections --depth 3`. User decides; `game` also has a `'` in `## 4. POINTS D'ATTENTION…` (S4 refuses it until renamed, or extract by index).
- [ ] **Phase 4a, memory v2 write side: shell, no mod** (shrunk 2026-10-25: the measured recall channels never read Meta; the measured status bug is a reconcile parser bug)
- Facts 2026-10-24 (scratchpad memeval, 434 entries): registries ~1M chars, never in always-on context, read only by /feat /bugfix /ship-feature (analyze-before-plan); Index drift 6 rows; status in 3 places (title tag, body Status line, Index column) → reconcile false-open BLK-032..034; no single writer (Edit needs a Read of a 357k file, so real writes are ad hoc python/bash); 8 projects on this machine hold v1 registries. Verified 2026-10-25: `lib/reconcile.sh:60-67` drops the entry's OWN header while BLK-032..034 carry `[resolved]` there (the false-open); nothing machine-reads `## Index` (analyze-before-plan.md:42, reconcile.sh:9, test T1); 1 of 1,290 entries across the 8 projects above a 1% accent ratio.
diff --git a/.claude/tasks/contracts/2026-10-27-rules-h3-extract-1326.md b/.claude/tasks/contracts/2026-10-27-rules-h3-extract-1326.md
new file mode 100644
index 0000000..b2e089d
--- /dev/null
+++ b/.claude/tasks/contracts/2026-10-27-rules-h3-extract-1326.md
@@ -0,0 +1,38 @@
+# CONTRACT — rules-h3-extract
+- date: 2026-10-27 | flow: feat | branch: feature/rules-h3-extract (off develop 925dafa)
+- status: active
+
+## REQUEST (verbatim — IMMUTABLE)
+lib/project-rules.sh: `extract` accepts a `###` heading (the section ends at the next heading of the same or higher level, outside a fence; `##` behaviour unchanged), `sections` gains `--depth 3` listing `###` subsections with their sizes (default stays `##` only), tests in lib/tests/project-rules.test.sh, and the /onboard split S4 text names the `###` option. Needed before the phase 0b split of faunosteo, whose path-bound content (12.6 KB) sits in `###` subsections of the always-on `## Project conventions`.
+
+(user, same turn: "ok merge it et enchaine sur les feat"; earlier gate answer: "Oui, /feat d'abord" to "extract accepte un titre ###, sections --depth 3; faunosteo passe ensuite".)
+
+## CLARIFICATIONS
+(pass A: none — request complete)
+Q: how does a row or an `extract` call name a `###` section? / A: the heading argument carries its prefix (`'### Supabase'`; a bare heading still means `##`), no `--level` flag [gated 2026-10-27]
+Q: `sections --depth 3`, a `##` parent's size? / A: whole section, children included (same number as depth 2) [gated 2026-10-27]
+
+## ACCEPTANCE CRITERIA
+1. `extract '### ' ` moves the `###` section: the rule holds `# ` + its body, the source loses exactly that section, the parent `##` and the next heading of level ≤ 3 stay.
+ CHECK: bash lib/tests/project-rules.test.sh | tail -1
+ EXPECT: FAIL=0
+ EVIDENCE: MET exit=0 marker-found :: PASS=116 FAIL=0
+2. A `###` section ends at the next `#`, `##` or `###` heading outside a fence; a `####` line or a fenced `### ` line never ends it.
+3. A bare heading argument still means `##` (every existing extract test unchanged); a heading argument of level 1 or ≥ 4 is rc 2 with nothing written.
+4. `sections ` output is unchanged (`##` only); `sections --depth 3 ` adds one `\t\t### ` line per subsection, lines in file order; `--depth` other than 2 or 3 is rc 2.
+5. `lib/project-rules.sh` stays shellcheck clean, every line ≤ 80 chars, functions ≤ 25 logic lines and ≤ 5 locals.
+ CHECK: shellcheck lib/project-rules.sh lib/tests/project-rules.test.sh && [ -z "$(awk 'length > 80' lib/project-rules.sh)" ] && echo WIDTH-OK
+ EXPECT: WIDTH-OK
+ EVIDENCE: MET exit=0 marker-found :: WIDTH-OK
+6. `skills/onboard/SKILL.md` § SPLIT MODE S4 names `sections --depth 3` and the `### ` row form; `agents/onboarder.md` MODE: split S0/S1 accept a `### ` row (uniqueness checked at depth 3, the prefix passed to `extract` as is).
+7. `make test` all GREEN (doctrine-citers, routing locks, project-rules).
+ CHECK: make test 2>&1 | tail -1
+ EXPECT: all suites green
+ EVIDENCE: MET exit=0 marker-found :: all suites green
+8. `bash lib/project-rules.sh check` still prints `4 rule(s) ok` on this repo and `sections CLAUDE.md` still lists 2 sections.
+ CHECK: bash lib/project-rules.sh check | tail -1 && [ "$(bash lib/project-rules.sh sections CLAUDE.md | wc -l)" = 2 ] && echo SECTIONS-OK
+ EXPECT: SECTIONS-OK
+ EVIDENCE: MET exit=0 marker-found :: project-rules: 4 rule(s) ok SECTIONS-OK
+
+## FILE SCOPE
+lib/project-rules.sh, lib/tests/project-rules.test.sh, skills/onboard/SKILL.md (§ SPLIT MODE S4/S5), agents/onboarder.md (§ MODE: split S0, S1)
diff --git a/.claude/tasks/plans/2026-10-27-rules-h3-extract-1326.md b/.claude/tasks/plans/2026-10-27-rules-h3-extract-1326.md
new file mode 100644
index 0000000..8fb9a16
--- /dev/null
+++ b/.claude/tasks/plans/2026-10-27-rules-h3-extract-1326.md
@@ -0,0 +1,303 @@
+# PLAN r3 — rules-h3-extract (feat, 2026-10-27)
+Contract: `.claude/tasks/contracts/2026-10-27-rules-h3-extract-1326.md`.
+Base develop 925dafa. Our code (strict): `lib/project-rules.sh` 80 cols,
+≤ 25 logic lines and ≤ 5 locals per function, shellcheck clean, mawk-safe
+awk (no `{n,m}` intervals), no `sed -i`. r2 folds the 3-lens challenge
+(S5 cell, separator loss, `#1 title` regression, arity, AC5 gate items,
+parent-with-children test); r3 folds the confirmation pass (T13r locale
+collation, re-emission gated on level 3, level-refusal flip, `####`+ arm,
+S0.3 wording, S5 anchor, 4-backtick fence). Edits anchor on TEXT, never
+on line numbers.
+
+## Approach
+- The heading argument carries its level: bare `` = `## `
+ (unchanged, including a title that starts with `#` such as `#1 priority`);
+ `### ` = a level-3 section; `## ` is accepted as the explicit
+ level-2 form. `# x` (H1) or `####`-and-deeper → rc 2 `heading level must
+ be ## or ###`. One helper
+ `_rules_heading_line` normalises the argument to the exact heading LINE;
+ every awk helper takes that line and derives the level inside awk as
+ `lvl = index(h, " ") - 1`.
+- A section of level L ends at the next heading of level ≤ L outside a
+ fence: awk test `match($0, /^#+ /) && RLENGTH - 1 <= lvl`.
+- Separator rule, level 3 ONLY: when a `###` section is removed and its end
+ is a heading of a LOWER level (`#`/`##`), the trailing run of blank/`---`
+ lines it carried is re-emitted in the source (it was the parent's closing
+ separator); when the end is a same-level heading, the run goes with the
+ section. A `##` section keeps today's behaviour exactly (its run always
+ travels with it, an H1 end included): the awk condition is
+ `lvl == 3 && RLENGTH - 1 < lvl`. The rule body trims the run either way.
+- `sections [--depth 2|3] `: depth 2 is today's output byte for byte;
+ depth 3 also lists each `###` subsection (its own chars, its line, the
+ `### ` heading). A `##` parent's chars keep counting through its
+ children (same number as depth 2). Exactly one positional argument after
+ the optional flag, else rc 2 (a flag after the file is an error, not a
+ silent depth 2). Lines come out in file order: awk prints at close, so the
+ output is piped through `sort -t "$(printf '\t')" -k2,2n`.
+- Rule title line: `# `.
+
+## Files
+### 1. `lib/project-rules.sh`
+Header: replace the block that starts at the line beginning
+`# sections ` and ends at the line before `# emit ` with:
+```
+# sections [--depth 2|3] chars, line, heading per ## section
+# (--depth 3 adds the ### subsections; a section
+# ends at the next heading of level ≤ its own)
+# extract move one section to a
+# rule (bare heading = ##; "### title" = a subsection;
+# a ### moved last keeps its parent's trailing ---)
+```
+Every header line ≤ 80 chars.
+
+Replace `_rules_heading_count`, `_rules_section_body` and
+`_rules_without_section` (they now take the heading LINE), and add
+`_rules_heading_line` before them:
+
+```bash
+_rules_heading_line() { # → "## t" | "### t" on stdout, rc 2
+ case "$1" in
+ '## '*|'### '*) printf '%s\n' "$1" ;;
+ '# '*|'####'*)
+ echo "project-rules: heading level must be ## or ###: $1" >&2
+ return 2 ;;
+ *) printf '## %s\n' "$1" ;;
+ esac
+}
+
+_rules_heading_count() { # → fence-aware count
+ awk -v h="$2" '/^```/ { fence = !fence }
+ !fence && $0 == h { n++ }
+ END { print n + 0 }' "$1"
+}
+
+_rules_section_body() { # → body, ---/blank trimmed
+ awk -v h="$2" '
+ BEGIN { lvl = index(h, " ") - 1 }
+ /^```/ { fence = !fence }
+ !fence && $0 == h { on = 1; next }
+ !fence && on && match($0, /^#+ /) && RLENGTH - 1 <= lvl { exit }
+ on { buf[++n] = $0 }
+ END { while (n > 0 && (buf[n] == "" || buf[n] == "---")) n--
+ for (i = 1; i <= n; i++) print buf[i] }' "$1"
+}
+
+_rules_without_section() { # → the file minus it
+ # a ### ended by a lower-level heading gives its trailing ---/blank run
+ # back to the source (the parent's closing separator); a ## keeps today's
+ # behaviour, its run travels with it
+ awk -v h="$2" '
+ BEGIN { lvl = index(h, " ") - 1 }
+ /^```/ { fence = !fence }
+ !fence && $0 == h { skip = 1; n = 0; next }
+ !fence && skip && match($0, /^#+ /) && RLENGTH - 1 <= lvl {
+ if (lvl == 3 && RLENGTH - 1 < lvl) for (i = 1; i <= n; i++) print buf[i]
+ skip = 0 }
+ skip { if ($0 == "" || $0 == "---") buf[++n] = $0; else n = 0; next }
+ { print }' "$1"
+}
+```
+(`'####'*` without a trailing space catches every level ≥ 4.)
+
+`project_rules_sections` becomes:
+```bash
+project_rules_sections() { # [--depth 2|3] → chars, line, heading
+ local depth=2
+ if [ "${1:-}" = "--depth" ]; then depth="${2:-}"; shift 2; fi
+ case "$depth" in 2|3) ;; *)
+ echo "project-rules: --depth takes 2 or 3" >&2; return 2 ;; esac
+ [ $# -eq 1 ] \
+ || { echo "project-rules: sections [--depth 2|3] " >&2; return 2; }
+ [ -f "$1" ] || { echo "project-rules: $1 not found" >&2; return 2; }
+ awk -v depth="$depth" '
+ function flush2() {
+ if (h2 != "") printf "%d\t%d\t%s\n", c2, l2, h2; h2 = "" }
+ function flush3() {
+ if (h3 != "") printf "%d\t%d\t%s\n", c3, l3, h3; h3 = "" }
+ /^```/ { fence = !fence }
+ /^# / && !fence { flush3(); flush2() }
+ /^## / && !fence { flush3(); flush2(); h2 = $0; l2 = NR; c2 = 0 }
+ /^### / && !fence && depth == 3 { flush3(); h3 = $0; l3 = NR; c3 = 0 }
+ h2 != "" { c2 += length($0) + 1 }
+ h3 != "" { c3 += length($0) + 1 }
+ END { flush3(); flush2() }' "$1" | sort -t "$(printf '\t')" -k2,2n
+}
+```
+(`shift 2` with a lone `--depth` and `set -u`: `${2:-}` is empty, the case
+refuses it before the shift matters; if shellcheck or bash complains about
+`shift 2` on one argument, guard with `[ $# -ge 2 ] &&`.)
+
+`project_rules_extract` becomes (locals: src out globs hline tmp):
+```bash
+project_rules_extract() { #
+ local src="$1" out="$3" globs="$4" hline tmp
+ hline=$(_rules_heading_line "$2") || return 2
+ [ "$(_rules_heading_count "$src" "$hline")" = 1 ] || {
+ echo "project-rules: heading must occur exactly once: $hline" >&2
+ return 2; }
+ [ -e "$out" ] && { echo "project-rules: $out exists" >&2; return 2; }
+ _rules_globs_all_match "$globs" || return 2
+ mkdir -p "$(dirname "$out")"
+ tmp=$(mktemp) || { echo "project-rules: no temp file" >&2; return 2; }
+ { printf -- '---\npaths: %s\n---\n\n# %s\n' "$globs" "${hline#* }"
+ _rules_section_body "$src" "$hline"; } > "$out"
+ if ! { _rules_without_section "$src" "$hline" > "$tmp" \
+ && cat "$tmp" > "$src"; }; then
+ rm -f "$tmp" "$out"
+ echo "project-rules: $src not rewritten, $out removed" >&2
+ return 2
+ fi
+ rm -f "$tmp"
+ echo "project-rules: moved '$hline' to $out"
+}
+```
+Main dispatch: `sections) project_rules_sections "${@:2}" ;;`. The usage
+`*)` arm becomes:
+```bash
+ *) echo "usage: project-rules.sh [-C dir] check [rules-dir] | matches" \
+ " | sections [--depth 2|3] | extract " \
+ " | emit " >&2
+ return 2 ;;
+```
+
+### 2. `lib/tests/project-rules.test.sh`
+No existing expectation changes (the "moved" message now prints the heading
+line; no test greps it). Insert the block AFTER the T12 block's closing
+`cd "$FIX" || exit 1` and BEFORE the `echo "PASS=$pass FAIL=$fail"` line:
+
+````bash
+# T13 ### subsections: hidden at depth 2, listed at depth 3, extractable,
+# a ### moved last gives its parent's --- back, a ## parent takes its ###
+mkdir -p "$FIX/d3/src" && cd "$FIX/d3" || exit 1
+echo x > src/a.ts
+cat > CLAUDE.md <<'EOF'
+# Top
+
+## P
+intro
+
+### Sub
+s1
+```
+### fenced
+```
+#### deep
+s2
+
+### Sub2
+s3
+
+---
+
+## Q
+q
+EOF
+cp CLAUDE.md "$FIX/orig3.md"
+check T13-depth2-unchanged "$(bash "$PR" sections CLAUDE.md | cut -f1,3 | tr '\t\n' ' |')" '74 ## P|7 ## Q|'
+out=$(bash "$PR" sections --depth 3 CLAUDE.md)
+check T13b-depth3-file-order "$(printf '%s\n' "$out" | cut -f3 | tr '\n' '|')" '## P|### Sub|### Sub2|## Q|'
+check T13c-sub-chars-and-line "$(printf '%s\n' "$out" | awk -F'\t' '$3=="### Sub"{print $1 "," $2}')" '44,6'
+check T13d-parent-same-as-depth2 "$(printf '%s\n' "$out" | awk -F'\t' '$3=="## P"{print $1}')" 74
+bash "$PR" sections --depth 4 CLAUDE.md 2>/dev/null; check T13e-bad-depth-rc "$?" 2
+bash "$PR" sections CLAUDE.md --depth 3 2>/dev/null; check T13f-flag-after-file-rc "$?" 2
+bash "$PR" extract CLAUDE.md '### Sub' .claude/rules/sub.md '["src/**"]' >/dev/null
+check T13g-extract-sub-rc "$?" 0
+check T13h-rule-title "$(sed -n '5p' .claude/rules/sub.md)" '# Sub'
+# shellcheck disable=SC2016
+check T13i-removed-lines "$(diff "$FIX/orig3.md" CLAUDE.md | grep '^< ' | cut -c3- | grep -vE '^(---)?$' | tr '\n' '|')" '### Sub|s1|```|### fenced|```|#### deep|s2|'
+check T13j-rule-ends-before-sub2 "$(tail -1 .claude/rules/sub.md)" 's2'
+cp CLAUDE.md "$FIX/mid3.md"
+bash "$PR" extract CLAUDE.md '### Sub2' .claude/rules/sub2.md '["src/**"]' >/dev/null
+check T13k-last-child-rc "$?" 0
+check T13l-last-child-removed-lines "$(diff "$FIX/mid3.md" CLAUDE.md | grep '^< ' | cut -c3- | tr '\n' '|')" '### Sub2|s3|'
+check T13m-parent-separator-kept "$(grep -c '^---$' CLAUDE.md)" 1
+check T13n-no-additions "$(diff "$FIX/mid3.md" CLAUDE.md | grep -c '^> ')" 0
+check T13o-q-kept "$(grep -c '^## Q' CLAUDE.md)" 1
+bash "$PR" extract CLAUDE.md '#### deep' .claude/rules/deep.md '["src/**"]' 2>/dev/null
+check T13p-level4-rc "$?" 2
+check T13p2-level4-msg "$(bash "$PR" extract CLAUDE.md '#### deep' .claude/rules/deep.md '["src/**"]' 2>&1 >/dev/null | grep -c 'heading level must be ## or ###')" 1
+bash "$PR" extract CLAUDE.md '# Top' .claude/rules/top.md '["src/**"]' 2>/dev/null
+check T13q-level1-rc "$?" 2
+check T13q2-level1-msg "$(bash "$PR" extract CLAUDE.md '# Top' .claude/rules/top.md '["src/**"]' 2>&1 >/dev/null | grep -c 'heading level must be ## or ###')" 1
+check T13r-nothing-else-written "$(cd .claude/rules && printf '%s\n' * | wc -l | tr -d ' ')" 2
+cp "$FIX/orig3.md" CLAUDE.md
+bash "$PR" extract CLAUDE.md 'P' .claude/rules/p.md '["src/**"]' >/dev/null
+check T13s-parent-takes-children "$(grep -c '^### Sub' .claude/rules/p.md)" 2
+check T13t-parent-extract-q-kept "$(grep -c '^## Q' CLAUDE.md)" 1
+printf '## #1 priority\nbody\n' > hash.md
+bash "$PR" extract hash.md '#1 priority' .claude/rules/hash.md '["src/**"]' >/dev/null
+check T13u-bare-title-starting-with-hash "$?" 0
+cd "$FIX" || exit 1
+````
+(T13r counts files instead of listing them: glob order follows
+LC_COLLATE, and `make test` does not pin the locale.)
+Hand counts (each line `length + 1`, the heading line counted in its own
+section): `### Sub` = `### Sub`(8) `s1`(3) "```"(4) `### fenced`(11)
+"```"(4) `#### deep`(10) `s2`(3) ``(1) = 44, at file line 6. `### Sub2` =
+9+3+1+4+1 = 18. `## P` = `## P`(5) `intro`(6) ``(1) + 44 + 18 = 74.
+`## Q` = 5+2 = 7. The rule file: lines 1-3 frontmatter, 4 blank, 5
+`# Sub`, 6-11 the body. T13l: the diff of the Sub2 extract deletes exactly
+`### Sub2` and `s3` (the blank, `---`, blank run is re-emitted), so the
+`<` lines are those two. Expected tally: 93 + 23 = 116.
+
+### 3. `skills/onboard/SKILL.md` § SPLIT MODE S4 and S5
+S4: the first sentence `` `bash ~/.claude/lib/project-rules.sh -C sections
+CLAUDE.md` lists every `##` section with its size.`` becomes
+`` `bash ~/.claude/lib/project-rules.sh -C sections --depth 3
+CLAUDE.md` lists every `##` section with its size and, under it, its
+`###` subsections with theirs (the parent's size includes them).`` and this
+text is added right after that sentence:
+`An always-on parent (conventions, overview) whose subsections are
+path-bound (one module, one tool) keeps its intro and the subsections move,
+one row each, heading written `### ` in the TABLE (the prefix marks
+the level; a bare heading means `##`). A `###` title must be unique across
+the whole file, like a `##` one, and a `###` row's parent is never itself a
+move row (the parent would carry the child away first; say so, the user
+picks one).`
+S5: after the Docker example row add the row
+`| 3 | ### Supabase | 2,210 | move | supabase.md | ["supabase/**"] |`
+and, AFTER the gate template's closing ``` fence and BEFORE the paragraph
+that starts `"keep everything" ends the mode`, add the sentence `A `###`
+row's section cell is the exact heading argument, prefix included, nothing
+else (no parent breadcrumb: the cell crosses to the onboarder verbatim).`
+
+### 4. `agents/onboarder.md` § MODE: split
+INPUTS: `(heading without `## `)` becomes `(heading without `## `; a
+subsection row starts with `### ` and is passed to `extract` as written)`.
+S0 step 3: after `the heading has no `'`;` add `a heading whose leading `#`
+run is followed by a space starts with `### `; any other leading `#` is a
+bare `##` title (`#1 priority`);`
+S0 step 4: `` `PR sections CLAUDE.md` lists `## ` exactly once`` becomes
+`` `PR sections --depth 3 CLAUDE.md` lists the row's heading exactly once
+(`## ` for a bare row; a `### ` row's heading as written); a `### `
+row whose parent `##` is also a row → STOP with both rows``.
+S1 first line: `(single quotes around the heading):` becomes `(single quotes
+around the heading, passed as the row wrote it: bare, or with its `### `
+prefix):`.
+
+## Edge cases
+- `### ` inside a fence: never a heading (fence-aware, T13i).
+- `####` under a `###`: body of the `###` (T13i/T13j), not extractable (T13p).
+- Same `###` title under two parents: count 2 → rc 2, user renames (the
+ existing "exactly once" rule, now across levels).
+- Last `###` of a parent: the parent's trailing `---` stays in the source
+ (T13l/T13m); a same-level end takes the run with the section, as `##`.
+- `sections --depth 3` on a file with no `###`: identical to depth 2.
+- A bare title starting with `#` (`#1 priority`): still `##` (T13u).
+- `sort` on an empty awk output: prints nothing, rc 0.
+
+## Tests
+- `bash lib/tests/project-rules.test.sh | tail -1` → `FAIL=0` (114).
+- `shellcheck lib/project-rules.sh lib/tests/project-rules.test.sh` clean.
+- `awk 'length > 80' lib/project-rules.sh` empty.
+- `make test` all GREEN (citers census sees the skill/agent edits).
+- `bash lib/project-rules.sh check` → 4 rule(s) ok; `sections CLAUDE.md` → 2 lines.
+
+## Disposition
+- honors BDR-128 by keeping one oracle, inline `paths:`, subtract-only
+ extract, the `##` contract unchanged (depth-2 output byte-identical).
+- honors LRN-233 by keeping the awk-reads-the-pipe shape, the checked
+ `mktemp` + `if !` rewrite, no `{n,m}` awk intervals.
+- honors LRN-096 by flip tests (T13e/f refusals, T13p2/q2 the level arm's
+ message, T13i/l/n conservation).
+- BDR-003 unaffected.
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 32756dd..349ac0e 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -17,7 +17,7 @@ Format follows [Keep a Changelog](https://keepachangelog.com/) and this project
- **model-router prompt classifier**: a plain prompt typed in the composer (12 characters or more, not a slash command, not mid-turn, never under `-p` or in a sub-agent) that no keyword rule, skill, run slot, `/route` or floor covers is labelled by one call to the engine's small model (`design`, `analysis`, `coding`, `bookkeeping`, `chat`), bounded to 3 s. The label maps to plan, reflect, implement or apply and the turn takes that phase's route: its effort, and its model under the switch and the downgrade cap, never above the session model (an `ultrathink` floor raises the effort only, the guess's model holds); no dialog, no file write, gone at the end of the turn, replaced by any route call or typed skill, and dropped for that turn by a `/effort` typed between turns. Three failures in a row pause it for `cooldownMinutes` (one toast, `classifier: paused` in the status line). `"classify": false` in `~/.claude/model-router.json` and `/route classify on|off` turn it off; `/route show` prints `classify:`. The status line reads `route: classifier ` and `/route verbose on` adds `(: classifier)`.
- **model-router cold-read caps**: both main-loop caps measure the cold read a switch costs, from a per-model record of main's last step, warm within the engine's prompt-cache TTL (`cache_ttl` 5m or 1h from main's model-switch events, 1 h before the first, kept across `/clear`; records cleared by `/clear` and `/route reload`), plus the submitted prompt the engine's usage may not count yet (code points / 3 of its text, context entries and a typed skill's body, added at the turn's first main step unless usage already grew by half of it; a `document` attachment blocks the switch for that step); `downgradeMaxTokens` (default 120000) joins `upgradeMaxTokens` (200000). A model-loaded helper skill inside a best-tier run moves effort only; main routed onto a model whose window the context outgrew returns to the session model. `/route show` prints `switch: on (downgrade, cap 120000 tokens cold, ttl 60 min)`, the status line shows ` · switch off` only when the switch is off, the skip line is logged once per cap crossing and the change toast names a cap hold. A built-in `general-purpose` agent that main spawns with no model while main sits below the session model starts on the session model instead of inheriting the lower one.
- **/explain-diff skill**: turns a change (commit, range, branch, merge, PR, staged or uncommitted work) into one self-contained HTML page saved outside the repo, under `~/Documents/explanations//YYYY-MM-DD-.html`. The page has a background, an intuition built on toy data with HTML diagrams, a code walkthrough grouped by concern and a 5-question interactive quiz. Adapted from Geoffrey Litt's explain-diff gist. A bundled template (light and dark, works offline) and a checker (`scripts/check_explanation.py`: file name, location, sections, quiz, code escaping, no ASCII art, no em-dash) hold every page to the same floor. Routing row `reflect`; profiles full, max and dev.
-- **Project path rules (CLAUDE.md split)**: `lib/project-rules.sh` (`check`, `matches`, `sections`, `extract`, `emit`, optional `-C `) is the glob oracle for `.claude/rules/.md` rules, one-line `paths:` frontmatter, loaded on Read of a matching file; suite `lib/tests/project-rules.test.sh`. `/onboard split` classifies an existing project CLAUDE.md section by section behind a gate and moves the path-bound ones into rules on a `chore/claude-md-split` branch. `/onboard` and `/init-project` emit `docker`, `testing` and `ci` rules from `templates/project-rules/` when their globs match. This repo's CLAUDE.md now keeps its header, Health Stack and a pointer; four sections load as path rules.
+- **Project path rules (CLAUDE.md split)**: `lib/project-rules.sh` (`check`, `matches`, `sections`, `extract`, `emit`, optional `-C `) is the glob oracle for `.claude/rules/.md` rules, one-line `paths:` frontmatter, loaded on Read of a matching file; suite `lib/tests/project-rules.test.sh`. `/onboard split` classifies an existing project CLAUDE.md section by section behind a gate and moves the path-bound ones into rules on a `chore/claude-md-split` branch. `extract` also moves a `###` subsection (heading passed as `'### '`; a bare heading stays `##`), which ends at the next heading of level 3 or less outside a fence, and `sections --depth 3` lists each `##` section's subsections with their sizes, so `/onboard split` can move a path-bound subsection out of an always-on parent (one `### ` row; a row's parent is never itself a move row). `/onboard` and `/init-project` emit `docker`, `testing` and `ci` rules from `templates/project-rules/` when their globs match. This repo's CLAUDE.md now keeps its header, Health Stack and a pointer; four sections load as path rules.
- **InstructionsLoaded logger**: `hooks/instructions-loaded.sh`, wired in `settings.json`, appends one JSON line per instruction file loaded to `~/.claude/logs/instructions-loaded.jsonl` (rotated above 5 MB), the proof that a path rule loaded.
### Changed
diff --git a/agents/onboarder.md b/agents/onboarder.md
index a01ece0..cd201b9 100644
--- a/agents/onboarder.md
+++ b/agents/onboarder.md
@@ -199,7 +199,8 @@ PLACEHOLDERS :
INPUTS: `PROJECT_ROOT` (absolute; written as a literal path in every
command below, never through a variable), `TABLE` = the approved rows, one
-per line, ` | | ` (heading without `## `). No
+per line, ` | | ` (heading without `## `; a
+subsection row starts with `### ` and is passed to `extract` as written). No
BRIEF; PHASES 1-6 do not run. `PR` below stands for
`bash ~/.claude/lib/project-rules.sh -C `.
@@ -209,10 +210,14 @@ S0 — PREFLIGHT (no write before every step passes):
rule the oracle cannot parse (the one-line `paths: ["a", "b"]` form
only) is fixed by the user before any split.
3. Per row, by reading the row (never a shell test that embeds it):
- `` matches `[a-z0-9][a-z0-9-]*`; the heading has no `'`; every
+ `` matches `[a-z0-9][a-z0-9-]*`; the heading has no `'`; a heading
+ whose leading `#` run is followed by a space starts with `### `; any other
+ leading `#` is a bare `##` title (`#1 priority`); every
glob is relative, with no `'`, no leading `/`, no `..`. A row that
fails → STOP with the row and the field.
-4. Per row: `PR sections CLAUDE.md` lists `## ` exactly once;
+4. Per row: `PR sections --depth 3 CLAUDE.md` lists the row's heading exactly
+ once (`## ` for a bare row; a `### ` row's heading as written);
+ a `### ` row whose parent `##` is also a row → STOP with both rows;
`/.claude/rules/.md` does not exist; every glob of
`` passes `PR matches ''` (rc 0). Any failure → STOP
with the row and the reason.
@@ -236,7 +241,8 @@ S0 — PREFLIGHT (no write before every step passes):
A STOP after 5.d reverts the gitignore line (5.e); nothing else was
written.
-S1 — EXTRACT, per row (single quotes around the heading):
+S1 — EXTRACT, per row (single quotes around the heading, passed as the row
+wrote it: bare, or with its `### ` prefix):
```bash
bash ~/.claude/lib/project-rules.sh -C extract CLAUDE.md '' .claude/rules/.md ''
```
diff --git a/lib/project-rules.sh b/lib/project-rules.sh
index 62e84fd..8b96a72 100644
--- a/lib/project-rules.sh
+++ b/lib/project-rules.sh
@@ -7,10 +7,12 @@
# check [rules-dir] every path rule parses and every glob matches ≥1
# path; rc 2 with the culprit named
# matches rc 0 + the first hits, rc 1 none
-# sections chars, line, heading per top-level ## section
-# (a section ends at the next # or ## heading
-# outside a fence)
-# extract move one section to a rule
+# sections [--depth 2|3] chars, line, heading per ## section
+# (--depth 3 adds the ### subsections; a section
+# ends at the next heading of level ≤ its own)
+# extract move one section to a
+# rule (bare heading = ##; "### title" = a subsection;
+# a ### moved last keeps its parent's trailing ---)
# emit the rule with the matching globs only (rc 1
# when none matches, nothing written)
# Globs match the WORKING TREE (compgen -G with globstar and dotglob,
@@ -105,39 +107,68 @@ project_rules_matches() { # → rc 0 + the first 3 hits, rc 1 none
|| { echo "no match: $1" >&2; return 1; }
}
-project_rules_sections() { # → chars, line, heading per ## section
+project_rules_sections() { # [--depth 2|3] → chars, line, heading
+ local depth=2
+ if [ "${1:-}" = "--depth" ]; then depth="${2:-}"; shift 2; fi
+ case "$depth" in 2|3) ;; *)
+ echo "project-rules: --depth takes 2 or 3" >&2; return 2 ;; esac
+ [ $# -eq 1 ] \
+ || { echo "project-rules: sections [--depth 2|3] " >&2; return 2; }
[ -f "$1" ] || { echo "project-rules: $1 not found" >&2; return 2; }
- awk '
- function flush() { if (h != "") printf "%d\t%d\t%s\n", c, l, h; h = "" }
+ awk -v depth="$depth" '
+ function flush2() {
+ if (h2 != "") printf "%d\t%d\t%s\n", c2, l2, h2; h2 = "" }
+ function flush3() {
+ if (h3 != "") printf "%d\t%d\t%s\n", c3, l3, h3; h3 = "" }
/^```/ { fence = !fence }
- /^# / && !fence { flush() }
- /^## / && !fence { flush(); h = $0; l = NR; c = 0 }
- h != "" { c += length($0) + 1 }
- END { flush() }' "$1"
+ /^# / && !fence { flush3(); flush2() }
+ /^## / && !fence { flush3(); flush2(); h2 = $0; l2 = NR; c2 = 0 }
+ /^### / && !fence && depth == 3 { flush3(); h3 = $0; l3 = NR; c3 = 0 }
+ h2 != "" { c2 += length($0) + 1 }
+ h3 != "" { c3 += length($0) + 1 }
+ END { flush3(); flush2() }' "$1" | sort -t "$(printf '\t')" -k2,2n
}
-_rules_heading_count() { # → fence-aware count of "## h"
- awk -v h="## $2" '/^```/ { fence = !fence }
- !fence && $0 == h { n++ }
- END { print n + 0 }' "$1"
+_rules_heading_line() { # → "## t" | "### t" on stdout, rc 2
+ case "$1" in
+ '## '*|'### '*) printf '%s\n' "$1" ;;
+ '# '*|'####'*)
+ echo "project-rules: heading level must be ## or ###: $1" >&2
+ return 2 ;;
+ *) printf '## %s\n' "$1" ;;
+ esac
}
-_rules_section_body() { # → body, trailing ---/blank trimmed
- awk -v h="## $2" '
+_rules_heading_count() { # → fence-aware count
+ awk -v h="$2" '/^```/ { fence = !fence }
+ !fence && $0 == h { n++ }
+ END { print n + 0 }' "$1"
+}
+
+_rules_section_body() { # → body, ---/blank trimmed
+ awk -v h="$2" '
+ BEGIN { lvl = index(h, " ") - 1 }
/^```/ { fence = !fence }
!fence && $0 == h { on = 1; next }
- !fence && on && (/^## / || /^# /) { exit }
+ !fence && on && match($0, /^#+ /) && RLENGTH - 1 <= lvl { exit }
on { buf[++n] = $0 }
END { while (n > 0 && (buf[n] == "" || buf[n] == "---")) n--
for (i = 1; i <= n; i++) print buf[i] }' "$1"
}
-_rules_without_section() { # → the file minus that section
- awk -v h="## $2" '
+_rules_without_section() { # → the file minus it
+ # a ### ended by a lower-level heading gives its trailing ---/blank run
+ # back to the source (the parent's closing separator); a ## keeps today's
+ # behaviour, its run travels with it
+ awk -v h="$2" '
+ BEGIN { lvl = index(h, " ") - 1 }
/^```/ { fence = !fence }
- !fence && $0 == h { skip = 1; next }
- !fence && skip && (/^## / || /^# /) { skip = 0 }
- !skip { print }' "$1"
+ !fence && $0 == h { skip = 1; n = 0; next }
+ !fence && skip && match($0, /^#+ /) && RLENGTH - 1 <= lvl {
+ if (lvl == 3 && RLENGTH - 1 < lvl) for (i = 1; i <= n; i++) print buf[i]
+ skip = 0 }
+ skip { if ($0 == "" || $0 == "---") buf[++n] = $0; else n = 0; next }
+ { print }' "$1"
}
_rules_globs_all_match() { # → rc 0 valid and every glob matches
@@ -152,24 +183,25 @@ _rules_globs_all_match() { # → rc 0 valid and every glob matches
}
project_rules_extract() { #
- local src="$1" heading="$2" out="$3" globs="$4" tmp
- [ "$(_rules_heading_count "$src" "$heading")" = 1 ] || {
- echo "project-rules: heading must occur exactly once: ## $heading" >&2
+ local src="$1" out="$3" globs="$4" hline tmp
+ hline=$(_rules_heading_line "$2") || return 2
+ [ "$(_rules_heading_count "$src" "$hline")" = 1 ] || {
+ echo "project-rules: heading must occur exactly once: $hline" >&2
return 2; }
[ -e "$out" ] && { echo "project-rules: $out exists" >&2; return 2; }
_rules_globs_all_match "$globs" || return 2
mkdir -p "$(dirname "$out")"
tmp=$(mktemp) || { echo "project-rules: no temp file" >&2; return 2; }
- { printf -- '---\npaths: %s\n---\n\n# %s\n' "$globs" "$heading"
- _rules_section_body "$src" "$heading"; } > "$out"
- if ! { _rules_without_section "$src" "$heading" > "$tmp" \
+ { printf -- '---\npaths: %s\n---\n\n# %s\n' "$globs" "${hline#* }"
+ _rules_section_body "$src" "$hline"; } > "$out"
+ if ! { _rules_without_section "$src" "$hline" > "$tmp" \
&& cat "$tmp" > "$src"; }; then
rm -f "$tmp" "$out"
echo "project-rules: $src not rewritten, $out removed" >&2
return 2
fi
rm -f "$tmp"
- echo "project-rules: moved '## $heading' to $out"
+ echo "project-rules: moved '$hline' to $out"
}
project_rules_emit() { # → the rule, matching globs only
@@ -197,13 +229,14 @@ _project_rules_main() {
case "${1:-}" in
check) project_rules_check "${2:-.claude/rules}" ;;
matches) project_rules_matches "${2:?glob}" ;;
- sections) project_rules_sections "${2:?file}" ;;
+ sections) project_rules_sections "${@:2}" ;;
extract) project_rules_extract "${2:?file}" "${3:?heading}" "${4:?out}" \
"${5:?globs-json}" ;;
emit) project_rules_emit "${2:?skeleton}" "${3:?out}" ;;
*) echo "usage: project-rules.sh [-C dir] check [rules-dir] | matches" \
- " | sections | extract " \
- " | emit " >&2; return 2 ;;
+ " | sections [--depth 2|3] | extract " \
+ " | emit " >&2
+ return 2 ;;
esac
}
diff --git a/lib/tests/project-rules.test.sh b/lib/tests/project-rules.test.sh
index 54bf3a0..ecbbfab 100644
--- a/lib/tests/project-rules.test.sh
+++ b/lib/tests/project-rules.test.sh
@@ -233,5 +233,68 @@ check T12h-existing-target-rc "$?" 2
bash "$PR" check >/dev/null; check T12i-emitted-rules-pass-check "$?" 0
cd "$FIX" || exit 1
+# T13 ### subsections: hidden at depth 2, listed at depth 3, extractable,
+# a ### moved last gives its parent's --- back, a ## parent takes its ###
+mkdir -p "$FIX/d3/src" && cd "$FIX/d3" || exit 1
+echo x > src/a.ts
+cat > CLAUDE.md <<'EOF'
+# Top
+
+## P
+intro
+
+### Sub
+s1
+```
+### fenced
+```
+#### deep
+s2
+
+### Sub2
+s3
+
+---
+
+## Q
+q
+EOF
+cp CLAUDE.md "$FIX/orig3.md"
+fence=$(printf '\140\140\140')
+check T13-depth2-unchanged "$(bash "$PR" sections CLAUDE.md | cut -f1,3 | tr '\t\n' ' |')" '74 ## P|7 ## Q|'
+out=$(bash "$PR" sections --depth 3 CLAUDE.md)
+check T13b-depth3-file-order "$(printf '%s\n' "$out" | cut -f3 | tr '\n' '|')" '## P|### Sub|### Sub2|## Q|'
+check T13c-sub-chars-and-line "$(printf '%s\n' "$out" | awk -F'\t' '$3=="### Sub"{print $1 "," $2}')" '44,6'
+check T13d-parent-same-as-depth2 "$(printf '%s\n' "$out" | awk -F'\t' '$3=="## P"{print $1}')" 74
+bash "$PR" sections --depth 4 CLAUDE.md 2>/dev/null; check T13e-bad-depth-rc "$?" 2
+bash "$PR" sections CLAUDE.md --depth 3 2>/dev/null; check T13f-flag-after-file-rc "$?" 2
+bash "$PR" extract CLAUDE.md '### Sub' .claude/rules/sub.md '["src/**"]' >/dev/null
+check T13g-extract-sub-rc "$?" 0
+check T13h-rule-title "$(sed -n '5p' .claude/rules/sub.md)" '# Sub'
+check T13i-removed-lines "$(diff "$FIX/orig3.md" CLAUDE.md | grep '^< ' | cut -c3- | grep -vE '^(---)?$' | tr '\n' '|')" "### Sub|s1|$fence|### fenced|$fence|#### deep|s2|"
+check T13j-rule-ends-before-sub2 "$(tail -1 .claude/rules/sub.md)" 's2'
+cp CLAUDE.md "$FIX/mid3.md"
+bash "$PR" extract CLAUDE.md '### Sub2' .claude/rules/sub2.md '["src/**"]' >/dev/null
+check T13k-last-child-rc "$?" 0
+check T13l-last-child-removed-lines "$(diff "$FIX/mid3.md" CLAUDE.md | grep '^< ' | cut -c3- | tr '\n' '|')" '### Sub2|s3|'
+check T13m-parent-separator-kept "$(grep -c '^---$' CLAUDE.md)" 1
+check T13n-no-additions "$(diff "$FIX/mid3.md" CLAUDE.md | grep -c '^> ')" 0
+check T13o-q-kept "$(grep -c '^## Q' CLAUDE.md)" 1
+bash "$PR" extract CLAUDE.md '#### deep' .claude/rules/deep.md '["src/**"]' 2>/dev/null
+check T13p-level4-rc "$?" 2
+check T13p2-level4-msg "$(bash "$PR" extract CLAUDE.md '#### deep' .claude/rules/deep.md '["src/**"]' 2>&1 >/dev/null | grep -c 'heading level must be ## or ###')" 1
+bash "$PR" extract CLAUDE.md '# Top' .claude/rules/top.md '["src/**"]' 2>/dev/null
+check T13q-level1-rc "$?" 2
+check T13q2-level1-msg "$(bash "$PR" extract CLAUDE.md '# Top' .claude/rules/top.md '["src/**"]' 2>&1 >/dev/null | grep -c 'heading level must be ## or ###')" 1
+check T13r-nothing-else-written "$(cd .claude/rules && printf '%s\n' * | wc -l | tr -d ' ')" 2
+cp "$FIX/orig3.md" CLAUDE.md
+bash "$PR" extract CLAUDE.md 'P' .claude/rules/p.md '["src/**"]' >/dev/null
+check T13s-parent-takes-children "$(grep -c '^### Sub' .claude/rules/p.md)" 2
+check T13t-parent-extract-q-kept "$(grep -c '^## Q' CLAUDE.md)" 1
+printf '## #1 priority\nbody\n' > hash.md
+bash "$PR" extract hash.md '#1 priority' .claude/rules/hash.md '["src/**"]' >/dev/null
+check T13u-bare-title-starting-with-hash "$?" 0
+cd "$FIX" || exit 1
+
echo "PASS=$pass FAIL=$fail"
[ "$fail" -eq 0 ]
diff --git a/skills/onboard/SKILL.md b/skills/onboard/SKILL.md
index da14e89..c0eaba8 100644
--- a/skills/onboard/SKILL.md
+++ b/skills/onboard/SKILL.md
@@ -1119,8 +1119,16 @@ claude-md-split`. A project without gitflow (no `develop`):
`git -C switch -c chore/claude-md-split`, and say so. Everything
after this step reads the branched file.
-S4 — CLASSIFY. `bash ~/.claude/lib/project-rules.sh -C sections
-CLAUDE.md` lists every `##` section with its size. For each one decide:
+S4 — CLASSIFY. `bash ~/.claude/lib/project-rules.sh -C sections --depth 3
+CLAUDE.md` lists every `##` section with its size and, under it, its
+`###` subsections with theirs (the parent's size includes them).
+An always-on parent (conventions, overview) whose subsections are
+path-bound (one module, one tool) keeps its intro and the subsections move,
+one row each, heading written `### ` in the TABLE (the prefix marks
+the level; a bare heading means `##`). A `###` title must be unique across
+the whole file, like a `##` one, and a `###` row's parent is never itself a
+move row (the parent would carry the child away first; say so, the user
+picks one). For each one decide:
- always-on: project overview, stack, build/test/lint commands, folder
structure, conventions that apply everywhere, exceptions to global rules,
workflow expectations, key dependencies, anything needed before a file is
@@ -1144,9 +1152,13 @@ SPLIT — CLAUDE.md ( chars, sections) on chore/claude-md-s
| # | section | chars | verdict | rule file | paths |
| 1 | Stack | 420 | keep | | |
| 2 | Docker | 1,340 | move | docker.md | ["Dockerfile*", "docker-compose*"] |
+| 3 | ### Supabase | 2,210 | move | supabase.md | ["supabase/**"] |
...
Moves sections, chars (% of the file). Approve, edit a row, or "keep everything".
```
+A `###` row's section cell is the exact heading argument, prefix included,
+nothing else (no parent breadcrumb: the cell crosses to the onboarder
+verbatim).
"keep everything" ends the mode with no change (`bash
~/.claude/lib/gitflow.sh delete chore/claude-md-split`). An edited row's
globs are re-verified with `matches` before they enter the TABLE. The