claude-md-init

Installation
SKILL.md

[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 ask user whether to skip.

Quick Summary

Goal: Automate CLAUDE.md lifecycle — generate from project-config.json + template, incrementally update marked sections, or refactor for token efficiency.

Workflow:

  1. Detect Mode — init (no CLAUDE.md or --mode init), update (--mode update), refactor (--mode refactor)
  2. Run Generatornode .claude/skills/claude-md-init/scripts/generate-claude-md.cjs --mode <mode>
  3. AI Fill — Review output, fill creative sections (project description, golden rules inference)
  4. 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 (<!-- 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

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)
  • User explicit --mode flag → override detection

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:

  1. Reads docs/project-config.json
  2. Reads template (references/claude-md-template.md) for init, or existing CLAUDE.md for update
  3. Calls section builders to generate content for each marker key
  4. Writes output to CLAUDE.md (creates backup .claude-md.backup first)
  5. 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:

  1. Read existing CLAUDE.md
  2. Match sections by ## heading text against known section keys (see references/section-registry.md)
  3. For each matched section: wrap with markers, replace content with generated content
  4. For unmatched user sections: preserve as-is (no markers added)
  5. Write output with backup

Phase 3: AI Fill (Post-Script)

After the script generates the mechanical parts, AI reviews and fills:

  1. Project description in TL;DR — write a concise 2-3 sentence description based on config + codebase
  2. Golden rules — infer from contextGroups[].rules in config, but rewrite as human-readable rules
  3. Decision quick-ref — build from modules[] + framework config, add project-specific patterns
  4. 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)

Refactor Mode (AI-Only)

When --mode refactor or user asks to optimize CLAUDE.md:

  1. Read entire CLAUDE.md
  2. Identify: redundant sections, verbose explanations, duplicate info available in referenced docs
  3. Apply token efficiency: remove duplication, consolidate tables, shorten where possible
  4. Preserve all section markers
  5. 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

node .claude/skills/claude-md-init/scripts/test-generate-claude-md.cjs
Weekly Installs
2
GitHub Stars
6
First Seen
12 days ago
Installed on
amp2
cline2
opencode2
cursor2
kimi-cli2
warp2