with one click
claude-md-init
// [Documentation] Use when you need initialize, update, or refactor CLAUDE markdown from project-config JSON and codebase scan results.
// [Documentation] Use when you need initialize, update, or refactor CLAUDE markdown from project-config JSON and codebase scan results.
[HINT] Download the complete skill directory including SKILL.md and all related files
| 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. |
Goal: Automate CLAUDE.md lifecycle — generate from project-config.json + template, incrementally update marked sections, or refactor for token efficiency.
Workflow:
--mode init), update (--mode update), refactor (--mode refactor)node .claude/skills/claude-md-init/scripts/generate-claude-md.cjs --mode <mode>Key Rules:
docs/project-config.json<!-- SECTION:key -->) enable incremental updates without overwriting user content| 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. |
docs/project-config.json — primary data source (run /project-config first if missing)# Check CLAUDE.md state
node .claude/skills/claude-md-init/scripts/generate-claude-md.cjs --detect
Decision logic:
initupdatesmart-merge (see below)--mode flag → override detection# Init mode: generate fresh CLAUDE.md
node .claude/skills/claude-md-init/scripts/generate-claude-md.cjs --mode init
# Update mode: sync marked sections only
node .claude/skills/claude-md-init/scripts/generate-claude-md.cjs --mode update
Script behavior:
docs/project-config.jsonreferences/claude-md-template.md) for init, or existing CLAUDE.md for updateCLAUDE.md (creates backup .claude-md.backup first)When running update on an existing CLAUDE.md that has NO section markers:
## heading text against known section keys (see references/section-registry.md)After the script generates the mechanical parts, AI reviews and fills:
contextGroups[].rules in config, but rewrite as human-readable rulesmodules[] + framework config, add project-specific patterns{project-name}, TODO).claude/skills/claude-md-init/ references leak into output (self-reference)When --mode refactor or user asks to optimize CLAUDE.md:
<!-- SECTION:tldr -->
Auto-generated content here...
<!-- /SECTION:tldr -->
Rules:
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 |
node .claude/skills/claude-md-init/scripts/test-generate-claude-md.cjs
[IMPORTANT] Use
TaskCreateto 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:
Check downstream references before deleting. Deleting components causes documentation and code staleness cascades. Map all referencing files before removal. Verify AI-generated content against actual code. AI hallucinates APIs, class names, and method signatures. Always grep to confirm existence before documenting or referencing. Trace full dependency chain after edits. Changing a definition misses downstream variables and consumers derived from it. Always trace the full chain. Trace ALL code paths when verifying correctness. Confirming code exists is not confirming it executes. Always trace early exits, error branches, and conditional skips — not just happy path. When debugging, ask "whose responsibility?" before fixing. Trace whether bug is in caller (wrong data) or callee (wrong handling). Fix at responsible layer — never patch symptom site. Assume existing values are intentional — ask WHY before changing. Before changing any constant, limit, flag, or pattern: read comments, check git blame, examine surrounding code. Verify ALL affected outputs, not just the first. Changes touching multiple stacks require verifying EVERY output. One green check is not all green checks. Holistic-first debugging — resist nearest-attention trap. When investigating any failure, list EVERY precondition first (config, env vars, DB names, endpoints, DI registrations, data preconditions), then verify each against evidence before forming any code-layer hypothesis. Surgical changes — apply the diff test. Bug fix: every changed line must trace directly to the bug. Don't restyle or improve adjacent code. Enhancement task: implement improvements AND announce them explicitly. Surface ambiguity before coding — don't pick silently. If request has multiple interpretations, present each with effort estimate and ask. Never assume all-records, file-based, or more complex path.
IMPORTANT MUST ATTENTION maintain >=8 rules per 100 lines. Critical rules in first+last 5 lines. Tables over prose.
MUST ATTENTION apply critical thinking — every claim needs traced proof, confidence >80% to act. Anti-hallucination: never present guess as fact.
MUST ATTENTION apply AI mistake prevention — holistic-first debugging, fix at responsible layer, surface ambiguity before coding, re-read files after compaction.
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.