Skip to content

chore(claude): let the loop edit docs, rules, skills and guides unattended - #667

Merged
Ardnived merged 1 commit into
mainfrom
claude/allow-doc-self-edits
Aug 31, 2026
Merged

Ardnived merged 1 commit into
mainfrom
claude/allow-doc-self-edits

Conversation

@Ardnived

Copy link
Copy Markdown
Contributor

Summary

  • Allows the loop (and local sessions) to edit .claude/docs, .claude/rules, .claude/skills, CLAUDE.md and AGENTS.md without a live approval prompt — a routine run stalled on exactly this during a docs-sync step
  • settings.json itself and .claude/hooks deliberately stay gated: a hook edit is arbitrary code execution in the reviewer's session

Contract impact

Applied identically across all four product repos, and mirrored in the routines' allowed_tools (which is the layer that certainly applies in cloud — repo settings may not load there, since the session root is /home/user and repos are subdirectories).

Test results

  • python3 -c "import json; json.load(...)" — valid JSON

Notes for reviewer

Everything the loop writes still lands as a PR you review; this removes the approval prompt, not the review.

…ended

The autonomous loop stalled awaiting approval to edit .claude/rules/tests.md
and .claude/docs/environment.md during a docs-sync step. All loop output is
reviewed as PRs anyway, so gating these edits behind a live approval only
stalls unattended runs without adding review.

Allows Edit/Write on .claude/docs, .claude/rules, .claude/skills, CLAUDE.md
and AGENTS.md. Deliberately NOT .claude/settings.json or .claude/hooks —
a hook edit is arbitrary code execution in the reviewer's own session, so
those keep requiring approval.

Co-Authored-By: Claude Opus 5 <[email protected]>
@Ardnived
Ardnived merged commit 60e80f9 into main Aug 31, 2026
@Ardnived
Ardnived deleted the claude/allow-doc-self-edits branch August 31, 2026 21:16
Ardnived added a commit that referenced this pull request Sep 1, 2026
…irectory (#669)

* refactor(claude): move rules and docs out of the protected .claude/ directory

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]>

* refactor(claude): symlink the non-directory rules from docs/ instead 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]>

---------

Co-authored-by: Claude Opus 5 (1M context) <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant