Craft CLAUDE.md
Generate or update highly effective CLAUDE.md files that make Claude Code maximally useful.
Core Principle
CLAUDE.md is onboarding for a stateless agent, not documentation. Every line must answer: "Would a senior engineer who can read the code still need to be told this?" If no, cut it.
Workflow
Step 1: Determine Mode
- Target file already exists? → UPDATE mode
- No file at target? → CREATE mode
- Ambiguous target? → Ask the user. Default to
./CLAUDE.md (project root)
Step 2: Determine Location
Read references/location-guide.md to understand what belongs at each level:
~/.claude/CLAUDE.md: personal defaults (<30 lines)
./CLAUDE.md: project root (<60 lines)
- Parent directory: monorepo shared conventions (<40 lines)
- Child directory: module-specific overrides (<30 lines)
The location determines scope, line budget, and content focus.
CREATE Mode
2a. Auto-Detect Project Context
Scan the project for signals. Read files as needed, don't guess:
| Signal |
What to look for |
| Package manager |
package.json, pyproject.toml, Cargo.toml, go.mod, Gemfile, pom.xml |
| Build system |
Makefile, Justfile, build.gradle, CMakeLists.txt, Taskfile.yml |
| Config files |
tsconfig.json, .eslintrc*, .prettierrc*, ruff.toml, clippy.toml |
| Test framework |
jest.config.*, pytest.ini, setup.cfg [tool:pytest], .mocharc.* |
| CI/CD |
.github/workflows/, .gitlab-ci.yml, Jenkinsfile |
| Monorepo |
packages/, apps/, workspace config in package.json, pnpm-workspace.yaml |
| Existing docs |
README.md, CONTRIBUTING.md, docs/ |
| Git conventions |
Recent commit messages (git log --oneline -20), branch naming patterns |
| Existing .claude/ |
.claude/ directory, existing CLAUDE.md files at other levels |
Read README.md if it exists. It often contains build/test commands and architecture notes.
2b. Interview the User
Ask 2-4 targeted questions about things you could not auto-detect:
- "Are there architectural decisions or trade-offs I should know about?"
- "Any gotchas or things that trip up new contributors?"
- "Any non-obvious commands or workflows?" (only if Makefile/scripts don't make them clear)
- For home CLAUDE.md: "What coding preferences do you want applied to all projects?"
Do NOT ask about things you already detected. Keep questions specific and actionable.
2c. Generate the CLAUDE.md
- Select the appropriate template from
references/templates.md based on detected project type
- Fill in auto-detected commands and conventions
- Incorporate user answers from the interview
- Apply constraints from
references/best-practices.md:
- Stay under the line budget for the target location
- Only include what Claude can't figure out from code
- Every line must be universally applicable (no task-specific instructions)
- Use IMPORTANT/MUST sparingly (max 2-3 per file)
- Don't describe tools Claude already knows
- Don't duplicate README content
- For code style/pattern rules, point to canonical files instead of prose descriptions
- If content exceeds the line budget, use
@path imports for progressive disclosure
- Present the draft to the user for review
- Write the file only after user approval
UPDATE Mode
2a. Diagnose the Existing File
Read the existing CLAUDE.md and evaluate against references/best-practices.md:
Check for these problems:
- Too long: exceeds line budget for its location
- Redundant: duplicates README, states obvious conventions, describes tools Claude knows
- Missing critical sections: no build/test commands, no architecture context
- Task-specific instructions: contains instructions for specific features or tickets
- Linter-as-CLAUDE.md: style rules that should be in a formatter/linter config
- Over-emphasized: too many IMPORTANT/MUST/ALWAYS/NEVER markers
- Stale: references files, tools, or conventions that no longer exist
- File-by-file descriptions: describes what each file does (Claude can read them)
- Generic/template content: instructions copied from a template that don't match the actual project
- History not guidance: instructions phrased as past events ("we migrated to X") instead of forward-looking rules ("use X for all new work")
2b. Auto-Detect Context Changes
Scan the project (same signals as CREATE mode) to find:
- New tools or frameworks added since the CLAUDE.md was written
- Commands that have changed
- Conventions that are now enforced by tooling (and can be removed from CLAUDE.md)
2c. Propose Changes
Present surgical changes with rationale for each:
- What to remove and why (e.g., "Remove ESLint style rules, these are enforced by your .eslintrc")
- What to add and why (e.g., "Add
make integration-test, detected in Makefile but not documented")
- What to restructure and why (e.g., "Move auth-module instructions to
src/auth/CLAUDE.md")
- Whether to introduce
@path imports for progressive disclosure
2d. Apply After Approval
Only modify the file after the user reviews and approves the changes.
Key Principles (Always Apply)
- CLAUDE.md is onboarding for a stateless agent, not documentation. Claude reads it fresh every session.
- Only include what Claude cannot figure out from code. If it's in package.json, tsconfig.json, or the code itself, don't repeat it.
- Every line must be universally applicable. No task-specific, ticket-specific, or sprint-specific content.
- Concise > comprehensive. A 30-line CLAUDE.md that's followed beats a 200-line one that's ignored.
- Use hooks and formatters instead of linting instructions. Claude respects tool output; don't manually enforce style.
- Use @path imports for progressive disclosure. Keep root lean, add depth through references.
- Maintain with the litmus test: "Would this mislead an agent?" When code changes, ask if an outdated CLAUDE.md instruction would cause Claude to make a mistake. Update when contracts/boundaries change; skip when only implementation details change.
Reference Files
Read these as needed during the workflow:
references/best-practices.md: do's, don'ts, anti-patterns, and the instruction budget framework
references/location-guide.md: what content belongs at each CLAUDE.md location and how levels interact
references/templates.md: starter templates by project type (Python, Node/TS, Go, Rust, generic, home)
Output Format
The generated CLAUDE.md should:
- Use
# headers to organize sections (Build & Test, Architecture, Conventions, Gotchas)
- Use code blocks for commands
- Use bullet points for rules and conventions
- Include blank lines between sections for readability
- NOT include meta-commentary ("This file was generated by...")
- NOT include the line budget or other meta-instructions in the output
1---2name: craft-claudemd3description: Create or update CLAUDE.md files following research-backed best practices. Use when asked to: create a new CLAUDE.md, improve/update an existing CLAUDE.md, set up Claude Code for a project, write project instructions for Claude, or generate a CLAUDE.md at any location (home, project root, parent, child directory). Triggers on: "make a CLAUDE.md", "improve my CLAUDE.md", "set up Claude Code for this project", "create project instructions", "optimize my CLAUDE.md", "CLAUDE.md is too long", "what should go in CLAUDE.md", "help me write a CLAUDE.md", "craft a CLAUDE.md", "initialize Claude Code for this repo", "configure Claude for my project". Also trigger when users mention CLAUDE.md quality, bloat, or effectiveness issues.4---56# Craft CLAUDE.md78Generate or update highly effective CLAUDE.md files that make Claude Code maximally useful.910## Core Principle1112CLAUDE.md is **onboarding for a stateless agent**, not documentation. Every line must answer: "Would a senior engineer who can read the code still need to be told this?" If no, cut it.1314## Workflow1516### Step 1: Determine Mode1718- **Target file already exists?** → UPDATE mode19- **No file at target?** → CREATE mode20- **Ambiguous target?** → Ask the user. Default to `./CLAUDE.md` (project root)2122### Step 2: Determine Location2324Read `references/location-guide.md` to understand what belongs at each level:25- `~/.claude/CLAUDE.md`: personal defaults (<30 lines)26- `./CLAUDE.md`: project root (<60 lines)27- Parent directory: monorepo shared conventions (<40 lines)28- Child directory: module-specific overrides (<30 lines)2930The location determines scope, line budget, and content focus.3132---3334## CREATE Mode3536### 2a. Auto-Detect Project Context3738Scan the project for signals. Read files as needed, don't guess:3940| Signal | What to look for |41|--------|-----------------|42| **Package manager** | `package.json`, `pyproject.toml`, `Cargo.toml`, `go.mod`, `Gemfile`, `pom.xml` |43| **Build system** | `Makefile`, `Justfile`, `build.gradle`, `CMakeLists.txt`, `Taskfile.yml` |44| **Config files** | `tsconfig.json`, `.eslintrc*`, `.prettierrc*`, `ruff.toml`, `clippy.toml` |45| **Test framework** | `jest.config.*`, `pytest.ini`, `setup.cfg [tool:pytest]`, `.mocharc.*` |46| **CI/CD** | `.github/workflows/`, `.gitlab-ci.yml`, `Jenkinsfile` |47| **Monorepo** | `packages/`, `apps/`, workspace config in package.json, `pnpm-workspace.yaml` |48| **Existing docs** | `README.md`, `CONTRIBUTING.md`, `docs/` |49| **Git conventions** | Recent commit messages (`git log --oneline -20`), branch naming patterns |50| **Existing .claude/** | `.claude/` directory, existing CLAUDE.md files at other levels |5152Read `README.md` if it exists. It often contains build/test commands and architecture notes.5354### 2b. Interview the User5556Ask 2-4 targeted questions about things you **could not auto-detect**:5758- "Are there architectural decisions or trade-offs I should know about?"59- "Any gotchas or things that trip up new contributors?"60- "Any non-obvious commands or workflows?" (only if Makefile/scripts don't make them clear)61- For home CLAUDE.md: "What coding preferences do you want applied to all projects?"6263Do NOT ask about things you already detected. Keep questions specific and actionable.6465### 2c. Generate the CLAUDE.md66671. Select the appropriate template from `references/templates.md` based on detected project type682. Fill in auto-detected commands and conventions693. Incorporate user answers from the interview704. Apply constraints from `references/best-practices.md`:71 - Stay under the line budget for the target location72 - Only include what Claude can't figure out from code73 - Every line must be universally applicable (no task-specific instructions)74 - Use IMPORTANT/MUST sparingly (max 2-3 per file)75 - Don't describe tools Claude already knows76 - Don't duplicate README content77 - For code style/pattern rules, point to canonical files instead of prose descriptions785. If content exceeds the line budget, use `@path` imports for progressive disclosure796. Present the draft to the user for review807. Write the file only after user approval8182---8384## UPDATE Mode8586### 2a. Diagnose the Existing File8788Read the existing CLAUDE.md and evaluate against `references/best-practices.md`:8990**Check for these problems:**91- **Too long**: exceeds line budget for its location92- **Redundant**: duplicates README, states obvious conventions, describes tools Claude knows93- **Missing critical sections**: no build/test commands, no architecture context94- **Task-specific instructions**: contains instructions for specific features or tickets95- **Linter-as-CLAUDE.md**: style rules that should be in a formatter/linter config96- **Over-emphasized**: too many IMPORTANT/MUST/ALWAYS/NEVER markers97- **Stale**: references files, tools, or conventions that no longer exist98- **File-by-file descriptions**: describes what each file does (Claude can read them)99- **Generic/template content**: instructions copied from a template that don't match the actual project100- **History not guidance**: instructions phrased as past events ("we migrated to X") instead of forward-looking rules ("use X for all new work")101102### 2b. Auto-Detect Context Changes103104Scan the project (same signals as CREATE mode) to find:105- New tools or frameworks added since the CLAUDE.md was written106- Commands that have changed107- Conventions that are now enforced by tooling (and can be removed from CLAUDE.md)108109### 2c. Propose Changes110111Present **surgical changes** with rationale for each:112- What to remove and why (e.g., "Remove ESLint style rules, these are enforced by your .eslintrc")113- What to add and why (e.g., "Add `make integration-test`, detected in Makefile but not documented")114- What to restructure and why (e.g., "Move auth-module instructions to `src/auth/CLAUDE.md`")115- Whether to introduce `@path` imports for progressive disclosure116117### 2d. Apply After Approval118119Only modify the file after the user reviews and approves the changes.120121---122123## Key Principles (Always Apply)1241251. **CLAUDE.md is onboarding for a stateless agent, not documentation.** Claude reads it fresh every session.1262. **Only include what Claude cannot figure out from code.** If it's in package.json, tsconfig.json, or the code itself, don't repeat it.1273. **Every line must be universally applicable.** No task-specific, ticket-specific, or sprint-specific content.1284. **Concise > comprehensive.** A 30-line CLAUDE.md that's followed beats a 200-line one that's ignored.1295. **Use hooks and formatters instead of linting instructions.** Claude respects tool output; don't manually enforce style.1306. **Use @path imports for progressive disclosure.** Keep root lean, add depth through references.1317. **Maintain with the litmus test: "Would this mislead an agent?"** When code changes, ask if an outdated CLAUDE.md instruction would cause Claude to make a mistake. Update when contracts/boundaries change; skip when only implementation details change.132133---134135## Reference Files136137Read these as needed during the workflow:138139- `references/best-practices.md`: do's, don'ts, anti-patterns, and the instruction budget framework140- `references/location-guide.md`: what content belongs at each CLAUDE.md location and how levels interact141- `references/templates.md`: starter templates by project type (Python, Node/TS, Go, Rust, generic, home)142143---144145## Output Format146147The generated CLAUDE.md should:148- Use `#` headers to organize sections (Build & Test, Architecture, Conventions, Gotchas)149- Use code blocks for commands150- Use bullet points for rules and conventions151- Include blank lines between sections for readability152- NOT include meta-commentary ("This file was generated by...")153- NOT include the line budget or other meta-instructions in the output