Analyze the current project and write an effective CLAUDE.md — either creating one from scratch or refining an existing one — following official Claude Code guidelines and the principle that shorter is better.
Steps
Check for existing CLAUDE.md at the project root. If one exists, read it first.
Inspect project files to detect build system, test runner, lint/format setup, and conventions:
package.json, pyproject.toml, Cargo.toml, Makefile, *.sln, go.mod
.eslintrc*, .prettierrc*, biome.json, ruff.toml
README.md, docs/ directory, .github/ for PR/branch conventions
git log --oneline -10 to detect commit message conventions
git remote -v to identify the repository
Apply the placement decision for each rule you find:
- Project-wide rules →
CLAUDE.md
- Domain-specific or file-type-specific rules (e.g., "React component rules", "SQL migration rules") →
.claude/rules/<domain>.md with paths: frontmatter
- Automated/enforcement behaviors (auto-format on save, lint fixing) → do NOT put in CLAUDE.md; note them as candidates for
settings.json PostToolUse hooks
Apply the include/exclude filter before writing each line:
✅ Include:
- Bash commands Claude cannot guess (build, test, deploy, migrate, seed)
- Code style rules that differ from language/framework defaults
- Testing instructions and preferred test runners
- Branch naming, PR conventions, commit message format
- Required env vars or non-obvious setup steps
- Common gotchas or non-obvious behaviors
- Critical invariants (wrap in
<important> tags)
❌ Exclude:
- Anything Claude can infer by reading the code
- Standard language conventions Claude already knows
- Detailed API documentation (link to docs instead)
- File-by-file descriptions of the codebase
- Self-evident practices like "write clean code"
- Automated behaviors (formatting, linting) — suggest
settings.json hooks instead
Write CLAUDE.md to the project root using this structure (omit empty sections):
# <Project Name>
<1-2 sentence description of what the project is>
# Commands
- install: <cmd>
- dev: <cmd>
- test: <cmd>
- lint: <cmd>
- build: <cmd>
# Code Style
<only rules that differ from defaults>
# Workflow
<branch naming, PR conventions, non-obvious steps>
<important>
<critical rules that must not be forgotten>
</important>
Keep the total file under 50 lines where possible. Never exceed 200 lines.
Create .claude/rules/<domain>.md stubs for any domain-specific rules identified. Each stub must include paths: frontmatter:
---
paths:
- "src/components/**"
---
# <Domain> Rules
# TODO: add rules here
Report what was written, what was excluded and why, any .claude/rules/ stubs created, and any behaviors suggested for settings.json.
Output Format
After completing the task, output:
## CLAUDE.md written
Path: <path>
Lines: <count>
### Included
- <item>: <why included>
### Excluded
- <item>: <why excluded>
### Routed to .claude/rules/
- <file>: applies to <glob pattern>
### Suggested for settings.json
- <behavior>: use PostToolUse hook to automate
1---2name: create-claude-md3description: Generate or refine a concise, effective CLAUDE.md for the current project following official best-practice guidelines. Use when the user wants to create, write, or update a project's CLAUDE.md.4---56Analyze the current project and write an effective `CLAUDE.md` — either creating one from scratch or refining an existing one — following official Claude Code guidelines and the principle that shorter is better.78## Steps9101. **Check for existing CLAUDE.md** at the project root. If one exists, read it first.11122. **Inspect project files** to detect build system, test runner, lint/format setup, and conventions:13 - `package.json`, `pyproject.toml`, `Cargo.toml`, `Makefile`, `*.sln`, `go.mod`14 - `.eslintrc*`, `.prettierrc*`, `biome.json`, `ruff.toml`15 - `README.md`, `docs/` directory, `.github/` for PR/branch conventions16 - `git log --oneline -10` to detect commit message conventions17 - `git remote -v` to identify the repository18193. **Apply the placement decision** for each rule you find:20 - Project-wide rules → `CLAUDE.md`21 - Domain-specific or file-type-specific rules (e.g., "React component rules", "SQL migration rules") → `.claude/rules/<domain>.md` with `paths:` frontmatter22 - Automated/enforcement behaviors (auto-format on save, lint fixing) → do NOT put in CLAUDE.md; note them as candidates for `settings.json` PostToolUse hooks23244. **Apply the include/exclude filter** before writing each line:2526 ✅ Include:27 - Bash commands Claude cannot guess (build, test, deploy, migrate, seed)28 - Code style rules that differ from language/framework defaults29 - Testing instructions and preferred test runners30 - Branch naming, PR conventions, commit message format31 - Required env vars or non-obvious setup steps32 - Common gotchas or non-obvious behaviors33 - Critical invariants (wrap in `<important>` tags)3435 ❌ Exclude:36 - Anything Claude can infer by reading the code37 - Standard language conventions Claude already knows38 - Detailed API documentation (link to docs instead)39 - File-by-file descriptions of the codebase40 - Self-evident practices like "write clean code"41 - Automated behaviors (formatting, linting) — suggest `settings.json` hooks instead42435. **Write `CLAUDE.md`** to the project root using this structure (omit empty sections):4445 ```46 # <Project Name>47 <1-2 sentence description of what the project is>4849 # Commands50 - install: <cmd>51 - dev: <cmd>52 - test: <cmd>53 - lint: <cmd>54 - build: <cmd>5556 # Code Style57 <only rules that differ from defaults>5859 # Workflow60 <branch naming, PR conventions, non-obvious steps>6162 <important>63 <critical rules that must not be forgotten>64 </important>65 ```6667 Keep the total file under 50 lines where possible. Never exceed 200 lines.68696. **Create `.claude/rules/<domain>.md` stubs** for any domain-specific rules identified. Each stub must include `paths:` frontmatter:7071 ```markdown72 ---73 paths:74 - "src/components/**"75 ---76 # <Domain> Rules7778 # TODO: add rules here79 ```80817. **Report** what was written, what was excluded and why, any `.claude/rules/` stubs created, and any behaviors suggested for `settings.json`.8283## Output Format8485After completing the task, output:8687```88## CLAUDE.md written89Path: <path>90Lines: <count>9192### Included93- <item>: <why included>9495### Excluded96- <item>: <why excluded>9798### Routed to .claude/rules/99- <file>: applies to <glob pattern>100101### Suggested for settings.json102- <behavior>: use PostToolUse hook to automate103```