| name | claude-md-init |
| version | 1.0.0 |
| description | [Documentation] Use when you need initialize, update, or refactor CLAUDE markdown from project-config JSON and codebase scan results. |
Quick Summary
Goal: Automate CLAUDE.md lifecycle โ generate from project-config.json + template, incrementally update marked sections, or refactor for token efficiency.
Workflow:
- Detect Mode โ init (no CLAUDE.md or
--mode init), update (--mode update), refactor (--mode refactor)
- Run Generator โ
node .claude/skills/claude-md-init/scripts/generate-claude-md.cjs --mode <mode>
- AI Fill โ Review output, fill creative sections (project description, golden rules inference)
- Verify โ Confirm output is valid, no project-specific leaks from template
- Sync Mirrors โ After CLAUDE.md is written (init/update/refactor), call
/sync-codex to regenerate the stale AGENTS.md + Codex mirror surfaces from the new CLAUDE.md
Key Rules:
- Generic โ works in any project by reading
docs/project-config.json
- Section markers (
<!-- SECTION:key -->) enable incremental updates without overwriting user content
- Conditional sections โ generated ONLY when config has matching data; empty config = section omitted
- Static framework sections (8 total) are portable across all projects
Bootstrap Gate (when CLAUDE.md is missing or incomplete)
This skill is the AI-runnable route the agent-files bootstrap gate offers when a portable
.claude install lands in a project without a root CLAUDE.md โ or with one that carries only
project-specific knowledge and is missing the universal portable guides. A single hook detects the gap
and routes here (shared detection lib: .claude/hooks/lib/agent-files-state.cjs):
init-prompt-gate.cjs (UserPromptSubmit) โ blocks the first prompt once project-config.json
is populated but CLAUDE.md / AGENTS.md is missing or incomplete. This UserPromptSubmit
gate is the sole agent-files bootstrap router.
Three-state detection per root file: missing โ routes to --mode init (fresh from template);
incomplete โ routes to --mode update (smart-merge โ preserves your project content, injects the
guides); ok โ no block. Completeness is decided by hasUniversalGuides(): a current-or-newer
sentinel (<!-- CK:UNIVERSAL-GUIDES v1 -->) โ complete; an older sentinel โ flag for update; no
sentinel โ fall back to scanning required anchors (First Action Decision, Workflow Step Advancement,
Task Planning Rules, Code Responsibility Hierarchy, Evidence-Based Reasoning) so legacy/hand-written
complete files still pass.
Run /claude-md-init (or the generator directly) to produce CLAUDE.md from
docs/project-config.json + template. The generated file ships the universal session-start guides
(workflow ask-confirm gate, workflow step-advancement + parallel-phase barrier, task-planning rules,
code hierarchy, naming, evidence/confidence rules) and stamps the sentinel at the top so the gate
recognizes it as complete. It also stamps the hook-independent Workflow-First Gate (from
.claude/skills/shared/workflow-first-gate.md, via stampHeader()) immediately after the sentinel โ
the primacy-anchor routing rule (bugโworkflow-bugfix workflow, feature/enhancementโworkflow-feature workflow) that
mirrors into AGENTS.md and survives with no hooks.
Opt-out โ to keep a project-only CLAUDE.md/AGENTS.md (your custom knowledge, none of the
universal guides), set portability.requireUniversalGuides: false in docs/project-config.json
(persistent; default true). The gate then checks only existence, never completeness. The transient
skip init escape still dismisses both hooks for 24h. The gate is dormant in empty/greenfield folders
and before config is populated. AGENTS.md is generated separately by /sync-codex (user-invoke-only).
Modes
| Mode | When | Behavior |
|---|
init | No CLAUDE.md exists, or first-time setup | Generate fresh CLAUDE.md from template + config. Populates all markers. |
update | CLAUDE.md exists with markers | Replace only content between markers. Preserve everything else. |
refactor | CLAUDE.md exists, needs optimization | AI reads entire CLAUDE.md, optimizes for token efficiency, removes redundancy, improves structure. No script โ pure AI. |
Prerequisites
docs/project-config.json โ primary data source (run /project-config first if missing)
- Node.js available (for generator script)
Phase 1: Detect Mode
node .claude/skills/claude-md-init/scripts/generate-claude-md.cjs --detect
Decision logic:
- No CLAUDE.md โ
init
- CLAUDE.md with markers โ
update
- CLAUDE.md without markers โ
smart-merge (see below)
- User explicit
--mode flag โ override detection
Phase 2: Run Generator Script
node .claude/skills/claude-md-init/scripts/generate-claude-md.cjs --mode init
node .claude/skills/claude-md-init/scripts/generate-claude-md.cjs --mode update
Script behavior:
- Reads
docs/project-config.json
- Reads template (
references/claude-md-template.md) for init, or existing CLAUDE.md for update
- Calls section builders to generate content for each marker key
- Writes output to
CLAUDE.md (creates backup .claude-md.backup first)
- Outputs report: which sections were generated, which skipped (no data), which preserved
Smart-Merge (Update on CLAUDE.md Without Markers)
When running update on an existing CLAUDE.md that has NO section markers:
- Read existing CLAUDE.md
- Match sections by
## heading text against known section keys (see references/section-registry.md)
- For each matched section: wrap with markers, replace content with generated content
- For unmatched user sections: preserve as-is (no markers added)
- Write output with backup
Phase 3: AI Fill (Post-Script)
After the script generates the mechanical parts, AI reviews and fills:
- Project description in TL;DR โ write a concise 2-3 sentence description based on config + codebase
- Golden rules โ infer from
contextGroups[].rules in config, but rewrite as human-readable rules
- Decision quick-ref โ build from
modules[] + framework config, add project-specific patterns
- Naming conventions โ detect from codebase patterns if not in config
Phase 4: Verify
Phase 5: Sync Mirrors (after CLAUDE.md is written)
Writing/updating CLAUDE.md leaves the generated mirror surfaces stale โ AGENTS.md (Codex), the
.codex/ mirrors, and other downstream surfaces are derived FROM CLAUDE.md and
do not update on their own.
MUST add a final todo task โ "Sync Codex mirrors from updated CLAUDE.md" โ and run it after
init/update/refactor completes, by invoking the /sync-codex skill (the full cross-surface
migrate โ hooks โ context โ verify pipeline, which regenerates AGENTS.md). Create this as
the LAST TaskCreate item so it always follows the verify step:
TaskCreate: "Sync Codex mirrors from updated CLAUDE.md โ invoke /sync-codex"
Skip only when no CLAUDE.md content actually changed (e.g. generator reported all sections preserved /
no diff). Otherwise the AGENTS.md mirror drifts from CLAUDE.md and Codex runs against stale
guidance.
Refactor Mode (AI-Only)
When --mode refactor or user asks to optimize CLAUDE.md:
- Read entire CLAUDE.md
- Identify: redundant sections, verbose explanations, duplicate info available in referenced docs
- Apply token efficiency: remove duplication, consolidate tables, shorten where possible
- Preserve all section markers
- Report: lines before/after, sections changed, estimated token savings
Section Marker Protocol
<!-- SECTION:tldr -->
Auto-generated content here...
<!-- /SECTION:tldr -->
Rules:
- Only content between markers is replaced on update
- Content outside markers is never touched
- Missing markers in update mode โ section skipped (not inserted)
- Init mode uses template which includes all markers
- Markers use lowercase kebab-case keys matching section-registry.md
Section Keys (Quick Reference)
See references/section-registry.md for full mapping. Summary:
| Key | Source | Conditional? |
|---|
tldr | project.*, modules[], framework.* | No โ always generated |
golden-rules | contextGroups[].rules | Yes โ skip if no rules |
decision-quick-ref | modules[], framework.* | Yes โ skip if no modules |
key-locations | modules[].pathRegex | Yes โ skip if no modules |
dev-commands | testing.commands, infrastructure.* | Yes โ skip if no commands |
infra-ports | modules[].meta.port (infra) | Yes โ skip if no ports |
api-ports | modules[].meta.port (services) | Yes โ skip if no ports |
integration-testing | framework.integrationTestDoc | Yes โ skip if no doc |
e2e-testing | framework.e2eTestDoc or scan | Yes โ skip if no tests |
doc-index | Scan docs/ directory | Yes โ skip if no docs/ |
doc-lookup | modules[] + business features | Yes โ skip if no modules |
Running Tests
Generator + bootstrap-gate coverage lives in the hooks test suite:
node .claude/hooks/tests/run-all-tests.cjs --filter=agent-files
[IMPORTANT] Use TaskCreate to break ALL work into small tasks BEFORE starting โ including tasks for each file read. This prevents context loss from long files. For simple tasks, AI MUST ATTENTION ask user whether to skip.
Critical Thinking Mindset โ Apply critical thinking, sequential thinking. Every claim needs traced proof, confidence >80% to act.
Anti-hallucination: Never present guess as fact โ cite sources for every claim, admit uncertainty freely, self-check output for errors, cross-reference independently, stay skeptical of own confidence โ certainty without evidence root of all hallucination.
Output Quality โ Token efficiency without sacrificing quality.
- No inventories/counts โ AI can
grep | wc -l. Counts go stale instantly
- No directory trees โ AI can
glob/ls. Use 1-line path conventions
- No TOCs โ AI reads linearly. TOC wastes tokens
- No examples that repeat what rules say โ one example only if non-obvious
- Lead with answer, not reasoning. Skip filler words and preamble
- Sacrifice grammar for concision in reports
- Unresolved questions at end, if any
AI Mistake Prevention โ Failure modes to avoid on every task:
Re-read files after context changes. Context compaction, resume, or long-running work can make memory stale; verify current files before acting.
Verify generated content against source evidence. AI hallucinates APIs, names, claims, and document facts. Check the relevant source before documenting or referencing.
Check downstream references before deleting or renaming. Removing an artifact can stale docs, generated mirrors, configs, and callers; map references first.
Trace the full impact chain after edits. Changing a definition can miss derived outputs and consumers. Follow the affected chain before declaring done.
Verify ALL affected outputs, not just the first. One green check is not all green checks; validate every output surface the change can affect.
Assume existing values are intentional โ ask WHY before changing. Before changing a constant, limit, flag, wording, or pattern, read nearby context and history.
Surface ambiguity before acting โ don't pick silently. Multiple valid interpretations require an explicit question or stated assumption with risk.
Keep shared guidance role-relevant. Universal guidance must help every receiving skill or agent; code-specific obligations belong only in code-specific protocols.
IMPORTANT MUST ATTENTION maintain >=8 rules per 100 lines. Critical rules in first+last 5 lines. Tables over prose.
MUST ATTENTION apply critical + sequential thinking โ every claim needs appropriate traced evidence (file:line for repo/code claims; source URL or artifact section for research, product, content, and docs claims); confidence >80% to act, <60% DO NOT recommend. Anti-hallucination: never present guess as fact, admit uncertainty freely, cross-reference independently, stay skeptical of own confidence.
MUST ATTENTION apply AI mistake prevention โ verify generated content against evidence, trace downstream references before deleting or renaming, verify all affected outputs, re-read files after context loss, and surface ambiguity before acting.
Closing Reminders
Protocols in force (concise digest of the SYNC/shared blocks this skill carries): MUST ATTENTION honor every protocol below.
- Critical Thinking: apply critical + sequential thinking; traced proof, confidence >80% to act.
- Output Quality: token-efficient โ no inventories/trees/TOCs; tables over prose.
- AI Mistake Prevention: verify generated content against evidence, trace downstream references, verify all affected outputs, re-read after context loss, surface ambiguity.
IMPORTANT MUST ATTENTION break work into small todo tasks using TaskCreate BEFORE starting
IMPORTANT MUST ATTENTION search codebase for 3+ similar patterns before creating new code
IMPORTANT MUST ATTENTION cite file:line evidence for every claim (confidence >80% to act)
IMPORTANT MUST ATTENTION add a final review todo task to verify work quality
[TASK-PLANNING] Before acting, analyze task scope and systematically break it into small todo tasks and sub-tasks using TaskCreate.