MITupdated 21d ago
Build a project-specific CLAUDE.md that earns every line: exact commands, an architecture map, real gotchas, and enforced boundaries β and nothing Claude already knows. The goal is the inverse of naive /init output: short, specific, and free of README duplication, directory trees, and generic filler.
What can you do with Generate Claude Md?
name: generate-claude-md description: Generate a lean, high-signal CLAUDE.md for a repository from codebase analysis. Grounded in Anthropic best practices and empirical studies; built to pass review-claude-md (a bundled validator enforces the same critical checks). Use when the user asks to "generate CLAUDE.md", "create a CLAUDE.md", "write a CLAUDE.md", "init CLAUDE.md", "scaffold CLAUDE.md", or "bootstrap CLAUDE.md" for a project. argument-hint: "[path/to/repo] [--output PATH] [--update] [--force] [--rules] [--dry-run]" allowed-tools: Bash, Edit, Glob, Grep, Read, Task, Write user-invocable: true context: fork agent: general-purpose
Generate CLAUDE.md
Build a project-specific CLAUDE.md that earns every line: exact commands, an
architecture map, real gotchas, and enforced boundaries β and nothing Claude
already knows. The goal is the inverse of naive /init output: short, specific,
and free of README duplication, directory trees, and generic filler.
This skill is the generator counterpart to the review-claude-md plugin. It
targets the same rubric the reviewer audits against. The bundled validator
(Phase 7) deterministically gates the mechanical checks β commands present,
length, no README duplication, no generic advice, no directory tree, bullets β
which are all of the reviewer's Critical checks, so a passing file cannot earn a
review FAIL verdict. The remaining quality (architecture as relationships, domain
mapping, real gotchas, style deltas) is your job during synthesis. Read
references/principles.md in full before synthesizing β
it is the source of truth for every rule below.
Arguments
Parse from $ARGUMENTS:
- First positional arg: repo root (default: current working directory)
--output PATHβ write to PATH instead of<repo>/CLAUDE.md--updateβ merge into an existing CLAUDE.md, preserving sections this skill does not manage; regenerate the rest--forceβ overwrite an existing CLAUDE.md (explicit, destructive opt-in)--rulesβ split topic detail into.claude/rules/*.mdeven under the budget--dry-runβ return the generated content without writing any file
Write safety (read first)
Never silently overwrite. Decide the write target like this:
- Resolve target:
--output PATH, else<repo>/CLAUDE.md. - Target does not exist β write it directly.
- Target exists and
--forceβ overwrite it (the flag is the explicit approval). - Target exists and
--updateβ merge (see Phase 6), then write the target. - Target exists, no flag β do not touch it. Write to
<dir>/CLAUDE.generated.mdand report that the user should diff it against the current file, then re-run with--updateor--force. --dry-runβ write nothing; return the content in the report.
Workflow
Phase 1: Setup
- Resolve repo root and the write target per Write safety above.
- Detect existing context:
CLAUDE.md,.claude/CLAUDE.md,.claude/rules/*,AGENTS.md,.cursorrules. Note whetherAGENTS.mdexists (drives bridging). - Confirm
README.mdpresence (used to avoid duplication).
Phase 2: Scan the codebase
Spawn one Explore agent. Pass it the repo root and the full contents of
references/scan-spec.md as its instructions. It reads
manifests, task runners, CI, lint/test config, entry points, and git history, and
returns the compact structured summary that file specifies. Do not re-read what
the agent already summarized.
Phase 3: Verify commands
For each build/test/lint/run command in the summary, confirm it is real with a
non-destructive probe (--help, --version, make -n <target>, a script entry
in a manifest, or its presence in CI). Drop or mark (unverified) anything that
cannot be confirmed. Prefer the form CI uses over the README form.
Phase 4: Synthesize
Read references/principles.md and references/section-guide.md before writing. Then build the file:
- Work section by section in the priority order from the section guide. Include a section only if it has real, project-specific content.
- Apply the deletion test to every line: "Would removing this cause Claude to make a mistake?" If no, cut it.
- Use
file:linepointers, never pasted code. Phrase rules positively ("use Y"). Bullets, not paragraphs. Reserve emphasis for at most a couple of lines. - Do not duplicate README headings (from the summary). No directory tree. No standard language conventions. No generic advice.
- If
AGENTS.mdexists, bridge instead of duplicating: make the first line@AGENTS.mdand add only Claude-specific content. See references/modularization.md.
See references/example.md for a full worked file and a counter-example.
Phase 5: Budget & modularization
- Count lines. Keep the root under 150 lines β this is the limit
review-claude-mdenforces (its C2 check), so staying under it is what makes the output pass that audit. The official ceiling is 200, but 150 is the binding target here. Aim well below it. - If over budget, or if
--ruleswas passed, move topic detail into.claude/rules/*.mdper references/modularization.md, usingpaths:frontmatter to scope rules to globs. Keep commands, the architecture map, top gotchas, and etiquette in the root, and link each rule file from the root with a one-line description.
Phase 6: Write
- Default /
--force: write the synthesized content to the target. --update: read the existing file, keep any heading this skill does not manage (preserve user-authored sections verbatim), replace the managed sections with the freshly synthesized ones, and write the merged result. Never drop a section you did not generate.- Create any
.claude/rules/*.mdfiles from Phase 5. --dry-run: skip all writes.
Phase 7: Validate & iterate
Run the validator on the written file (or, for --dry-run, on a temp copy):
python3 "${CLAUDE_SKILL_DIR}/scripts/validate-claude-md.py" "<target-file>" --human
Parse the result. For any [FAIL] check, fix the file and re-run. Iterate up to
3 rounds. The validator enforces line count, README de-duplication, no generic
advice, no directory tree, no oversized code blocks, bullet ratio, and the presence
of build/test/lint commands plus a pre-commit gate β mirroring the same checks
review-claude-md runs (its command checks skip automatically for AGENTS.md bridge
files). A genuinely-absent command (e.g. a project with no linter) should be
reported honestly, not invented.
Phase 8: Report
Return a summary:
- Target path written (or the
.generated.mdfallback / dry-run notice) - Final line count and the validator verdict (PASS, or remaining advisories)
- Sections included and any
.claude/rules/*.mdcreated - If a
.generated.mdfallback was used: the exact next step (diff, then--updateor--force) - One or two follow-ups the human should confirm (e.g. an unverified command, a
gotcha that needs a real
file:line)
Error handling
- No manifests / unknown stack: infer commands from CI and scripts; if still unknown, omit the Commands section rather than guessing, and flag it in the report.
- Empty or trivial repo: generate only the sections with real content (often just Commands). Do not pad to look complete.
- Existing CLAUDE.md and no flag: never overwrite β use the
.generated.mdfallback and tell the user how to proceed. - Validator keeps failing after 3 rounds: write the best version, report the
remaining failing checks honestly, and suggest
/review-claude-md --fix.
Example invocations
/generate-claude-md
/generate-claude-md /path/to/repo --dry-run
/generate-claude-md --update
/generate-claude-md --force --rules
Install
Add Generate Claude Md to your client. Pick the one you use.
npx skills add smykla-skalski/saiInstalls every skill in the repository, then prompts for which to keep.
/plugin marketplace add smykla-skalski/saiAdds the repository as a plugin marketplace; install individual plugins with `/plugin install`.
git clone https://github.com/smykla-skalski/sai
cp -r claude/generate-claude-md/skills/generate-claude-md ~/.claude/skills/A skill is a plain directory. Copy it into `.claude/skills/` in a project or in your home directory.
Score
87 / 100
Excellent