memory-manager
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseMemory Manager
内存管理器
Manage the full Claude Code memory hierarchy across three layers. Produces well-organised, correctly-placed memory files that follow size guidelines and progressive disclosure.
管理跨三个层级的完整Claude Code内存体系。生成结构清晰、存放位置正确且符合大小规范与渐进式披露原则的内存文件。
Three Memory Layers
三个内存层级
| Layer | Location | Purpose | Managed by this skill |
|---|---|---|---|
| CLAUDE.md hierarchy | | Project context, commands, architecture, rules | Yes |
| Rules topic files | | Correction rules, patterns, technical facts | Yes |
| Auto-memory | | Session-specific patterns | No (Claude manages automatically) |
| 层级 | 位置 | 用途 | 是否由本skill管理 |
|---|---|---|---|
| CLAUDE.md体系 | | 项目上下文、命令、架构、规则 | 是 |
| 规则主题文件 | | 修正规则、模式、技术事实 | 是 |
| 自动内存 | | 会话特定模式 | 否(由Claude自动管理) |
Operating Modes
操作模式
Mode 1: Session Capture
模式1:会话捕获
When: End of session, "capture learnings", "update CLAUDE.md with what we learned"
- Review the conversation for discoveries worth preserving:
- Commands that worked (or didn't)
- Gotchas and workarounds found
- Architecture decisions made
- Configuration quirks discovered
- Patterns that would help future sessions
- Categorise each discovery using the placement decision tree below
- Draft all changes as diffs in a single batch
- Present the batch — apply after a single yes/no confirmation
Keep it concise: one line per concept. No verbose explanations, no generic advice.
触发场景:会话结束时、执行"capture learnings"、"update CLAUDE.md with what we learned"
- 回顾对话内容,筛选值得保留的发现:
- 生效(或失效)的命令
- 发现的陷阱与解决方案
- 已确定的架构决策
- 发现的配置特殊点
- 对未来会话有帮助的模式
- 使用下方的存放决策树对每个发现进行分类
- 将所有修改以diff形式批量草拟
- 展示批量修改内容,在单次确认同意后应用
注意简洁性:每个概念仅用一行描述。避免冗长解释,不要通用建议。
Mode 2: Full Audit
模式2:完整审计
When: "audit memory", "check project docs", periodic maintenance, working in a neglected project
- Run the audit script:
bash
python3 skills/memory-manager/scripts/audit_memory.py [repo-path] - Review the output: sizes, quality scores, project type, missing docs, stale references
- Generate changes autonomously — create, update, or flag files as needed
- Present all changes as a single batch for approval
- Apply approved changes
For large repos, delegate to a sub-agent:
Task(subagent_type: "general-purpose",
prompt: "Run python3 skills/memory-manager/scripts/audit_memory.py /path/to/repo
and summarise the findings.")触发场景:执行"audit memory"、"check project docs"、定期维护、处理长期未打理的项目
- 运行审计脚本:
bash
python3 skills/memory-manager/scripts/audit_memory.py [repo-path] - 查看输出内容:文件大小、质量评分、项目类型、缺失文档、过时引用
- 自主生成修改内容——按需创建、更新或标记文件
- 将所有修改作为单个批量内容提交审批
- 应用已获批的修改
对于大型仓库,可委托给子Agent:
Task(subagent_type: "general-purpose",
prompt: "Run python3 skills/memory-manager/scripts/audit_memory.py /path/to/repo
and summarise the findings.")Mode 3: Restructure
模式3:内存重构
When: "restructure memory", root CLAUDE.md over 200 lines, first-time memory setup
- Run full audit (Mode 2) first
- Split oversized files:
- Extract topic sections from root CLAUDE.md into
.claude/rules/<topic>.md - Extract directory-specific content into sub-directory CLAUDE.md files
- Extract topic sections from root CLAUDE.md into
- Create missing documentation files based on project type
- Present the restructure plan, apply after approval
触发场景:执行"restructure memory"、根目录CLAUDE.md超过200行、首次设置内存
- 先执行完整审计(模式2)
- 拆分过大的文件:
- 从根目录CLAUDE.md中提取主题章节到
.claude/rules/<topic>.md - 将目录特定内容提取到子目录的CLAUDE.md文件中
- 从根目录CLAUDE.md中提取主题章节到
- 根据项目类型创建缺失的文档文件
- 展示重构方案,在审批通过后应用
Placement Decision Tree
存放决策树
Would this still apply if I switched to a completely different project?
├── YES → ~/.claude/rules/<topic>.md
│ (correction rules, API patterns, coding standards)
└── NO → Is it specific to a subdirectory?
├── YES → <dir>/CLAUDE.md
│ (integrations, directory-specific gotchas)
└── NO → ./CLAUDE.md (project root)
(identity, stack, commands, architecture, critical rules)如果切换到一个完全不同的项目,这些内容是否仍然适用?
├── 是 → ~/.claude/rules/<topic>.md
│ (修正规则、API模式、编码标准)
└── 否 → 内容是否特定于某个子目录?
├── 是 → <dir>/CLAUDE.md
│ (集成内容、目录特定陷阱)
└── 否 → ./CLAUDE.md(项目根目录)
(项目标识、技术栈、命令、架构、关键规则)Size Targets
大小规范
| File Type | Target | Maximum |
|---|---|---|
| Root CLAUDE.md | 50-150 lines | 200 |
| Sub-directory CLAUDE.md | 15-50 lines | 80 |
| Rules topic file | 20-80 lines | 120 |
| 文件类型 | 目标值 | 最大值 |
|---|---|---|
| 根目录CLAUDE.md | 50-150行 | 200 |
| 子目录CLAUDE.md | 15-50行 | 80 |
| 规则主题文件 | 20-80行 | 120 |
What Belongs Where
内容存放规则
Root CLAUDE.md
根目录CLAUDE.md
- Project name, purpose, owner
- Tech stack summary
- Build/deploy/test commands (copy-paste ready)
- Directory structure overview
- Critical "never do X" rules
- Key integrations and secrets locations
- 项目名称、用途、负责人
- 技术栈摘要
- 构建/部署/测试命令(可直接复制粘贴使用)
- 目录结构概述
- 关键的“禁止操作X”规则
- 核心集成与密钥位置
Sub-directory CLAUDE.md
子目录CLAUDE.md
- External service integrations for that component
- Non-obvious configuration specific to this area
- Directory-specific commands
- Gotchas when working in this directory
Don't create when: parent covers it, directory is self-explanatory, content would be under 10 lines.
- 该组件对应的外部服务集成内容
- 特定于该区域的非显性配置
- 目录专属命令
- 在该目录工作时的注意事项
无需创建的情况:父目录已覆盖相关内容、目录内容一目了然、内容不足10行。
.claude/rules/ topic files
.claude/rules/主题文件
- Correction rules bridging training cutoff (e.g. API changes, deprecated patterns)
- Coding patterns and standards
- Platform-specific formatting rules
- Error prevention patterns
- 弥补训练截止日期后变化的修正规则(如API变更、已废弃模式)
- 编码模式与标准
- 平台特定格式规则
- 错误预防模式
What to delete
需删除的内容
- Content Claude already knows from training
- Verbose explanations of standard frameworks
- Changelogs or version history (use git)
- Duplicated content from parent CLAUDE.md files
- "TODO" items that were never completed
- Generic advice not specific to the project
- Claude已通过训练掌握的内容
- 对标准框架的冗长解释
- 变更日志或版本历史(使用git管理)
- 与父目录CLAUDE.md重复的内容
- 从未完成的“TODO”项
- 非项目专属的通用建议
Project Type Detection
项目类型检测
The audit script detects project type from file presence and suggests appropriate documentation:
| Indicator | Type | Suggested Docs |
|---|---|---|
| Cloudflare Worker | ARCHITECTURE.md |
| Vite/React | ARCHITECTURE.md |
| Next.js | ARCHITECTURE.md |
MCP patterns in | MCP Server | ARCHITECTURE.md, API_ENDPOINTS.md |
| API Project | API_ENDPOINTS.md, DATABASE_SCHEMA.md |
| Drizzle/Prisma config | Database | DATABASE_SCHEMA.md |
All projects get CLAUDE.md. Additional docs only when the project type warrants them. See references/project-types.md for full detection heuristics and doc templates.
审计脚本通过文件存在情况检测项目类型,并推荐合适的文档:
| 识别标识 | 项目类型 | 推荐文档 |
|---|---|---|
| Cloudflare Worker | ARCHITECTURE.md |
| Vite/React | ARCHITECTURE.md |
| Next.js | ARCHITECTURE.md |
| MCP Server | ARCHITECTURE.md、API_ENDPOINTS.md |
| API项目 | API_ENDPOINTS.md、DATABASE_SCHEMA.md |
| 存在Drizzle/Prisma配置 | 数据库项目 | DATABASE_SCHEMA.md |
所有项目都需要CLAUDE.md。仅当项目类型有需求时才添加额外文档。完整的检测规则与文档模板请查看references/project-types.md。
Autonomy Rules
自主操作规则
- Just do it: Run audit, detect project type, identify gaps, draft changes
- Brief confirmation: Apply changes (single batch yes/no, not item-by-item)
- Ask first: Delete existing content, major restructures (moving 50+ lines), create new project docs from scratch where there's ambiguity about content
- 直接执行:运行审计、检测项目类型、识别缺口、草拟修改内容
- 简短确认:应用修改内容(单次批量确认是/否,无需逐项确认)
- 先询问再操作:删除现有内容、大规模重构(移动50行以上内容)、在内容存在歧义时从零创建新的项目文档
Quality Scoring
质量评分
The audit script scores each CLAUDE.md on 6 criteria (100 points):
| Criterion | Points | What it measures |
|---|---|---|
| Commands/Workflows | 20 | Build, test, deploy documented |
| Architecture Clarity | 20 | Structure, relationships, entry points |
| Non-Obvious Patterns | 15 | Gotchas, quirks, warnings |
| Conciseness | 15 | Dense content, no filler |
| Currency | 15 | References valid, commands work |
| Actionability | 15 | Copy-paste ready, real paths |
See references/quality-criteria.md for the full rubric.
审计脚本从6个维度对每个CLAUDE.md进行评分(总分100分):
| 评分维度 | 分值 | 衡量内容 |
|---|---|---|
| 命令/工作流 | 20 | 构建、测试、部署流程是否已文档化 |
| 架构清晰度 | 20 | 结构、关联关系、入口点是否清晰 |
| 非显性模式 | 15 | 是否记录陷阱、特殊点与警告 |
| 简洁性 | 15 | 内容是否精炼、无冗余 |
| 时效性 | 15 | 引用是否有效、命令是否可正常执行 |
| 可操作性 | 15 | 是否可直接复制粘贴、路径是否真实有效 |
完整评分标准请查看references/quality-criteria.md。
Reference Files
参考文件
| When | Read |
|---|---|
| Scoring CLAUDE.md quality | references/quality-criteria.md |
| Detecting project type and expected docs | references/project-types.md |
| Creating new CLAUDE.md or rules files | references/templates.md |
| 使用场景 | 参考文件 |
|---|---|
| 对CLAUDE.md进行质量评分 | references/quality-criteria.md |
| 检测项目类型与所需文档 | references/project-types.md |
| 创建新的CLAUDE.md或规则文件 | references/templates.md |
Scripts
脚本说明
- — Scan all three layers, score quality, detect project type, flag issues
scripts/audit_memory.py- — human-readable report
python3 audit_memory.py [repo-path] - — structured JSON output
python3 audit_memory.py [repo-path] --json
- — 扫描三个内存层级、进行质量评分、检测项目类型、标记问题
scripts/audit_memory.py- — 生成人类可读的报告
python3 audit_memory.py [repo-path] - — 生成结构化JSON输出
python3 audit_memory.py [repo-path] --json