EasyPlatform claude-md-init
[Documentation] Initialize, update, or refactor CLAUDE.md from project-config.json and codebase scan results. Triggers on: claude.md init, claude.md update, claude.md sync, claude.md refactor, init claude, setup claude, generate claude.md, refresh claude.md.
git clone https://github.com/duc01226/EasyPlatform
T=$(mktemp -d) && git clone --depth=1 https://github.com/duc01226/EasyPlatform "$T" && mkdir -p ~/.claude/skills && cp -r "$T/.claude/skills/claude-md-init" ~/.claude/skills/duc01226-easyplatform-claude-md-init && rm -rf "$T"
.claude/skills/claude-md-init/SKILL.md<!-- SYNC:critical-thinking-mindset -->[IMPORTANT] Use
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.TaskCreate
<!-- /SYNC:critical-thinking-mindset --> <!-- SYNC:ai-mistake-prevention -->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.
<!-- /SYNC:ai-mistake-prevention --> <!-- SYNC:output-quality-principles -->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.
<!-- /SYNC:output-quality-principles -->Output Quality — Token efficiency without sacrificing quality.
- No inventories/counts — AI can
. Counts go stale instantlygrep | wc -l- No directory trees — AI can
/glob. Use 1-line path conventionsls- 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
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
), update (--mode init
), refactor (--mode update
)--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
Key Rules:
- Generic — works in any project by reading
docs/project-config.json - Section markers (
) enable incremental updates without overwriting user content<!-- SECTION:key --> - Conditional sections — generated ONLY when config has matching data; empty config = section omitted
- Static framework sections (8 total) are portable across all projects
Modes
| Mode | When | Behavior |
|---|---|---|
| No CLAUDE.md exists, or first-time setup | Generate fresh CLAUDE.md from template + config. Populates all markers. |
| CLAUDE.md exists with markers | Replace only content between markers. Preserve everything else. |
| CLAUDE.md exists, needs optimization | AI reads entire CLAUDE.md, optimizes for token efficiency, removes redundancy, improves structure. No script — pure AI. |
Prerequisites
— primary data source (rundocs/project-config.json
first if missing)/project-config- 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 →
(see below)smart-merge - User explicit
flag → override detection--mode
Phase 2: Run Generator Script
# 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:
- Reads
docs/project-config.json - Reads template (
) for init, or existing CLAUDE.md for updatereferences/claude-md-template.md - Calls section builders to generate content for each marker key
- Writes output to
(creates backupCLAUDE.md
first).claude-md.backup - 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
in config, but rewrite as human-readable rulescontextGroups[].rules - Decision quick-ref — build from
+modules[]
config, add project-specific patternsframework - 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
references leak into output (self-reference).claude/skills/claude-md-init/ - Conditional sections with no data are omitted (not empty stubs)
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? |
|---|---|---|
| , , | No — always generated |
| | Yes — skip if no rules |
| , | Yes — skip if no modules |
| | Yes — skip if no modules |
| , | Yes — skip if no commands |
| (infra) | Yes — skip if no ports |
| (services) | Yes — skip if no ports |
| | Yes — skip if no doc |
| or scan | Yes — skip if no tests |
| Scan directory | Yes — skip if no docs/ |
| + business features | Yes — skip if no modules |
Running Tests
node .claude/skills/claude-md-init/scripts/test-generate-claude-md.cjs
Closing Reminders
- IMPORTANT MUST ATTENTION break work into small todo tasks using
BEFORE startingTaskCreate - IMPORTANT MUST ATTENTION search codebase for 3+ similar patterns before creating new code
- IMPORTANT MUST ATTENTION cite
evidence for every claim (confidence >80% to act)file:line - IMPORTANT MUST ATTENTION add a final review todo task to verify work quality <!-- SYNC:output-quality-principles:reminder -->
- IMPORTANT MUST ATTENTION maintain >=8 rules per 100 lines. Critical rules in first+last 5 lines. Tables over prose. <!-- /SYNC:output-quality-principles:reminder --> <!-- SYNC:critical-thinking-mindset:reminder -->
- MUST ATTENTION apply critical thinking — every claim needs traced proof, confidence >80% to act. Anti-hallucination: never present guess as fact. <!-- /SYNC:critical-thinking-mindset:reminder --> <!-- SYNC:ai-mistake-prevention:reminder -->
- MUST ATTENTION apply AI mistake prevention — holistic-first debugging, fix at responsible layer, surface ambiguity before coding, re-read files after compaction. <!-- /SYNC:ai-mistake-prevention:reminder -->