ai-coding/skills/claude-memory/SKILL.md
Create and optimize CLAUDE.md memory files or .claude/rules/ modular rules for Claude Code projects. Comprehensive guidance on file hierarchy, content structure, path-scoped rules, best practices, and anti-patterns. Use when working with CLAUDE.md files, .claude/rules directories, setting up new projects, or improving Claude Code's context awareness.
npx skillsauth add melvynx/aiblueprint claude-memoryInstall this skill globally with one command. Works with Claude Code, Cursor, and Windsurf.
3 of 9 scanners reported clean
Some scanners were skipped, did not run, or reported a non-clean status. Review each row below.
<core_principle> Memory files consume tokens from the context window. ~100-150 instruction slots available for your customizations. Keep files minimal — only include what the agent cannot discover on its own.
Two approaches:
<quick_start>
Run /init to auto-generate a CLAUDE.md. Or create manually:
# Project Name
## Tech Stack
- [Primary framework]
- [Key non-obvious libraries]
## Commands
- `npm run dev` - Dev server
- `npm test` - Run tests
- `npm run build` - Build
## Rules
- [2-3 critical project-specific rules]
# during a session to add memory items quickly/memory to open CLAUDE.md in your editor
</quick_start><file_hierarchy>
| Priority | Location | Scope |
|----------|----------|-------|
| 1 (Highest) | Enterprise policy (managed by IT) | All org users |
| 2 | ./CLAUDE.md or ./.claude/CLAUDE.md | Team via git |
| 2 | ./.claude/rules/*.md | Team via git |
| 3 | ~/.claude/CLAUDE.md | All your projects |
| 3 | ~/.claude/rules/*.md | All your projects |
| 4 (Lowest) | ./CLAUDE.local.md (auto-gitignored) | Just you |
Claude recurses UP from current directory, loading all CLAUDE.md files found. Also discovers CLAUDE.md in subtrees when reading files in those directories.
Monorepo strategy: Root file defines WHEN; subtree files define HOW.
root/CLAUDE.md # Universal: tech stack, git workflow
apps/web/CLAUDE.md # Frontend-specific
apps/api/CLAUDE.md # Backend-specific
</file_hierarchy>
<rules_directory>
The .claude/rules/ directory splits instructions into focused markdown files.
Use .claude/rules/ when: many concerns, different rules for different file types, team maintains different areas.
Use CLAUDE.md when: small project, universal rules, single source of truth.
Path-scoped rules use YAML frontmatter:
---
paths:
- "src/api/**/*.ts"
---
# API Rules
- All endpoints must include input validation
Supported patterns: **/*.ts, src/**/*, src/**/*.{ts,tsx}, {src,lib}/**/*.ts
Rules without paths frontmatter load unconditionally.
See references/rules-directory-guide.md for complete guide including symlinks, user-level rules, and migration. </rules_directory>
<content_structure> Structure CLAUDE.md with only these sections:
Do NOT include:
See references/section-templates.md for ready-to-use templates. See references/project-patterns.md for framework-specific patterns. </content_structure>
<writing_rules> Golden rule: If someone with zero project context reads your CLAUDE.md and gets confused, Claude will too.
Be specific, never vague:
❌ "Format code properly" / "Write good tests" / "Follow best practices"
✅ "Run `pnpm lint` before committing" / "Tests in `__tests__/` using Vitest"
Prohibitions > positive guidance:
❌ "Try to use TanStack Form for forms"
✅ "NEVER use native form/useState for forms — ALWAYS use TanStack Form"
Show, don't tell: When format matters, show a concrete example (3-5 lines max).
Emphasis hierarchy: CRITICAL > NEVER > ALWAYS > IMPORTANT > YOU MUST
**CRITICAL**: Never commit secretsSee references/prompting-techniques.md for advanced techniques. </writing_rules>
<size_limits>
When exceeding limits, split into .claude/rules/ files or link to separate docs:
- **API patterns**: See [docs/api-patterns.md](docs/api-patterns.md)
- **Testing guide**: See [docs/testing-guide.md](docs/testing-guide.md)
CLAUDE.md supports importing: @docs/coding-standards.md (relative/absolute paths, ~ expansion, up to 5 levels deep, not evaluated inside code blocks).
</size_limits>
Before creating or updating memory files, use AskUserQuestion:
Creating new memory:
/init or minimal templateMaintaining:
# for quick additions during workTroubleshooting:
| Problem | Solution |
|---------|----------|
| Claude ignores instructions | Reduce file size, add emphasis (CRITICAL, NEVER) |
| Context overflow | Use /clear, split into .claude/rules/ |
| Instructions conflict | Consolidate, use hierarchy (root vs subtree) |
| Path rules not applying | Verify glob pattern matches target files |
</workflow>
<init_workflow>
/claude-memory init — Create Minimal CLAUDE.mdWhen the user argument contains "init", execute this workflow to scaffold a CLAUDE.md with only the essential sections.
Read package.json (or equivalent: pyproject.toml, Cargo.toml, go.mod, etc.) to detect:
Also check for existing linter configs (ESLint, Biome, Prettier, tsconfig) — do NOT include rules they already enforce.
Scan for non-obvious architecture-critical files. Look for:
Create the file with ONLY these sections. Each section should be compact — the whole file should be under 50 lines.
# [Project Name]
[One-line description of what this project is]
## Tech Stack
- [Only non-obvious technologies — skip deps detectable from config files]
## Commands
- `[dev command]` - Dev server
- `[build command]` - Build
- `[test command]` - Tests
- [Any non-obvious commands like db:push, seed, etc.]
## Important Files
- [Only files the agent wouldn't discover naturally]
## Rules
- [Leave empty with a comment: "Add project-specific rules as you encounter friction"]
Show the generated file to the user. Write it to ./CLAUDE.md after approval.
Rules:
<optimize_workflow>
/claude-memory optimize — Deep CLAUDE.md CleanupWhen the user argument contains "optimize", execute this workflow.
CRITICAL — Step 0 is MANDATORY. Do NOT skip it. Do NOT start optimizing without reading the guide first.
YOU MUST use the Read tool on {SKILL_PATH}/references/optimize-guide.md BEFORE doing anything else.
This file contains the research data (ETH Zurich study), the 6 bloat categories with specific examples, target metrics, and before/after examples. Without reading it, you will miss removal criteria and produce a subpar optimization.
Read every CLAUDE.md, CLAUDE.local.md, and .claude/rules/*.md in the project. Count total lines.
Read ESLint/Biome/Prettier/TypeScript configs. Any CLAUDE.md line duplicating an enforced rule → delete.
For each line ask: "Can the agent discover this by reading the project, or does a linter enforce this?" If yes → delete.
Remove everything matching:
Show before/after with line counts. For each removal, cite which bloat category it falls under. Let user approve before applying changes.
Target: < 100 lines ideal, < 150 max. </optimize_workflow>
<reference_guides>
development
Create or edit Claude, Codex, and Cursor skills/rules. Use for SKILL.md, .cursor/rules, AGENTS.md, skill prompts, frontmatter, references, scripts, and discovery rules.
data-ai
Create and maintain agent rules in AGENTS.md and .agents/rules/. Use for project rules, conventions, constraints, rule indexes, or requests to add or optimize agent rules.
development
Set up per-worktree environments for Claude Code, Cursor, or Codex. Use for worktree-ready repos, IDE environment config, worktree-up/down scripts, or dev.sh wiring.
testing
Interview the user relentlessly about a plan or design until reaching shared understanding, resolving each branch of the decision tree. Use when user wants to stress-test a plan, get grilled on their design, or mentions "grill me".