home / skills / gwenwindflower / .charmschool / claude-memory-files

claude-memory-files skill

/agents/claude/skills/claude-memory-files

This skill creates and refines CLAUDE.md memory files for Claude Code, helping structure, imports, and modular rules.

npx playbooks add skill gwenwindflower/.charmschool --skill claude-memory-files

Review the files below or copy the command above to add this skill to your agents.

Files (2)
SKILL.md
7.4 KB
---
name: claude-memory-files
description: |
  Write, create, and improve CLAUDE.md project memory files for Claude Code. Use when: (1) Creating or bootstrapping a new CLAUDE.md, (2) Improving, refactoring, or splitting a bloated CLAUDE.md, (3) Questions about CLAUDE.md structure, imports, or modular rules, (4) After significant codebase exploration—cache discoveries to avoid re-crawling.
---

# CLAUDE.md Authoring

Write effective project memory files that give Claude Code the context it needs without wasting tokens.

## Core Principles

**Be specific and actionable.** "Use 2-space indentation in TypeScript" beats "format code properly."

**Progressive disclosure.** Keep root CLAUDE.md minimal. Split detailed guidance into `.claude/rules/` files or use `@imports`.

**Challenge every line.** Claude is already smart—only add context it doesn't have. Ask: "Does this justify its token cost?"

**Avoid redundancy.** Don't repeat what's in README, package.json, or inferable from code.

**Living document.** After significant exploration, update with discoveries to prevent re-crawling.

## Degrees of Freedom

Match instruction specificity to the task's fragility:

- **High freedom** (guidance): Multiple valid approaches, context-dependent decisions
- **Medium freedom** (patterns): Preferred approach exists, some variation acceptable
- **Low freedom** (strict rules): Operations are fragile, consistency critical, specific sequence required

**When unsure, opt for lowest freedom.** Rules can be loosened later, but damage from under-specified guidance can't always be undone. Treat CLAUDE.md as a least-privilege system.

## File Locations

| Location | Purpose | Shared With |
| --- | --- | --- |
| `./CLAUDE.md` or `./.claude/CLAUDE.md` | Team project instructions | Team (via git) |
| `./.claude/rules/*.md` | Modular topic rules | Team (via git) |
| `./CLAUDE.local.md` | Personal project prefs | Just you |
| `~/.claude/CLAUDE.md` | Personal global prefs | Just you (all projects) |
| `~/.claude/rules/*.md` | Personal global rules | Just you (all projects) |

## Creating a New CLAUDE.md

### Quick Start

Run `/init` in Claude Code to bootstrap, then refine.

### Essential Sections

A good CLAUDE.md typically includes:

```markdown
# Project Name

Brief context (1-2 sentences): what this is, primary language/framework.

## Before Starting Work

Before exploring the codebase via file reads or bash commands, ask the user for:
- Existing architecture diagrams or documentation
- File tree documentation or codebase maps
- Relevant context from previous sessions
- Links to design docs, ADRs, or wikis

This avoids redundant exploration. After any significant discovery, update this CLAUDE.md.

## Project Structure

[Key directories and their purposes - avoids repeated `find` and `ls` commands]

- `src/api/` - REST endpoints, organized by resource
- `src/services/` - Business logic, one service per domain
- `src/models/` - Database models (Prisma)
- `tests/` - Mirrors src/ structure

## Commands

- Build: `pnpm run build`
- Test: `pnpm run test`
- Lint: `pnpm run lint`

## Architecture

[Non-obvious patterns, key abstractions, data flow]

## Conventions

- [Specific, actionable rules]
- [Things Claude wouldn't know from reading code]
```

### What to Include

- **Before Starting Work section** - instruct agent to ask for existing context before exploring
- **Project structure map** - key directories and purposes (avoids repeated file tree crawling)
- **Frequent commands** - build, test, lint, deploy (avoid repeated discovery)
- **Architecture overview** - key patterns, data flow, module boundaries
- **Non-obvious conventions** - naming patterns, file organization choices, commit style
- **Critical warnings** - "never modify X directly", "requires Y before Z"

### What to Exclude

- **Claude's existing knowledge**: Generic language idioms, standard library usage, common patterns
- **Redundant content**: Already in README.md, package.json, or inferable from code
- **Vague directives**: "Write clean code", "follow best practices", "be thorough"

## The Living Document Workflow

**Ideal workflow after significant work:**

1. Request comes in
2. Read files, explore codebase, do the work
3. Before ending session: update CLAUDE.md with what was learned or changed

**What to capture after exploration:**

