[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
# Check CLAUDE.md state
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)
Naming conventions — detect from codebase patterns if not in config
Phase 4: Verify
CLAUDE.md is valid markdown
All section markers are properly paired (open + close)
No template placeholder text remains (e.g., {project-name}, TODO)
No .claude/skills/claude-md-init/ references leak into output (self-reference)
Conditional sections with no data are omitted (not empty stubs)
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
[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.
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.