Repository navigation
refactor(claude): move rules and docs out of the protected .claude/ directory - #669
Merged
Merged
Conversation
…irectory Claude Code's Protected Paths guard makes any write under `.claude/` require interactive approval, and it runs BEFORE `permissions.allow` — so the allowlist added in #667 never applied. The unattended cloud loop stalls indefinitely on it (~75 minutes of one run this week) and cannot even perceive that it is blocked. Moving the content out of `.claude/` is the only fix. Path-conditional loading is preserved, not abandoned. Each `.claude/rules/*.md` becomes an `AGENTS.md` in the directory its `paths:` frontmatter targeted, with a `CLAUDE.md` symlink beside it — the pairing this repo already uses at the root and throughout `seeds/`. Subdirectory guides are included when an agent reads files in that directory, so the file's location now IS its scope and the globs are gone. .claude/rules/access.md -> src/plugins/access/AGENTS.md .claude/rules/admin-ui.md -> src/components/admin/AGENTS.md .claude/rules/api-clients.md -> src/plugins/usage/AGENTS.md .claude/rules/blocks.md -> src/lib/richEditor/blocks/AGENTS.md .claude/rules/collections.md -> src/collections/AGENTS.md .claude/rules/components.md -> src/components/AGENTS.md .claude/rules/email.md -> src/plugins/email/AGENTS.md .claude/rules/endpoints.md -> src/endpoints/AGENTS.md .claude/rules/globals.md -> src/globals/AGENTS.md .claude/rules/migrations.md -> src/migrations/AGENTS.md .claude/rules/openapi.md -> src/plugins/openapi/AGENTS.md .claude/rules/project-structure.md -> src/AGENTS.md .claude/rules/routes.md -> src/app/AGENTS.md .claude/rules/scripts.md -> scripts/AGENTS.md .claude/rules/storage.md -> src/plugins/storage/AGENTS.md .claude/rules/types.md -> src/types/AGENTS.md .claude/rules/{tests,testing-reqs}.md -> tests/AGENTS.md (merged) .claude/rules/code-style.md -> docs/code-style.md (@-imported) .claude/docs/*.md -> docs/*.md Three cases needed deciding rather than moving: - `code-style.md` had NO frontmatter, so it loaded every session. A nested guide cannot reproduce that, so it moves to `docs/` and is `@`-imported from AGENTS.md alongside the two docs already imported that way. Behaviour is unchanged; only the mechanism is. - `tests.md` (how to write tests) and `testing-reqs.md` (how to run them — the CPU guard and three-tier contract) both scoped to `tests/`. One directory can hold one guide, so they are merged into `tests/AGENTS.md` with all content kept; testing-reqs' sections are appended under "Test execution requirements" and its two cross-file pointers become in-file ones. - Six rules spanned unrelated directories. The body lives in the primary one and the others get a one-line pointer, so no prose is duplicated: Clients and Managers point at plugins/access, Clients also at plugins/usage, branding at components/admin, fields at collections, emails at plugins/email, and the two api/ route folders at plugins/openapi and plugins/storage. AGENTS.md's Documentation section claimed `.claude/rules/` were "path-scoped rules that auto-load when reading matching files ... each file's frontmatter declares its globs". That would have been false the moment the globs were dropped, so it now describes the nested arrangement it actually has. 118 path references across 68 files were rewritten — docs, skills, hooks, settings, and the ~35 source comments that cite a rule by path. `.claude/` keeps what is genuinely Claude-specific: hooks, skills, commands, agents, output styles and settings. The one surviving `.claude/docs` mention is a `$comment` in workflow.json describing a file deleted before this change. Verified: `pnpm lint` and `pnpm typecheck` pass; no reference to the old paths remains outside that historical note. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
|
🚅 Deployed to the SahajCloud-pr-669 environment in sahajcloud
1 service not affected by this PR
|
railway-app
Bot
temporarily deployed
to
sahajcloud / SahajCloud-pr-669
September 1, 2026 02:59
Destroyed
…of nesting them `.claude/rules/` supports symlinks, and this was verified rather than assumed: reading a file matching a rule's `paths:` glob injected the rule, and the injection cited the *target* path (`docs/rules/…`), not the symlink. That target is outside `.claude/`, so the Protected Paths guard never sees the edit and an unattended run does not stall. Creating the symlink is a one-time human cost; editing the rule is not. That changes the design of the previous commit. A nested `AGENTS.md` scopes by DIRECTORY; a `paths:` rule scopes by GLOB. Where a rule's scope was one clean subtree, the nested guide is the better home — it sits beside the code it governs. Where it was not, the previous commit had to invent pointer files, and each pointer was evidence of the mis-fit. Nine rules go back to `docs/rules/` with their original `paths:` frontmatter, symlinked into `.claude/rules/`: docs/rules/routes.md src/app/**/route.ts — a filename across many dirs docs/rules/endpoints.md src/collections/*/endpoints/** — wildcard middle docs/rules/testing-reqs.md tests/** + **/*.test.ts + **/*.spec.ts docs/rules/access.md 3 unrelated paths docs/rules/admin-ui.md 3 unrelated paths docs/rules/storage.md 2 unrelated paths docs/rules/openapi.md 2 unrelated paths docs/rules/email.md 2 unrelated dirs docs/rules/api-clients.md a directory plus one file elsewhere Eight stay nested, because their scope really is one subtree: collections, components, globals, migrations, types, scripts, blocks, project-structure. `code-style.md` is unchanged — unscoped, `@`-imported from the root guide. `tests.md` and `testing-reqs.md` are split back apart. `tests.md` (how to write tests, `tests/**/*.spec.ts`) is directory-clean and stays `tests/AGENTS.md`; `testing-reqs.md` (how to RUN them — the CPU guard and the three-tier contract) reaches `**/*.spec.ts` outside `tests/`, so it becomes a symlinked rule. Both were recovered from the merge-base rather than unpicked from the merged file, so no prose was rewritten. Fourteen pointer files are deleted — every one that existed only because a rule spanned directories, now redundant because the glob reaches those paths again: the two `api/` route folders, Clients, Managers, branding, and emails. `src/fields/AGENTS.md` STAYS: `collections.md` covered `src/collections/**` and `src/fields/**`, and with the body nested under `src/collections/` the pointer is the only thing that reaches `src/fields/`. Every nested guide that remains keeps its `CLAUDE.md` symlink (mode 120000); `seeds/atlas/` was missing one and now has it. Path references are rewritten across docs, hooks, skills and source comments; `.claude/settings.json` already allowed `Edit/Write(docs/**)`, and deliberately does NOT allow `.claude/rules/**` — nothing should ever need to write there. The root guide now describes both mechanisms and says why the content lives in `docs/`, so nobody tidies it back into `.claude/` and reintroduces the stall. Verified: lean gate green (lint, typecheck, typecheck:tests, 1497 unit tests); every symlink resolves; each relocated rule diffs against the merge-base by path strings only. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
This was referenced Sep 1, 2026
1 of 12 tasks
This branch was successfully deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Why
Claude Code's Protected Paths guard makes any write under
.claude/require interactive approval, and it runs beforepermissions.allow. The allowlist added in #667 (Edit(.claude/rules/**),Edit(.claude/docs/**)) therefore never took effect. The unattended cloud loop stalls indefinitely on the prompt — roughly 75 minutes of one run this week — and cannot perceive that it is blocked. The guard cannot be configured away, so the content has to leave.claude/.The mechanism that shapes this PR
.claude/rules/follows symlinks, and the injected rule cites the target path. Verified empirically, not assumed: reading a file matching a rule'spaths:glob injected the rule into context, and the injection nameddocs/rules/…, not the symlink. The target is outside.claude/, so the guard never sees the edit.Creating the symlink may prompt once. Editing the rule afterwards never does. That is a one-time human setup cost, not a per-edit one — which is exactly the property the loop needs.
So guidance loads two ways, by scope shape
A nested
AGENTS.mdscopes by directory. Apaths:rule scopes by glob. Neither is better in general; the right one depends on whether the rule's scope is a directory.Nested
AGENTS.md+CLAUDE.mdsymlink — the scope is one clean subtree, so the guide sits beside the code it governs and its location is its scope:collections.mdsrc/collections/AGENTS.mdcomponents.mdsrc/components/AGENTS.mdglobals.mdsrc/globals/AGENTS.mdmigrations.mdsrc/migrations/AGENTS.mdtypes.mdsrc/types/AGENTS.mdscripts.mdscripts/AGENTS.mdblocks.mdsrc/lib/richEditor/blocks/AGENTS.mdproject-structure.mdsrc/AGENTS.mdtests.mdtests/AGENTS.mddocs/rules/*.md, symlinked into.claude/rules/— the scope is not a directory, so thepaths:frontmatter is kept intact and the rule loads by glob:routes.mdsrc/app/**/route.ts— a filename pattern across many directories;src/app/AGENTS.mdfires for all ofsrc/appendpoints.mdsrc/collections/*/endpoints/**— wildcard middle segmenttesting-reqs.md**/*.test.ts/**/*.spec.tsreach outsidetests/access.mdadmin-ui.mdstorage.mdopenapi.mdemail.mdapi-clients.mdRoot import:
code-style.mdhad no frontmatter, so it loaded unconditionally every session. No nested guide reproduces that, so it staysdocs/code-style.md,@-imported fromAGENTS.mdbeside the two docs already imported that way. Same behaviour, different mechanism..claude/docs/{architecture,environment,mcp-setup}.md→docs/.Each pointer file was evidence of a mis-fit
The first pass had no glob mechanism available, so a rule spanning unrelated directories had to be split into a body plus one-line pointer files. Those pointers are now redundant — the glob reaches those paths again — and fourteen files are deleted:
src/app/(payload)/api/openapi.json/,src/app/(payload)/api/webhooks/,src/collections/Clients/,src/collections/Managers/,src/components/branding/,src/emails/(each anAGENTS.md+CLAUDE.mdpair). Two inline pointer paragraphs go too, fromsrc/collections/AGENTS.mdandsrc/globals/AGENTS.md.src/fields/AGENTS.mdstays.collections.mdcoveredsrc/collections/**andsrc/fields/**. With the body nested undersrc/collections/, that pointer is the only thing that reachessrc/fields/— it is load-bearing, not redundant. It is the one rule in the keep-nested list whose scope is not strictly a single subtree.tests.mdandtesting-reqs.md, split back apartThe first pass merged them because both scoped to
tests/and one directory holds one guide. They separate cleanly under the split:tests.md— how to write tests,tests/**/*.spec.ts, directory-clean → staystests/AGENTS.mdtesting-reqs.md— how to run them (the CPU guard, the three-tier speed contract), reaching**/*.spec.tsoutsidetests/→ symlinked ruleBoth were recovered from the merge-base rather than unpicked from the merged file, so no prose was rewritten in either direction.
Documentation
AGENTS.md's Documentation section now describes both mechanisms and which one a subsystem uses, and states why the content lives indocs/— so nobody "tidies" it back into.claude/and reintroduces the stall.docs/architecture.md's opening claim about where subsystem detail lives is corrected the same way..claude/settings.jsonalready grantsEdit/Write(docs/**). It deliberately does not grant.claude/rules/**: nothing should ever need to write there, and a grant would not help if it did.Verification
pnpm lint,pnpm typecheck,pnpm typecheck:tests,pnpm test:unit(1497/1497, 47s).claude/rules/*.mdsymlink resolves;git ls-files -sshows mode120000for all nine, and for everyCLAUDE.md(seeds/atlas/was missing one and now has it)testing-reqs.mdthat described the old loading mechanismdocs/rules/*.md,docs/*.mdand nested-guide path cited anywhere in the tree existsThis remains a pure relocation. No rule prose was rewritten beyond repointing paths the move broke.