- Directory structures discovered (so future sessions don't re-crawl)
- Key files and their purposes
- Patterns identified in the codebase
- Gotchas or non-obvious behaviors
- New conventions established during the work

**Example update after exploration:**

```markdown
## Project Structure (updated 2024-01)

After exploring the codebase:

- `src/handlers/` - Lambda handlers, one per API route
- `src/lib/` - Shared utilities
  - `src/lib/db.ts` - Database connection singleton
  - `src/lib/auth.ts` - JWT validation middleware
- `infrastructure/` - CDK stacks (not Terraform as README suggests)
```

**Trigger phrases for updating CLAUDE.md:**

- "Let me update CLAUDE.md with what we learned"
- "I should document this discovery"
- "Future sessions will benefit from knowing..."

## Using Imports

Import files with `@path/to/file` syntax:

```markdown
See @README.md for project overview.
Standard commands in @package.json.

## Team Conventions
- Git workflow: @docs/git-workflow.md
- API patterns: @docs/api-standards.md

## Individual Setup
@~/.claude/personal-prefs.md
```

Imports work recursively (max depth 5). Not evaluated inside code blocks.

## Modular Rules with .claude/rules/

For larger projects, split instructions by topic:

```text
.claude/
├── CLAUDE.md              # Minimal root
└── rules/
    ├── typescript.md      # Language conventions
    ├── testing.md         # Test patterns
    ├── api.md             # API design rules
    └── frontend/
        ├── react.md
        └── styles.md
```

### Path-Scoped Rules

Use YAML frontmatter to scope rules to specific files:

```markdown
---
paths:
  - "src/api/**/*.ts"
  - "src/services/**/*.ts"
---

# API Layer Rules

- All endpoints require input validation
- Use standard error response format from @docs/errors.md
```

Glob patterns: `**/*.ts`, `src/**/*`, `*.{ts,tsx}`, `{src,lib}/**/*.ts`

## Refactoring a Bloated CLAUDE.md

If CLAUDE.md exceeds ~50 lines, consider restructuring:

1. **Analyze**: Identify conflicting or redundant instructions
2. **Extract**: Keep only universal content in root (description, critical commands, overrides)
3. **Categorize**: Group remaining content by topic
4. **Split**: Move to `.claude/rules/` or imported files
5. **Prune**: Remove vague directives, defaults Claude already knows, outdated refs

See [refactoring checklist](./references/refactoring-checklist.md) for detailed guidance.

## Markdown Formatting

CLAUDE.md files should follow standard markdownlint rules. Detailed guidance is available in user-level rules (`~/.claude/rules/`):

- **Code blocks**: Always specify a language. Use `text` for file trees and non-code content.
- **Tables**: Use spaces around inner pipe edges (`| cell | cell |` not `|cell|cell|`).

## Quality Checklist

Before committing CLAUDE.md changes:

- [ ] Every instruction is specific and actionable
- [ ] No duplication with README or other docs
- [ ] Root file under 50 lines (for larger projects)
- [ ] No generic advice Claude already knows
- [ ] Commands are accurate and tested
- [ ] Path-scoped rules use correct glob patterns
- [ ] Imports resolve to existing files
- [ ] Recent explorations/discoveries have been captured

Overview

This skill writes, creates, and improves CLAUDE.md project memory files tailored for Claude Code. It helps bootstrap a minimal root memory, refactor bloated memories into modular rules, and capture discoveries after exploring a codebase to avoid repeated crawling. It focuses on concise, actionable instructions that save tokens and reduce redundant file reads.

How this skill works

The skill analyzes repository layout, build/test commands, and non-obvious conventions to produce or update CLAUDE.md and optional .claude/rules/*.md files. It suggests a minimal root file with progressive-disclosure imports and can split large documents into scoped rule files with YAML path frontmatter. It also generates a "Before Starting Work" checklist to force the agent to ask for external context before exploring files.

When to use it

  • Bootstrapping a new CLAUDE.md for a project
  • Refactoring or splitting a CLAUDE.md longer than ~50 lines
  • Adding discoveries after significant codebase exploration to cache structure and gotchas
  • Defining path-scoped rules for fragile or critical operations
  • Clarifying imports, import depth, and modular rule placement

Best practices

  • Keep root CLAUDE.md minimal; move details into .claude/rules or imported files
  • Prefer specific, actionable rules over vague guidance (e.g., exact indentation, filenames, or commands)
  • Include a Before Starting Work section instructing the agent to ask for context before file reads
  • When in doubt, choose lower degrees of freedom (strict rules) for fragile operations; relax later if safe
  • Use imports (@path/to/file) and path-scoped YAML frontmatter to avoid duplication and re-crawling

Example use cases

  • Create a one-page CLAUDE.md with project summary, key directories, and commands (build/test/lint)
  • Split a bloated CLAUDE.md into topic files under .claude/rules (typescript.md, testing.md, api.md) with YAML path scoping
  • After exploring the repo, update CLAUDE.md with discovered directory structure and critical files to prevent future crawling
  • Add critical warnings and non-obvious conventions (files never to modify, required bootstrap steps)
  • Generate imports to link README and package.json without duplicating content

FAQ

How large should the root CLAUDE.md be?

Aim for under ~50 lines; move detailed rules into .claude/rules or imports.

When should I use path-scoped rules?

Use them for layer-specific constraints or fragile operations where consistent behavior matters.

How do imports behave?

Use @path/to/file; imports resolve recursively up to a depth of five and are not evaluated inside code fences.