feat(rules): rules/ directory symlinked into ~/.claude like the other dirs

Claude Code loads modular rule files from ~/.claude/rules/ (user scope,
recursive, markdown, optional paths: frontmatter for lazy path-scoped
loading — stable, symlink-supported). The repo had no rules/ at all, so
the ctx7 setup had created ~/.claude/rules as a REAL directory outside
version control — invisible to the repo, unreproducible on a new machine.

- rules/README.md — doctrine: one rule per file; paths:-scoped extraction
  is the token win, always-on doctrine stays in CLAUDE.md
- link.sh — rules added to the symlinked-dirs loop
- .gitignore — rules/context7.md ignored (machine-owned: `ctx7 setup`
  (re)writes it, same treatment as skills/find-docs/)

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01XpphkdTosUzokBDNG7PToS
This commit is contained in:
Bastien Chanot
2026-07-04 13:32:55 +02:00
co-authored by Claude Opus 4.8
parent 1cd13e7a3d
commit 06391a6247
3 changed files with 32 additions and 1 deletions
+4
View File
@@ -74,6 +74,10 @@ skills/find-skills
# this repo's skills/). ctx7-managed and re-created on demand — not vendored here. # this repo's skills/). ctx7-managed and re-created on demand — not vendored here.
skills/find-docs/ skills/find-docs/
# Context7 rule — (re)written by the same `ctx7 setup` into ~/.claude/rules (a
# symlink to this repo's rules/). ctx7-managed — not vendored here.
rules/context7.md
# Staging area used by lib/toggle-external.sh when disabling a tool # Staging area used by lib/toggle-external.sh when disabling a tool
skills-disabled/ skills-disabled/
+1 -1
View File
@@ -20,7 +20,7 @@ link_file() {
link_file "$REPO/CLAUDE.md" "$CLAUDE/CLAUDE.md" link_file "$REPO/CLAUDE.md" "$CLAUDE/CLAUDE.md"
link_file "$REPO/settings.json" "$CLAUDE/settings.json" link_file "$REPO/settings.json" "$CLAUDE/settings.json"
for item in hooks agents skills lib templates; do for item in hooks agents skills lib templates rules; do
target="$CLAUDE/$item" target="$CLAUDE/$item"
if [ -L "$target" ]; then if [ -L "$target" ]; then
if [ "$(readlink "$target")" = "$REPO/$item" ]; then if [ "$(readlink "$target")" = "$REPO/$item" ]; then
+27
View File
@@ -0,0 +1,27 @@
# rules/
Modular instruction files loaded by Claude Code alongside `CLAUDE.md`.
Symlinked to `~/.claude/rules` by `link.sh`, same model as `agents/`,
`skills/`, `lib/`.
## What belongs here
One rule = one file = one concern. Candidates: instructions that are
self-contained enough to live outside `CLAUDE.md`'s main flow, or that
tooling generates/owns.
Rules support an optional `paths:` YAML frontmatter (glob list). A rule
WITH `paths` loads lazily — only when Claude reads a file matching a
glob; a rule WITHOUT it loads at session start, same cost as CLAUDE.md.
So: extract from CLAUDE.md only what can be path-scoped (the token win)
or what is generated; always-on doctrine stays in CLAUDE.md.
Docs: https://code.claude.com/docs/en/memory.md#path-specific-rules
## Machine-owned files (gitignored, regenerated)
- `context7.md` — written by `ctx7 setup --claude --cli`
(install-plugins.sh STEP ctx7). Not vendored: ctx7 owns its content
and rewrites it on setup; the repo would fight the generator. Same
treatment as `skills/find-docs/`.
Hand-written rules ARE tracked — add them normally.