Instructions for Managing CLAUDE.md Files
Determine Action Type
CREATE: New CLAUDE.md file requested
UPDATE: Modify existing CLAUDE.md (keywords: "update", "add", "modify", "change")
OPTIMIZE: Improve token efficiency (keywords: "optimize", "reduce tokens", "improve")
Updating Existing CLAUDE.md Files
- Read current file: Always read before editing
- Identify section: Locate relevant section or create new heading
- Make surgical edits: Use Edit tool for precise changes
- Preserve structure: Maintain existing organization patterns
- Validate: Ensure markdown is valid and clear
Optimizing CLAUDE.md Files
Audit current content:
- Identify verbose prose that can become bullets
- Find repetitive information
- Locate outdated or irrelevant content
Apply compression techniques:
- Convert paragraphs → bullets or tables
- Remove unnecessary words and filler
- Use abbreviations where context is clear
- Group similar items together
Remove anti-patterns:
- Delete sensitive information (credentials, tokens)
- Remove frequently changing data
- Extract verbose documentation to separate files
- Remove duplicate information
Validate token efficiency: Aim for maximum signal, minimum tokens
See reference.md for optimization strategies and examples.
Creating New CLAUDE.md Files
Gather context: Ask user for project details if missing:
- Coding standards (indentation, naming conventions)
- Build/test/deployment commands
- Architectural patterns
- Security requirements
Organize around WHAT/WHY/HOW:
- WHAT: Tech stack, codebase map, key packages
- WHY: Project purpose, component responsibilities
- HOW: Build/test/deploy commands, verification methods
Determine organization strategy (memory hierarchy):
Main CLAUDE.md (universal, <200 tokens ideal, <500 acceptable):
- Build/test/deploy commands
- Universal code style applying to all files
- Critical patterns used everywhere
- Cohesive project-wide conventions (Git, Security, Planning, Style)
CLAUDE.md in project root (shared via git)
.claude/rules/ (modular, 100-300 tokens each):
- Path/language-specific files (auto-loaded):
python.md, javascript.md
- Domain-specific patterns:
frontend/, backend/
- Path-specific rules with frontmatter (see reference.md)
CLAUDE.local.md (personal, auto-gitignored):
- Personal preferences not shared with team
- Local dev shortcuts, experimental rules
~/.claude/CLAUDE.md (cross-project personal):
- Universal personal preferences across all projects
@imports (lazy-loaded reference):
- External docs:
@README, @docs/architecture.md
- Home directory:
@~/.claude/my-prefs.md
Memory load order (later overrides earlier):
- Enterprise policy → 2. Project memory → 3. Project rules (.claude/rules/) → 4. User memory (~/.claude/) → 5. Project local (CLAUDE.local.md)
Organization decision tree:
- Universal + cohesive (Git/Security/Planning)? → Main CLAUDE.md (even if 200-500 tokens)
- Path/language-specific (Python/JS/Bash rules)? → .claude/rules/lang.md with frontmatter
- Domain-specific (frontend/backend patterns)? → .claude/rules/domain/
- Topic >300 tokens standalone? → Consider .claude/rules/topic.md
- Personal preferences? → CLAUDE.local.md or ~/.claude/
- Detailed reference docs? → @import external docs
Universal vs Path-Specific Decision:
Keep in main CLAUDE.md:
- Universal conventions applying to ALL files/operations
- Cohesive conceptual units (Git workflow, Security policies, Style guides)
- Even if combined total is 200-500 tokens
- Examples: commit format, pre-commit flow, security exclusions, output formatting
Extract to .claude/rules/:
- Path/language-specific rules (Python for
*.py, React for *.tsx)
- Domain-specific patterns (
frontend/, backend/, infra/)
- When single topic exceeds ~300 tokens standalone
- Examples:
python.md with paths: "**/*.py", bash-scripting.md with paths: "**/*.sh"
Key principle: Cohesion and semantic grouping matter more than strict token limits. A well-organized 430-token CLAUDE.md with universal sections (Git 90 + Security 50 + Planning 45 + Style 200 = 385 tokens) is better than fragmenting conceptually related content across multiple files.
Structure content (token-efficient):
- Use markdown headings for organization
- Use tables and bullets over prose
- Be specific (e.g., "Use 2-space indentation" not "Format code properly")
- Group related items logically
Include sanity marker (optional but recommended):
sanity check: [random-number]
Write file with appropriate sections based on user context
See reference.md § Templates for starter examples and § Modular Rules for .claude/rules/ patterns.
Key Principles
- Specific over generic: "Run
npm test" not "Test the code"
- Persistent not temporary: Coding standards yes, current bug no
- Concise not verbose: Bullets and tables over paragraphs
- Modular organization: Main CLAUDE.md + .claude/rules/ + @imports
- Path-specific when needed: Frontmatter with
paths: glob patterns
- Secure: Never include credentials or sensitive data
MANDATORY Validation (CREATE only)
STOP: Before creating new CLAUDE.md, answer YES/NO for each:
- Q1: Persistent (not temporary)? [YES/NO]
- Q2: Frequently referenced (coding standards, workflows)? [YES/NO]
- Q3: Concise (avoid verbose docs)? [YES/NO]
- Q4: Non-sensitive (no credentials/tokens)? [YES/NO]
If ANY answer is NO:
→ STOP. Explain why inappropriate.
→ Recommend alternatives: README.md (docs), environment variables (secrets), direct request (one-time), .claude/rules/ (detailed guidelines)
→ EXIT immediately.
If ALL answers are YES:
→ Proceed to "Creating New CLAUDE.md Files" section above.
Progressive Disclosure
Keep main CLAUDE.md lean (<200 tokens). Distribute content:
Modular rules (.claude/rules/ - auto-loaded):
.claude/rules/
|- code-style.md
|- security.md
|- frontend/react.md
|- backend/api.md
Imports (lazy-loaded when referenced):
@README
@docs/architecture.md
@~/.claude/my-project-prefs.md
Reference docs (external):
reference/
|- runbooks/building.md
|- standards/conventions.md
Use /memory command during session to view/edit loaded memories.
Constraints
- Instruction budget: LLMs follow ~150-200 instructions reliably. Claude Code's system prompt uses ~50, leaving ~100 for CLAUDE.md
- Token target: Main CLAUDE.md <200 tokens ideal, <500 acceptable for universal cohesive content
- Universal relevance: Every line should apply to most sessions, not task-specific work
- Modular distribution: Use .claude/rules/ for path/language/domain-specific content, not to fragment universal cohesive sections
- Cohesion over tokens: Keep conceptually related universal sections together (Git, Security, Planning, Style) even if combined total is 200-500 tokens
See reference.md § Content Guidelines for inclusion/exclusion rules and anti-patterns.
Validation Checklist
See reference.md § Templates, § Modular Rules, and § Import Syntax for detailed examples.
1---2name: edit-claude3description: Creates, updates, or optimizes CLAUDE.md files following Anthropic best practices. Use when user requests creating, updating, improving, or optimizing CLAUDE.md files for project context, coding standards, or persistent memory.4---56# Instructions for Managing CLAUDE.md Files78## Determine Action Type910**CREATE**: New CLAUDE.md file requested11**UPDATE**: Modify existing CLAUDE.md (keywords: "update", "add", "modify", "change")12**OPTIMIZE**: Improve token efficiency (keywords: "optimize", "reduce tokens", "improve")1314## Updating Existing CLAUDE.md Files15161. **Read current file**: Always read before editing172. **Identify section**: Locate relevant section or create new heading183. **Make surgical edits**: Use Edit tool for precise changes194. **Preserve structure**: Maintain existing organization patterns205. **Validate**: Ensure markdown is valid and clear2122## Optimizing CLAUDE.md Files23241. **Audit current content**:25 - Identify verbose prose that can become bullets26 - Find repetitive information27 - Locate outdated or irrelevant content28292. **Apply compression techniques**:30 - Convert paragraphs → bullets or tables31 - Remove unnecessary words and filler32 - Use abbreviations where context is clear33 - Group similar items together34353. **Remove anti-patterns**:36 - Delete sensitive information (credentials, tokens)37 - Remove frequently changing data38 - Extract verbose documentation to separate files39 - Remove duplicate information40414. **Validate token efficiency**: Aim for maximum signal, minimum tokens4243See `reference.md` for optimization strategies and examples.4445## Creating New CLAUDE.md Files46471. **Gather context**: Ask user for project details if missing:48 - Coding standards (indentation, naming conventions)49 - Build/test/deployment commands50 - Architectural patterns51 - Security requirements52532. **Organize around WHAT/WHY/HOW**:54 - **WHAT**: Tech stack, codebase map, key packages55 - **WHY**: Project purpose, component responsibilities56 - **HOW**: Build/test/deploy commands, verification methods57583. **Determine organization strategy** (memory hierarchy):5960 **Main CLAUDE.md** (universal, <200 tokens ideal, <500 acceptable):61 - Build/test/deploy commands62 - Universal code style applying to all files63 - Critical patterns used everywhere64 - Cohesive project-wide conventions (Git, Security, Planning, Style)65 - `CLAUDE.md` in project root (shared via git)6667 **.claude/rules/** (modular, 100-300 tokens each):68 - Path/language-specific files (auto-loaded): `python.md`, `javascript.md`69 - Domain-specific patterns: `frontend/`, `backend/`70 - Path-specific rules with frontmatter (see reference.md)7172 **CLAUDE.local.md** (personal, auto-gitignored):73 - Personal preferences not shared with team74 - Local dev shortcuts, experimental rules7576 **~/.claude/CLAUDE.md** (cross-project personal):77 - Universal personal preferences across all projects7879 **@imports** (lazy-loaded reference):80 - External docs: `@README`, `@docs/architecture.md`81 - Home directory: `@~/.claude/my-prefs.md`8283 **Memory load order** (later overrides earlier):84 1. Enterprise policy → 2. Project memory → 3. Project rules (.claude/rules/) → 4. User memory (~/.claude/) → 5. Project local (CLAUDE.local.md)85864. **Organization decision tree**:87 - Universal + cohesive (Git/Security/Planning)? → Main CLAUDE.md (even if 200-500 tokens)88 - Path/language-specific (Python/JS/Bash rules)? → .claude/rules/lang.md with frontmatter89 - Domain-specific (frontend/backend patterns)? → .claude/rules/domain/90 - Topic >300 tokens standalone? → Consider .claude/rules/topic.md91 - Personal preferences? → CLAUDE.local.md or ~/.claude/92 - Detailed reference docs? → @import external docs93945. **Universal vs Path-Specific Decision**:9596 **Keep in main CLAUDE.md:**97 - Universal conventions applying to ALL files/operations98 - Cohesive conceptual units (Git workflow, Security policies, Style guides)99 - Even if combined total is 200-500 tokens100 - Examples: commit format, pre-commit flow, security exclusions, output formatting101102 **Extract to .claude/rules/:**103 - Path/language-specific rules (Python for `*.py`, React for `*.tsx`)104 - Domain-specific patterns (`frontend/`, `backend/`, `infra/`)105 - When single topic exceeds ~300 tokens standalone106 - Examples: `python.md` with `paths: "**/*.py"`, `bash-scripting.md` with `paths: "**/*.sh"`107108 **Key principle:** Cohesion and semantic grouping matter more than strict token limits. A well-organized 430-token CLAUDE.md with universal sections (Git 90 + Security 50 + Planning 45 + Style 200 = 385 tokens) is better than fragmenting conceptually related content across multiple files.1091106. **Structure content** (token-efficient):111 - Use markdown headings for organization112 - Use tables and bullets over prose113 - Be specific (e.g., "Use 2-space indentation" not "Format code properly")114 - Group related items logically1151167. **Include sanity marker** (optional but recommended):117 ```118 sanity check: [random-number]119 ```1201218. **Write file** with appropriate sections based on user context122123See `reference.md § Templates` for starter examples and `§ Modular Rules` for .claude/rules/ patterns.124125## Key Principles126127- **Specific over generic**: "Run `npm test`" not "Test the code"128- **Persistent not temporary**: Coding standards yes, current bug no129- **Concise not verbose**: Bullets and tables over paragraphs130- **Modular organization**: Main CLAUDE.md + .claude/rules/ + @imports131- **Path-specific when needed**: Frontmatter with `paths:` glob patterns132- **Secure**: Never include credentials or sensitive data133134## MANDATORY Validation (CREATE only)135136**STOP**: Before creating new CLAUDE.md, answer YES/NO for each:137138- **Q1: Persistent** (not temporary)? [YES/NO]139- **Q2: Frequently referenced** (coding standards, workflows)? [YES/NO]140- **Q3: Concise** (avoid verbose docs)? [YES/NO]141- **Q4: Non-sensitive** (no credentials/tokens)? [YES/NO]142143**If ANY answer is NO:**144→ STOP. Explain why inappropriate.145→ Recommend alternatives: README.md (docs), environment variables (secrets), direct request (one-time), .claude/rules/ (detailed guidelines)146→ EXIT immediately.147148**If ALL answers are YES:**149→ Proceed to "Creating New CLAUDE.md Files" section above.150151---152153## Progressive Disclosure154155Keep main CLAUDE.md lean (<200 tokens). Distribute content:156157**Modular rules** (.claude/rules/ - auto-loaded):158```159.claude/rules/160 |- code-style.md161 |- security.md162 |- frontend/react.md163 |- backend/api.md164```165166**Imports** (lazy-loaded when referenced):167```markdown168@README169@docs/architecture.md170@~/.claude/my-project-prefs.md171```172173**Reference docs** (external):174```175reference/176 |- runbooks/building.md177 |- standards/conventions.md178```179180Use `/memory` command during session to view/edit loaded memories.181182## Constraints183184- **Instruction budget**: LLMs follow ~150-200 instructions reliably. Claude Code's system prompt uses ~50, leaving ~100 for CLAUDE.md185- **Token target**: Main CLAUDE.md <200 tokens ideal, <500 acceptable for universal cohesive content186- **Universal relevance**: Every line should apply to most sessions, not task-specific work187- **Modular distribution**: Use .claude/rules/ for path/language/domain-specific content, not to fragment universal cohesive sections188- **Cohesion over tokens**: Keep conceptually related universal sections together (Git, Security, Planning, Style) even if combined total is 200-500 tokens189190See `reference.md § Content Guidelines` for inclusion/exclusion rules and anti-patterns.191192## Validation Checklist193194- [ ] Information is persistent and frequently referenced195- [ ] No sensitive credentials or tokens included196- [ ] Content is concise and token-efficient (<200 tokens for main CLAUDE.md)197- [ ] Markdown structure is clear with headings198- [ ] Specific guidelines (not generic advice)199- [ ] Appropriate organization: main vs .claude/rules/ vs @imports200- [ ] Path-specific rules use frontmatter (if applicable)201- [ ] Sanity marker included (optional)202203See `reference.md § Templates`, `§ Modular Rules`, and `§ Import Syntax` for detailed examples.