AgentSkillsCN

memory-reference

Claude Code内存(CLAUDE.md)配置参考。在设置项目内存、理解内存层级,或配置持久化指令时,可选用此技能。

SKILL.md
--- frontmatter
name: memory-reference
description: Claude Code memory (CLAUDE.md) configuration reference. Use when setting up project memory, understanding memory hierarchy, or configuring persistent instructions.

Claude Code Memory Reference

Memory files (CLAUDE.md) provide persistent instructions that Claude loads every session.

Memory Hierarchy (Priority Order)

PriorityLocationPurposeShared With
1 (highest)Enterprise policyOrganization rulesAll users
2./CLAUDE.mdProject instructionsTeam via git
3./.claude/CLAUDE.mdAlternative project locationTeam via git
4./.claude/rules/*.mdModular project rulesTeam via git
5~/.claude/CLAUDE.mdPersonal preferencesJust you
6./CLAUDE.local.mdPersonal project prefsJust you (gitignored)

File Locations

code
/Library/Application Support/ClaudeCode/CLAUDE.md  # Enterprise (macOS)
./CLAUDE.md                                         # Project root
./.claude/CLAUDE.md                                 # Alternative project
./.claude/rules/*.md                                # Modular rules
~/.claude/CLAUDE.md                                 # User global
~/.claude/rules/*.md                                # User modular rules
./CLAUDE.local.md                                   # Project personal

Basic CLAUDE.md

markdown
# Project Instructions

## Code Style
- Use TypeScript for all new files
- Prefer functional components in React
- Use ESLint and Prettier for formatting

## Commands
- Build: `npm run build`
- Test: `npm test`
- Lint: `npm run lint`

## Architecture
- Components in `src/components/`
- API routes in `src/api/`
- Types in `src/types/`

Importing Files

Use @path/to/file to import other files:

markdown
# Project Memory

See @README.md for project overview.
See @package.json for available commands.

## Team Guidelines
@docs/guidelines.md

## Personal Preferences
@~/.claude/my-prefs.md

Import rules:

  • Relative and absolute paths allowed
  • Max depth: 5 hops
  • Not evaluated in code blocks

Modular Rules (.claude/rules/)

Organize rules by topic:

code
.claude/rules/
├── code-style.md
├── testing.md
├── security.md
└── api-design.md

Path-Specific Rules

Use frontmatter to scope rules:

markdown
---
paths: src/api/**/*.ts
---

# API Development Rules

- All endpoints must validate input
- Use consistent error response format
- Document with OpenAPI comments

Glob Patterns

PatternMatches
**/*.tsAll TypeScript files
src/**/*All files under src/
*.mdMarkdown in root
src/components/*.tsxReact components
src/**/*.{ts,tsx}TS and TSX in src/

Memory Commands

CommandDescription
/memoryView/edit memory files
/initBootstrap CLAUDE.md
/memory userEdit user memory
/memory projectEdit project memory

Best Practices

Be Specific

markdown
# Good
- Use 2-space indentation
- Name React components with PascalCase

# Bad
- Format code properly
- Use good naming

Use Structure

markdown
# Build Commands
- `npm run build` - Production build
- `npm run dev` - Development server

# Test Commands
- `npm test` - Run all tests
- `npm test:watch` - Watch mode

Keep Updated

Review and update memory as project evolves.

Example: Full Project Memory

markdown
# MyApp Project

## Overview
React + TypeScript web application with Express backend.

## Quick Commands
- Dev: `npm run dev`
- Test: `npm test`
- Build: `npm run build`
- Deploy: `npm run deploy`

## Code Style
- TypeScript strict mode
- Functional React components
- CSS Modules for styling
- Jest for testing

## Architecture
- `src/client/` - React frontend
- `src/server/` - Express backend
- `src/shared/` - Shared types

## Common Patterns
- Use `useQuery` for API calls
- Validate props with Zod schemas
- Log errors to Sentry

## Git Workflow
- Feature branches from `main`
- Squash merge PRs
- Conventional commit messages

Symlinks

Share rules across projects:

bash
# Symlink shared rules
ln -s ~/shared-rules .claude/rules/shared

# Symlink specific file
ln -s ~/company-security.md .claude/rules/security.md

Symlinks are followed during loading.

Debugging

bash
# View loaded memory
/memory

# Check what files are loaded
# Memory command shows all active files

For complete documentation, see: