Docs Architect — AI-Optimized Documentation (v2)
Build and maintain documentation that rides on Claude Code's native loading mechanisms. Cuts AI token consumption by 20–40% versus the v1 custom-summary pattern while preserving all information and giving humans a clean reference.
Core principle
Docs are a knowledge base. The AI receives only what is strictly necessary per task. v2 uses the official .claude/rules/ mechanism with two loading modes:
- Always-loaded rules — frontmatter-less
.claude/rules/*.md files load at session start alongside CLAUDE.md. Use for universally-needed content (business, stack, conventions, core architecture).
- Path-scoped rules —
.claude/rules/*.md with paths: frontmatter auto-load only when Claude reads matching files. Zero startup token cost. Use for subsystem-specific rules (backend, frontend, api, database, testing).
Full human docs live in docs/*.md as the source of truth. .claude/rules/*.md are lean (≤40 lines, ≤12 bullets) distillations mirrored from the full docs.
Architecture
./CLAUDE.md # <100 lines — hard NOs + pointer to rules
./.claude/rules/ # AI-facing rules (flat, no subfolders)
├── business-context.md # always-loaded
├── coding-rules.md # always-loaded
├── tech-stack.md # always-loaded
├── architecture.md # always-loaded
├── backend.md # path-scoped: backend/**
├── frontend.md # path-scoped: frontend/**
├── api.md # path-scoped: **/Controllers/**, **/routes/**
├── database.md # path-scoped: **/Entities/**, **/migrations/**
└── testing.md # path-scoped: **/*.test.*, **/tests/**
./.claude/agents/doc-explorer.md # research subagent (isolated context)
./.claude/commands/ # /docs-audit, /docs-sync, /docs-migrate
./docs/ # full human-readable reference
├── README.md # governance + index
├── architecture.md # full architecture doc
├── coding-rules.md # full conventions
├── tech-stack.md # full package catalog
├── api-contracts.md # full endpoint catalog
├── database-schema.md # full table catalog
├── deployment.md # full dev/prod reference
├── roadmap.md # product phases, KPIs, decisions
├── backlog.md # story registry
├── bugs.md # bug registry
├── ideas.md # raw ideas inbox
├── stories/ bugs/ plans/ # individual item files
└── research/ # deep reference docs
Modes
| Mode |
Purpose |
Primary reference to read |
/docs-architect |
Interactive — analyze, ask, build |
Step 1, then files as needed per step |
/docs-architect init |
Full v2 setup on a new or clean project |
assets/CLAUDE.md.template + assets/docs-README.md.template + references/governance.md + references/common-specs.md |
/docs-architect audit |
Audit structure + auto-fix offers |
references/audit-report.md |
/docs-architect sync |
Detect docs drift from code |
none (uses git diff + doc-explorer subagent) |
/docs-architect migrate |
Convert v1 _lite/ pattern to v2 .claude/rules/ |
references/migration-v1-to-v2.md |
/docs-architect segment <file> |
Segment a large doc |
references/common-specs.md §Segmentation patterns |
For everything related to hooks, subagents, settings precedence, built-in commands, claudeMdExcludes, and .claude/rules/ format details, read references/claude-code-native.md on demand.
Step 1: Analyze the project
Before creating or changing anything, understand the current state.
- Scan existing docs — check if
docs/ exists, list files with line counts.
- Scan
.claude/rules/ — check if the v2 layout is already in place.
- Check for legacy
_lite/ — if docs/_lite/*.summary.md exists, this is a v1 project → recommend /docs-architect migrate.
- Read CLAUDE.md — measure size (target <100 lines), look for stale
@docs/_lite/* imports.
- Detect documentation language — look for
Documentation language in CLAUDE.md Conventions. If not declared, ask the user. All generated docs must use this language.
- Identify the stack — backend, frontend, database, infra.
- Identify subtrees — backend/, frontend/, src/api/, src/components/, etc. These drive which path-scoped rules to install.
for f in docs/*.md; do lines=$(wc -l < "$f" 2>/dev/null); echo "$lines $f"; done 2>/dev/null | sort -rn
wc -l CLAUDE.md 2>/dev/null
ls .claude/rules/ 2>/dev/null
ls docs/_lite/ 2>/dev/null
Step 2: Create or optimize CLAUDE.md
Hard limit: under 100 lines. Copy from assets/CLAUDE.md.template and adapt. CLAUDE.md holds only:
- 1-2 line context
- Hard NOs (max 5 items — the single most destructive patterns for this project)
- Documentation language + code language declarations
- 1-2 universal conventions
- Process rules (branching, commits, CI)
- A pointer block explaining where context comes from (
.claude/rules/*.md for AI, docs/*.md for humans)
Everything else belongs in .claude/rules/. No @imports. No tables of summaries. No tech stack details. No business context.
Monorepo note: if the project is a monorepo and ancestor CLAUDE.md files would load unnecessarily, add claudeMdExcludes to .claude/settings.json. See references/claude-code-native.md §Monorepos.
Step 3: Create docs/README.md
The governance document for the docs/ folder. Copy from assets/docs-README.md.template. Contains: folder structure tree, 2-layer usage guide (humans + AI), AI rules, update table, and index. Keep under 200 lines.
All governance rules come from references/governance.md:
- Stories/bugs/plans tracking — mandatory priority/severity, dual-update rule (registry + individual file)
- File naming conventions —
{NNNNN}-{slug}.{type}.md
- Documentation management — no
.md outside docs/ (except CLAUDE.md, .claude/rules/, .claude/agents/, .claude/commands/), never mix languages
- Dual-update rule — when updating a
.claude/rules/*.md that mirrors a docs/*.md, update the full doc in the same commit (and vice versa)
- Ideas → Story pipeline — raw ideas land in
ideas.md, group via /brainstorming, promote to story + backlog.md entry
- Research —
research/ holds deep-reference docs consulted on-demand (no rule mirror)
- Frontend workflow (if applicable) — 3-step pipeline: product definition → design exploration → UX validation
- Git and code safety — all prohibitions (no autonomous migrations, no
git add ., no --force, no --no-verify, no --amend without request)
Step 4: Create full docs
Each full doc in docs/*.md is the source of truth. If a doc already exists, read it first and restructure — do NOT overwrite with a blank template.
Full doc specs
Read the specific spec on-demand from references/:
Individual specs (large docs): architecture-spec.md (10 sections) · coding-rules-spec.md (17) · api-contracts-spec.md (10+5) · database-schema-spec.md (10+5)
Common specs (one file): common-specs.md — backlog, bugs, tech-stack, deployment, roadmap (never remove business content), dev-testing, plus segmentation patterns table.
Research files (docs/research/<topic>.md): free-form deep reference. One file per topic. No rule mirror. Consult before the work type it covers.
Priority, severity, status
See references/governance.md for priority/severity definitions (ASAP/Critical/High/Medium/Low) and status definitions per item type (Pending/Open/Draft → … → Completed/Resolved).
Individual file templates
- assets/story.md.template — created at
In progress
- assets/bug.md.template
- assets/plan.md.template
Step 5: Create .claude/rules/ — the v2 core
.claude/rules/*.md replaces v1's _lite/ entirely. Two loading modes.
Decision table
| Rule applies… |
Loading mode |
Frontmatter |
| Every session, globally |
always-loaded |
none |
| Only when Claude touches a specific subtree |
path-scoped |
paths: with globs |
| On-demand reference only (humans or deep research) |
not a rule |
put in docs/*.md full file |
Always-loaded rules (no frontmatter)
Install these four from assets/rules/_always/*.md (copied flat into .claude/rules/, no subfolder):
- assets/rules/_always/business-context.md →
.claude/rules/business-context.md
- assets/rules/_always/coding-rules.md →
.claude/rules/coding-rules.md
- assets/rules/_always/tech-stack.md →
.claude/rules/tech-stack.md
- assets/rules/_always/architecture.md →
.claude/rules/architecture.md
Path-scoped rules (with paths: frontmatter)
Install the ones that match the project's subtrees. Ask the user which apply.
- assets/rules/backend.md →
.claude/rules/backend.md
- assets/rules/frontend.md →
.claude/rules/frontend.md
- assets/rules/api.md →
.claude/rules/api.md
- assets/rules/database.md →
.claude/rules/database.md
- assets/rules/testing.md →
.claude/rules/testing.md
Rules size limits
Each .claude/rules/*.md file: ≤40 lines, ≤12 bullets. Focus on constraints, decisions, and hard NOs. No narrative. Full narrative belongs in docs/*.md.
For exact .claude/rules/ format details (globs, precedence, flat-folder rule), read references/claude-code-native.md §.claude/rules/.
Step 6: Install native .claude/ artifacts
After rules, install the three Claude Code native artifacts that make the skill turn-key.
Agent
Copy assets/agents/doc-explorer.md → .claude/agents/doc-explorer.md. This subagent runs in isolated context (model: haiku) and handles doc audits, sync scans, and research without polluting the main session. Audit and sync modes delegate to it by default.
Slash commands
Copy all three:
- assets/commands/docs-audit.md →
.claude/commands/docs-audit.md
- assets/commands/docs-sync.md →
.claude/commands/docs-sync.md
- assets/commands/docs-migrate.md →
.claude/commands/docs-migrate.md
Users invoke these as /docs-audit, /docs-sync, /docs-migrate — no need to remember skill mode syntax.
Hook snippet (print-only)
Never auto-merge into .claude/settings.json. Print the contents of assets/hooks/settings.snippet.json to the user and say:
Paste this hooks block into .claude/settings.json (merge with any existing hooks). The docs-architect skill does not modify settings.json.
The snippet adds:
- SessionStart hook: warns if CLAUDE.md >100 lines
- PostToolUse hook: flags presence of legacy
docs/_lite/ files after Write/Edit
For full hook event catalogue and JSON format, see references/claude-code-native.md §Hooks.
Step 7: Segment large files
Any docs/*.md file over 150 lines should be segmented into subtopic files.
Process
- Read the full file.
- Identify 3–6 logical topics.
- Create
docs/<name>/ folder with one file per topic + README.md index.
- Keep the original file intact — it remains the full reference.
- Update the corresponding
.claude/rules/*.md file only if the segmentation changed the underlying facts.
Templates, header format, and common segmentation patterns (which doc splits by what axis) live in references/common-specs.md §Segmentation patterns.
Sync rule: the full doc is the source of truth. Never edit a segment without also editing the full doc.
Step 8: Audit mode
When invoked with /docs-architect audit, delegate the file scan to doc-explorer subagent when possible, run all checks, then offer to auto-fix.
Checks
- CLAUDE.md over 100 lines → flag, propose trimming
- CLAUDE.md containing
@docs/_lite/* imports → stale v1 pattern, suggest /docs-migrate
- CLAUDE.md missing
Documentation language declaration → ask and add
- Missing always-loaded
.claude/rules/*.md files (business-context, coding-rules, tech-stack, architecture) → install from assets
.claude/rules/*.md files over 40 lines → flag, ask to trim
.claude/rules/*.md with paths: patterns matching zero files → dead scope, suggest removing or fixing the globs
- Repo has backend/ or frontend/ or
**/Controllers/ but no matching path-scoped rule → missed token savings, offer to install from assets
- Missing
.claude/agents/doc-explorer.md when docs/ has ≥10 files → install
- Missing
/docs-audit, /docs-sync, /docs-migrate slash commands → install from assets
- Legacy
docs/_lite/*.summary.md (not .deprecated) present → suggest /docs-migrate
docs/*.md files over 150 lines without segmentation → flag
- Stories/bugs consistency: registry vs individual files (orphans, broken links, status mismatches)
docs/README.md missing or over 200 lines
- Pending ideas in
ideas.md ≥5 items → suggest grouping and promotion
- Referenced
research/ files missing
See references/audit-report.md for the output format.
Auto-fix
After the report, offer to fix each issue. Group fixes by type and confirm before applying.
| Issue |
Auto-fix action |
| Missing always-loaded rule |
Copy from assets/rules/_always/*.md |
| Missing path-scoped rule (subtree detected) |
Copy from assets/rules/*.md |
| Dead path pattern |
Ask user to correct the glob or remove the rule |
| Rule >40 lines |
Show top offenders, ask which bullets to cut |
| CLAUDE.md >100 lines |
Identify offloadable content, propose moving it to .claude/rules/ |
Missing docs/README.md |
Generate from template |
| Orphaned story/bug file |
Add missing entry to registry |
| Registry points to missing file |
Remove broken link |
| Status mismatch |
Show both, ask which is correct, update the other |
Legacy _lite/ present |
Offer to run /docs-architect migrate |
| Missing doc-explorer agent |
Copy from assets |
| Missing slash commands |
Copy from assets |
Flow: report → "Found X fixable issues. Fix all / fix individually / skip?" → apply selected fixes → re-run checks to confirm.
Step 9: Sync mode
When invoked with /docs-architect sync, detect which docs and rules are out of date relative to code changes.
Process
Find the last commit that touched docs or rules:
git log --oneline --all -- docs/ .claude/rules/ | head -1
Get all files changed since that commit:
git diff --name-only <last-docs-commit>..HEAD
Delegate the mapping analysis to the doc-explorer subagent if the change list is ≥20 files. Otherwise do it inline. Subagent runs in isolated context — its reads don't bloat the main session.
Map changed code files to affected rules and full docs:
| Changed files match |
Update rule |
Update full doc |
*.csproj, Directory.Packages.props, package.json, Cargo.toml, requirements.txt, go.mod |
tech-stack.md |
tech-stack.md |
docker-compose*, Dockerfile*, .env*, web.config, nginx.conf |
(none — no rule mirror) |
deployment.md |
Controllers, routes, endpoints (*Controller*, *Endpoint*, *Route*) |
api.md |
api-contracts.md |
Entity/model files, migrations (*Migration*, *Entity*, *Model*) |
database.md |
database-schema.md |
| Domain layer, patterns, middleware, interceptors |
architecture.md |
architecture.md |
| Naming conventions, validators, new patterns |
coding-rules.md |
coding-rules.md |
| Test files |
testing.md |
coding-rules.md (coverage section) |
- Output a sync report:
## Docs Sync Report
Last docs update: <commit-hash> (<date>)
Code commits since: <count>
### Rules + docs needing update
- .claude/rules/tech-stack.md + docs/tech-stack.md — 3 package files changed (list)
- .claude/rules/api.md + docs/api-contracts.md — 2 controllers modified (list)
- docs/deployment.md (rule-less) — docker-compose.yml changed
### Current
- .claude/rules/architecture.md + docs/architecture.md ✓
- .claude/rules/coding-rules.md + docs/coding-rules.md ✓
### Action
Update affected files now? [yes / pick individually / skip]
- If user confirms, read each affected rule + doc, read the changed code files, and apply the update. Dual update always — rule + full doc.
Step 10: Migrate mode (v1 → v2)
When invoked with /docs-architect migrate, convert a v1 project (custom _lite/ pattern) to v2 (.claude/rules/).
Read references/migration-v1-to-v2.md first. It has the full mapping table, examples, and safety rules.
Flow summary
- Scan
docs/_lite/*.summary.md, list files.
- For each summary, propose a
.claude/rules/*.md target (always-loaded vs path-scoped) based on the mapping table in the migration reference.
- Show the full mapping to the user, ask for confirmation or edits.
- Copy content into new
.claude/rules/*.md files, adding paths: frontmatter where applicable, stripping Source: lines (replaced with <!-- mirrors: docs/<file>.md -->).
- Rename originals to
docs/_lite/*.summary.md.deprecated. Never delete.
- Update
CLAUDE.md to remove the old _lite/ pointer table.
- Update
docs/README.md to describe the 2-layer v2 flow.
- Run
/docs-audit to verify.
- Tell the user: "Migration complete. Originals preserved as
.deprecated. Run rm docs/_lite/*.deprecated after verifying a fresh session loads context correctly."
Safety
- Never deletes files
- Never writes to
.claude/settings.json
- Never runs git commands
- Never modifies
docs/*.md full files (only creates new .claude/rules/*.md and renames _lite/ files)
Execution guidelines
- Use the
doc-explorer subagent for any task involving reading many files to answer one question (audits, syncs, coverage checks). Install it from assets/agents/doc-explorer.md during init so it's always available.
- Always read before writing — understand existing content before restructuring.
- Preserve originals — migrations and segmentation are additive. Never delete.
- Match project language — read
Documentation language from CLAUDE.md. If not declared, ask the user.
- Commit atomically — one commit per logical change.
- Update
docs/README.md last — after all other files are created or updated.
- Dual-update rule — when a
.claude/rules/*.md has a corresponding docs/*.md, update both in the same commit.
- Never load multiple full docs at once — the rules should be enough to orient. Read one full doc when detail is needed.
New project (/docs-architect init)
- Ask: project name, stack (backend / frontend / both), documentation language, which path-scoped rules apply (backend, frontend, api, database, testing — multi-select).
- Create
CLAUDE.md from assets/CLAUDE.md.template.
- Create
docs/README.md from assets/docs-README.md.template.
- Create full docs (
architecture.md, api-contracts.md, database-schema.md, coding-rules.md, tech-stack.md, deployment.md, roadmap.md, backlog.md, bugs.md, ideas.md). No _lite/ folder.
- Copy
assets/rules/_always/*.md flat into .claude/rules/ (4 always-loaded files).
- Copy the user-selected path-scoped rules into
.claude/rules/.
- Code-scan auto-fill (see below) — populate both the new
.claude/rules/*.md files AND the full docs/*.md files from real codebase content.
- Copy
assets/commands/*.md into .claude/commands/.
- Copy
assets/agents/doc-explorer.md into .claude/agents/.
- Print the contents of assets/hooks/settings.snippet.json and tell the user to paste it into
.claude/settings.json.
Code scanning for auto-fill
Scan the codebase to pre-populate both rules and docs with real content:
| Scan target |
How to find |
Pre-fills |
| Stack & packages |
Read *.csproj + Directory.Packages.props (or package.json, Cargo.toml, requirements.txt, go.mod) |
docs/tech-stack.md + .claude/rules/tech-stack.md |
| Infrastructure |
Read docker-compose*.yml, Dockerfile*, .env* |
docs/deployment.md |
| Architecture |
List project folders + read key files (Program.cs, Startup, middleware, DI registration) |
docs/architecture.md + .claude/rules/architecture.md |
| API endpoints |
Read controllers/routes, auth filters, middleware registration |
docs/api-contracts.md + .claude/rules/api.md |
| Database schema |
Read entity/model files, DbContext, migrations |
docs/database-schema.md + .claude/rules/database.md |
| Coding patterns |
Read existing code for naming, patterns, validation, error handling |
docs/coding-rules.md + .claude/rules/coding-rules.md |
| Business context |
Read existing README, comments, domain entities |
.claude/rules/business-context.md |
Rules for auto-fill:
- Mark auto-generated sections with
<!-- auto-generated from codebase scan --> so the user knows what to review.
- If a source file doesn't exist (e.g., no docker-compose), skip that doc section — don't create empty placeholders.
- Always ask the user to review auto-filled content before committing.
- Prefer being incomplete over being wrong — if unsure, note as
TODO: verify rather than guessing.
Existing v1 project (/docs-architect migrate)
- Read ALL existing docs and
_lite/ files before making any changes.
- Follow Step 10 (migrate mode) exactly.
- Never delete content — only restructure, rename, copy.
- Always show the user the mapping table BEFORE applying it.
Existing v2 project (/docs-architect or /docs-architect audit)
- Read ALL existing docs and
.claude/rules/*.md before making any changes.
- Never delete content — only restructure, move, or update.
- If CLAUDE.md is over 100 lines, identify what to offload to
.claude/rules/.
- Always show the user what you plan to change BEFORE doing it.
1---2name: docs-architect3description: Set up, migrate, and maintain a project's documentation for maximum AI context efficiency using Claude Code's native mechanisms. Builds a 2-layer system (`.claude/rules/*.md` for the AI + `docs/*.md` for humans) that cuts startup tokens 20-40% vs custom summary patterns. Triggers — "set up docs structure", "optimize docs for AI", "install .claude/rules", "migrate _lite to rules", "audit docs", "sync docs with code", "docs-architect", "estructura de documentacion".4---56# Docs Architect — AI-Optimized Documentation (v2)78Build and maintain documentation that rides on Claude Code's native loading mechanisms. Cuts AI token consumption by 20–40% versus the v1 custom-summary pattern while preserving all information and giving humans a clean reference.910## Core principle1112Docs are a knowledge base. The AI receives only what is strictly necessary per task. v2 uses the official `.claude/rules/` mechanism with two loading modes:1314- **Always-loaded rules** — frontmatter-less `.claude/rules/*.md` files load at session start alongside `CLAUDE.md`. Use for universally-needed content (business, stack, conventions, core architecture).15- **Path-scoped rules** — `.claude/rules/*.md` with `paths:` frontmatter auto-load **only** when Claude reads matching files. Zero startup token cost. Use for subsystem-specific rules (backend, frontend, api, database, testing).1617Full human docs live in `docs/*.md` as the source of truth. `.claude/rules/*.md` are lean (≤40 lines, ≤12 bullets) distillations mirrored from the full docs.1819## Architecture2021```22./CLAUDE.md # <100 lines — hard NOs + pointer to rules23./.claude/rules/ # AI-facing rules (flat, no subfolders)24 ├── business-context.md # always-loaded25 ├── coding-rules.md # always-loaded26 ├── tech-stack.md # always-loaded27 ├── architecture.md # always-loaded28 ├── backend.md # path-scoped: backend/**29 ├── frontend.md # path-scoped: frontend/**30 ├── api.md # path-scoped: **/Controllers/**, **/routes/**31 ├── database.md # path-scoped: **/Entities/**, **/migrations/**32 └── testing.md # path-scoped: **/*.test.*, **/tests/**33./.claude/agents/doc-explorer.md # research subagent (isolated context)34./.claude/commands/ # /docs-audit, /docs-sync, /docs-migrate35./docs/ # full human-readable reference36 ├── README.md # governance + index37 ├── architecture.md # full architecture doc38 ├── coding-rules.md # full conventions39 ├── tech-stack.md # full package catalog40 ├── api-contracts.md # full endpoint catalog41 ├── database-schema.md # full table catalog42 ├── deployment.md # full dev/prod reference43 ├── roadmap.md # product phases, KPIs, decisions44 ├── backlog.md # story registry45 ├── bugs.md # bug registry46 ├── ideas.md # raw ideas inbox47 ├── stories/ bugs/ plans/ # individual item files48 └── research/ # deep reference docs49```5051---5253## Modes5455| Mode | Purpose | Primary reference to read |56|---|---|---|57| `/docs-architect` | Interactive — analyze, ask, build | Step 1, then files as needed per step |58| `/docs-architect init` | Full v2 setup on a new or clean project | [assets/CLAUDE.md.template](assets/CLAUDE.md.template) + [assets/docs-README.md.template](assets/docs-README.md.template) + [references/governance.md](references/governance.md) + [references/common-specs.md](references/common-specs.md) |59| `/docs-architect audit` | Audit structure + auto-fix offers | [references/audit-report.md](references/audit-report.md) |60| `/docs-architect sync` | Detect docs drift from code | none (uses git diff + `doc-explorer` subagent) |61| `/docs-architect migrate` | Convert v1 `_lite/` pattern to v2 `.claude/rules/` | [references/migration-v1-to-v2.md](references/migration-v1-to-v2.md) |62| `/docs-architect segment <file>` | Segment a large doc | [references/common-specs.md](references/common-specs.md) §Segmentation patterns |6364For everything related to hooks, subagents, settings precedence, built-in commands, `claudeMdExcludes`, and `.claude/rules/` format details, read [references/claude-code-native.md](references/claude-code-native.md) on demand.6566---6768## Step 1: Analyze the project6970Before creating or changing anything, understand the current state.71721. **Scan existing docs** — check if `docs/` exists, list files with line counts.732. **Scan `.claude/rules/`** — check if the v2 layout is already in place.743. **Check for legacy `_lite/`** — if `docs/_lite/*.summary.md` exists, this is a v1 project → recommend `/docs-architect migrate`.754. **Read CLAUDE.md** — measure size (target <100 lines), look for stale `@docs/_lite/*` imports.765. **Detect documentation language** — look for `Documentation language` in CLAUDE.md Conventions. If not declared, ask the user. All generated docs must use this language.776. **Identify the stack** — backend, frontend, database, infra.787. **Identify subtrees** — backend/, frontend/, src/api/, src/components/, etc. These drive which path-scoped rules to install.7980```bash81for f in docs/*.md; do lines=$(wc -l < "$f" 2>/dev/null); echo "$lines $f"; done 2>/dev/null | sort -rn82wc -l CLAUDE.md 2>/dev/null83ls .claude/rules/ 2>/dev/null84ls docs/_lite/ 2>/dev/null85```8687---8889## Step 2: Create or optimize CLAUDE.md9091**Hard limit: under 100 lines.** Copy from [assets/CLAUDE.md.template](assets/CLAUDE.md.template) and adapt. CLAUDE.md holds only:9293- 1-2 line context94- Hard NOs (max 5 items — the single most destructive patterns for this project)95- Documentation language + code language declarations96- 1-2 universal conventions97- Process rules (branching, commits, CI)98- A pointer block explaining where context comes from (`.claude/rules/*.md` for AI, `docs/*.md` for humans)99100Everything else belongs in `.claude/rules/`. No `@imports`. No tables of summaries. No tech stack details. No business context.101102**Monorepo note**: if the project is a monorepo and ancestor `CLAUDE.md` files would load unnecessarily, add `claudeMdExcludes` to `.claude/settings.json`. See [references/claude-code-native.md](references/claude-code-native.md) §Monorepos.103104---105106## Step 3: Create docs/README.md107108The **governance document** for the `docs/` folder. Copy from [assets/docs-README.md.template](assets/docs-README.md.template). Contains: folder structure tree, 2-layer usage guide (humans + AI), AI rules, update table, and index. Keep under 200 lines.109110All governance rules come from [references/governance.md](references/governance.md):111112- **Stories/bugs/plans tracking** — mandatory priority/severity, dual-update rule (registry + individual file)113- **File naming conventions** — `{NNNNN}-{slug}.{type}.md`114- **Documentation management** — no `.md` outside `docs/` (except CLAUDE.md, `.claude/rules/`, `.claude/agents/`, `.claude/commands/`), never mix languages115- **Dual-update rule** — when updating a `.claude/rules/*.md` that mirrors a `docs/*.md`, update the full doc in the same commit (and vice versa)116- **Ideas → Story pipeline** — raw ideas land in `ideas.md`, group via `/brainstorming`, promote to story + `backlog.md` entry117- **Research** — `research/` holds deep-reference docs consulted on-demand (no rule mirror)118- **Frontend workflow** (if applicable) — 3-step pipeline: product definition → design exploration → UX validation119- **Git and code safety** — all prohibitions (no autonomous migrations, no `git add .`, no `--force`, no `--no-verify`, no `--amend` without request)120121---122123## Step 4: Create full docs124125Each full doc in `docs/*.md` is the source of truth. If a doc already exists, **read it first** and restructure — do NOT overwrite with a blank template.126127### Full doc specs128129Read the specific spec on-demand from `references/`:130131**Individual specs (large docs)**: [architecture-spec.md](references/architecture-spec.md) (10 sections) · [coding-rules-spec.md](references/coding-rules-spec.md) (17) · [api-contracts-spec.md](references/api-contracts-spec.md) (10+5) · [database-schema-spec.md](references/database-schema-spec.md) (10+5)132133**Common specs (one file)**: [common-specs.md](references/common-specs.md) — backlog, bugs, tech-stack, deployment, roadmap (never remove business content), dev-testing, plus segmentation patterns table.134135**Research files** (`docs/research/<topic>.md`): free-form deep reference. One file per topic. No rule mirror. Consult before the work type it covers.136137### Priority, severity, status138139See [references/governance.md](references/governance.md) for priority/severity definitions (ASAP/Critical/High/Medium/Low) and status definitions per item type (Pending/Open/Draft → … → Completed/Resolved).140141### Individual file templates142143- [assets/story.md.template](assets/story.md.template) — created at `In progress`144- [assets/bug.md.template](assets/bug.md.template)145- [assets/plan.md.template](assets/plan.md.template)146147---148149## Step 5: Create `.claude/rules/` — the v2 core150151`.claude/rules/*.md` replaces v1's `_lite/` entirely. Two loading modes.152153### Decision table154155| Rule applies… | Loading mode | Frontmatter |156|---|---|---|157| Every session, globally | always-loaded | none |158| Only when Claude touches a specific subtree | path-scoped | `paths:` with globs |159| On-demand reference only (humans or deep research) | not a rule | put in `docs/*.md` full file |160161### Always-loaded rules (no frontmatter)162163Install these four from `assets/rules/_always/*.md` (copied flat into `.claude/rules/`, no subfolder):164165- [assets/rules/_always/business-context.md](assets/rules/_always/business-context.md) → `.claude/rules/business-context.md`166- [assets/rules/_always/coding-rules.md](assets/rules/_always/coding-rules.md) → `.claude/rules/coding-rules.md`167- [assets/rules/_always/tech-stack.md](assets/rules/_always/tech-stack.md) → `.claude/rules/tech-stack.md`168- [assets/rules/_always/architecture.md](assets/rules/_always/architecture.md) → `.claude/rules/architecture.md`169170### Path-scoped rules (with `paths:` frontmatter)171172Install the ones that match the project's subtrees. Ask the user which apply.173174- [assets/rules/backend.md](assets/rules/backend.md) → `.claude/rules/backend.md`175- [assets/rules/frontend.md](assets/rules/frontend.md) → `.claude/rules/frontend.md`176- [assets/rules/api.md](assets/rules/api.md) → `.claude/rules/api.md`177- [assets/rules/database.md](assets/rules/database.md) → `.claude/rules/database.md`178- [assets/rules/testing.md](assets/rules/testing.md) → `.claude/rules/testing.md`179180### Rules size limits181182Each `.claude/rules/*.md` file: ≤40 lines, ≤12 bullets. Focus on constraints, decisions, and hard NOs. No narrative. Full narrative belongs in `docs/*.md`.183184For exact `.claude/rules/` format details (globs, precedence, flat-folder rule), read [references/claude-code-native.md](references/claude-code-native.md) §`.claude/rules/`.185186---187188## Step 6: Install native `.claude/` artifacts189190After rules, install the three Claude Code native artifacts that make the skill turn-key.191192### Agent193194Copy [assets/agents/doc-explorer.md](assets/agents/doc-explorer.md) → `.claude/agents/doc-explorer.md`. This subagent runs in isolated context (model: haiku) and handles doc audits, sync scans, and research without polluting the main session. Audit and sync modes delegate to it by default.195196### Slash commands197198Copy all three:199200- [assets/commands/docs-audit.md](assets/commands/docs-audit.md) → `.claude/commands/docs-audit.md`201- [assets/commands/docs-sync.md](assets/commands/docs-sync.md) → `.claude/commands/docs-sync.md`202- [assets/commands/docs-migrate.md](assets/commands/docs-migrate.md) → `.claude/commands/docs-migrate.md`203204Users invoke these as `/docs-audit`, `/docs-sync`, `/docs-migrate` — no need to remember skill mode syntax.205206### Hook snippet (print-only)207208**Never auto-merge** into `.claude/settings.json`. Print the contents of [assets/hooks/settings.snippet.json](assets/hooks/settings.snippet.json) to the user and say:209210> Paste this `hooks` block into `.claude/settings.json` (merge with any existing hooks). The docs-architect skill does not modify settings.json.211212The snippet adds:213- **SessionStart** hook: warns if CLAUDE.md >100 lines214- **PostToolUse** hook: flags presence of legacy `docs/_lite/` files after Write/Edit215216For full hook event catalogue and JSON format, see [references/claude-code-native.md](references/claude-code-native.md) §Hooks.217218---219220## Step 7: Segment large files221222Any `docs/*.md` file over **150 lines** should be segmented into subtopic files.223224### Process2252261. Read the full file.2272. Identify 3–6 logical topics.2283. Create `docs/<name>/` folder with one file per topic + `README.md` index.2294. **Keep the original file intact** — it remains the full reference.2305. Update the corresponding `.claude/rules/*.md` file only if the segmentation changed the underlying facts.231232Templates, header format, and common segmentation patterns (which doc splits by what axis) live in [references/common-specs.md](references/common-specs.md) §Segmentation patterns.233234**Sync rule**: the full doc is the source of truth. Never edit a segment without also editing the full doc.235236---237238## Step 8: Audit mode239240When invoked with `/docs-architect audit`, delegate the file scan to `doc-explorer` subagent when possible, run all checks, then offer to auto-fix.241242### Checks2432441. CLAUDE.md over 100 lines → flag, propose trimming2452. CLAUDE.md containing `@docs/_lite/*` imports → stale v1 pattern, suggest `/docs-migrate`2463. CLAUDE.md missing `Documentation language` declaration → ask and add2474. Missing always-loaded `.claude/rules/*.md` files (business-context, coding-rules, tech-stack, architecture) → install from assets2485. `.claude/rules/*.md` files over 40 lines → flag, ask to trim2496. `.claude/rules/*.md` with `paths:` patterns matching zero files → dead scope, suggest removing or fixing the globs2507. Repo has backend/ or frontend/ or `**/Controllers/` but no matching path-scoped rule → missed token savings, offer to install from assets2518. Missing `.claude/agents/doc-explorer.md` when `docs/` has ≥10 files → install2529. Missing `/docs-audit`, `/docs-sync`, `/docs-migrate` slash commands → install from assets25310. Legacy `docs/_lite/*.summary.md` (not `.deprecated`) present → suggest `/docs-migrate`25411. `docs/*.md` files over 150 lines without segmentation → flag25512. Stories/bugs consistency: registry vs individual files (orphans, broken links, status mismatches)25613. `docs/README.md` missing or over 200 lines25714. Pending ideas in `ideas.md` ≥5 items → suggest grouping and promotion25815. Referenced `research/` files missing259260See [references/audit-report.md](references/audit-report.md) for the output format.261262### Auto-fix263264After the report, offer to fix each issue. Group fixes by type and confirm before applying.265266| Issue | Auto-fix action |267|---|---|268| Missing always-loaded rule | Copy from `assets/rules/_always/*.md` |269| Missing path-scoped rule (subtree detected) | Copy from `assets/rules/*.md` |270| Dead path pattern | Ask user to correct the glob or remove the rule |271| Rule >40 lines | Show top offenders, ask which bullets to cut |272| CLAUDE.md >100 lines | Identify offloadable content, propose moving it to `.claude/rules/` |273| Missing `docs/README.md` | Generate from template |274| Orphaned story/bug file | Add missing entry to registry |275| Registry points to missing file | Remove broken link |276| Status mismatch | Show both, ask which is correct, update the other |277| Legacy `_lite/` present | Offer to run `/docs-architect migrate` |278| Missing doc-explorer agent | Copy from assets |279| Missing slash commands | Copy from assets |280281**Flow**: report → "Found X fixable issues. Fix all / fix individually / skip?" → apply selected fixes → re-run checks to confirm.282283---284285## Step 9: Sync mode286287When invoked with `/docs-architect sync`, detect which docs and rules are out of date relative to code changes.288289### Process2902911. **Find the last commit that touched docs or rules**:292 ```bash293 git log --oneline --all -- docs/ .claude/rules/ | head -1294 ```2952962. **Get all files changed since that commit**:297 ```bash298 git diff --name-only <last-docs-commit>..HEAD299 ```3003013. **Delegate the mapping analysis to the `doc-explorer` subagent** if the change list is ≥20 files. Otherwise do it inline. Subagent runs in isolated context — its reads don't bloat the main session.3023034. **Map changed code files to affected rules and full docs**:304305| Changed files match | Update rule | Update full doc |306|---|---|---|307| `*.csproj`, `Directory.Packages.props`, `package.json`, `Cargo.toml`, `requirements.txt`, `go.mod` | `tech-stack.md` | `tech-stack.md` |308| `docker-compose*`, `Dockerfile*`, `.env*`, `web.config`, `nginx.conf` | (none — no rule mirror) | `deployment.md` |309| Controllers, routes, endpoints (`*Controller*`, `*Endpoint*`, `*Route*`) | `api.md` | `api-contracts.md` |310| Entity/model files, migrations (`*Migration*`, `*Entity*`, `*Model*`) | `database.md` | `database-schema.md` |311| Domain layer, patterns, middleware, interceptors | `architecture.md` | `architecture.md` |312| Naming conventions, validators, new patterns | `coding-rules.md` | `coding-rules.md` |313| Test files | `testing.md` | `coding-rules.md` (coverage section) |3143155. **Output a sync report**:316```317## Docs Sync Report318319Last docs update: <commit-hash> (<date>)320Code commits since: <count>321322### Rules + docs needing update323- .claude/rules/tech-stack.md + docs/tech-stack.md — 3 package files changed (list)324- .claude/rules/api.md + docs/api-contracts.md — 2 controllers modified (list)325- docs/deployment.md (rule-less) — docker-compose.yml changed326327### Current328- .claude/rules/architecture.md + docs/architecture.md ✓329- .claude/rules/coding-rules.md + docs/coding-rules.md ✓330331### Action332Update affected files now? [yes / pick individually / skip]333```3343356. **If user confirms**, read each affected rule + doc, read the changed code files, and apply the update. Dual update always — rule + full doc.336337---338339## Step 10: Migrate mode (v1 → v2)340341When invoked with `/docs-architect migrate`, convert a v1 project (custom `_lite/` pattern) to v2 (`.claude/rules/`).342343**Read [references/migration-v1-to-v2.md](references/migration-v1-to-v2.md) first.** It has the full mapping table, examples, and safety rules.344345### Flow summary3463471. Scan `docs/_lite/*.summary.md`, list files.3482. For each summary, propose a `.claude/rules/*.md` target (always-loaded vs path-scoped) based on the mapping table in the migration reference.3493. Show the full mapping to the user, ask for confirmation or edits.3504. Copy content into new `.claude/rules/*.md` files, adding `paths:` frontmatter where applicable, stripping `Source:` lines (replaced with `<!-- mirrors: docs/<file>.md -->`).3515. **Rename** originals to `docs/_lite/*.summary.md.deprecated`. Never delete.3526. Update `CLAUDE.md` to remove the old `_lite/` pointer table.3537. Update `docs/README.md` to describe the 2-layer v2 flow.3548. Run `/docs-audit` to verify.3559. Tell the user: "Migration complete. Originals preserved as `.deprecated`. Run `rm docs/_lite/*.deprecated` after verifying a fresh session loads context correctly."356357### Safety358359- Never deletes files360- Never writes to `.claude/settings.json`361- Never runs git commands362- Never modifies `docs/*.md` full files (only creates new `.claude/rules/*.md` and renames `_lite/` files)363364---365366## Execution guidelines367368- **Use the `doc-explorer` subagent** for any task involving reading many files to answer one question (audits, syncs, coverage checks). Install it from [assets/agents/doc-explorer.md](assets/agents/doc-explorer.md) during `init` so it's always available.369- **Always read before writing** — understand existing content before restructuring.370- **Preserve originals** — migrations and segmentation are additive. Never delete.371- **Match project language** — read `Documentation language` from CLAUDE.md. If not declared, ask the user.372- **Commit atomically** — one commit per logical change.373- **Update `docs/README.md` last** — after all other files are created or updated.374- **Dual-update rule** — when a `.claude/rules/*.md` has a corresponding `docs/*.md`, update both in the same commit.375- **Never load multiple full docs at once** — the rules should be enough to orient. Read one full doc when detail is needed.376377### New project (`/docs-architect init`)3783791. Ask: project name, stack (backend / frontend / both), documentation language, which path-scoped rules apply (backend, frontend, api, database, testing — multi-select).3802. Create `CLAUDE.md` from [assets/CLAUDE.md.template](assets/CLAUDE.md.template).3813. Create `docs/README.md` from [assets/docs-README.md.template](assets/docs-README.md.template).3824. Create full docs (`architecture.md`, `api-contracts.md`, `database-schema.md`, `coding-rules.md`, `tech-stack.md`, `deployment.md`, `roadmap.md`, `backlog.md`, `bugs.md`, `ideas.md`). **No `_lite/` folder.**3835. Copy `assets/rules/_always/*.md` flat into `.claude/rules/` (4 always-loaded files).3846. Copy the user-selected path-scoped rules into `.claude/rules/`.3857. **Code-scan auto-fill** (see below) — populate both the new `.claude/rules/*.md` files AND the full `docs/*.md` files from real codebase content.3868. Copy `assets/commands/*.md` into `.claude/commands/`.3879. Copy `assets/agents/doc-explorer.md` into `.claude/agents/`.38810. **Print** the contents of [assets/hooks/settings.snippet.json](assets/hooks/settings.snippet.json) and tell the user to paste it into `.claude/settings.json`.389390#### Code scanning for auto-fill391392Scan the codebase to pre-populate both rules and docs with real content:393394| Scan target | How to find | Pre-fills |395|---|---|---|396| **Stack & packages** | Read `*.csproj` + `Directory.Packages.props` (or `package.json`, `Cargo.toml`, `requirements.txt`, `go.mod`) | `docs/tech-stack.md` + `.claude/rules/tech-stack.md` |397| **Infrastructure** | Read `docker-compose*.yml`, `Dockerfile*`, `.env*` | `docs/deployment.md` |398| **Architecture** | List project folders + read key files (Program.cs, Startup, middleware, DI registration) | `docs/architecture.md` + `.claude/rules/architecture.md` |399| **API endpoints** | Read controllers/routes, auth filters, middleware registration | `docs/api-contracts.md` + `.claude/rules/api.md` |400| **Database schema** | Read entity/model files, DbContext, migrations | `docs/database-schema.md` + `.claude/rules/database.md` |401| **Coding patterns** | Read existing code for naming, patterns, validation, error handling | `docs/coding-rules.md` + `.claude/rules/coding-rules.md` |402| **Business context** | Read existing README, comments, domain entities | `.claude/rules/business-context.md` |403404**Rules for auto-fill**:405406- Mark auto-generated sections with `<!-- auto-generated from codebase scan -->` so the user knows what to review.407- If a source file doesn't exist (e.g., no docker-compose), skip that doc section — don't create empty placeholders.408- Always ask the user to review auto-filled content before committing.409- Prefer being incomplete over being wrong — if unsure, note as `TODO: verify` rather than guessing.410411### Existing v1 project (`/docs-architect migrate`)4124131. Read ALL existing docs and `_lite/` files before making any changes.4142. Follow Step 10 (migrate mode) exactly.4153. **Never delete content** — only restructure, rename, copy.4164. Always show the user the mapping table BEFORE applying it.417418### Existing v2 project (`/docs-architect` or `/docs-architect audit`)4194201. Read ALL existing docs and `.claude/rules/*.md` before making any changes.4212. **Never delete content** — only restructure, move, or update.4223. If CLAUDE.md is over 100 lines, identify what to offload to `.claude/rules/`.4234. Always show the user what you plan to change BEFORE doing it.