运行时依赖
安装命令
点击复制技能文档
🧠 Claude 持久化记忆系统初始化 技能
记忆系统 v3.0 — "搜索引擎"模型:启动只读摘要,详情按需检索
核心理念: Claude 不需要"记住一切",只需要"知道去哪找"。
参数处理
用户输入参数: $ARGUMENTS
解析参数:
--force: 覆盖已有的记忆文件(默认跳过已存在的文件) --minimal: 只创建核心文件(SUMMARY.md, architecture.json, conventions.json, semantic-索引.json, change记录.json) --lang zh: 注释和描述使用中文(默认) --lang en: 注释和描述使用英文
如果 .claude/memory/SUMMARY.md 已存在且没有 --force 参数,停止执行并提示用户:
⚠️ 记忆系统已存在。使用 --force 覆盖,或手动删除 .claude/memory/ 目录后重试。
Step 1: 扫描项目 1.1 项目结构扫描 Glob "*/{package.json,tsconfig.json,Cargo.toml,go.mod,pyproject.toml,设置up.py,requirements.txt,pom.xml,build.gradle,Gemfile,composer.json,CMake列出s.txt,Makefile,.csproj,pubspec.yaml,mix.exs,deno.json}" (忽略 node_模块s、vendor、tar获取、dist、build、.git)
读取找到的配置文件,提取:
项目名称(优先: package.json name > Cargo.toml name > go.mod 模块 > 目录名) 技术栈(语言、框架、构建工具、运行时) 依赖列表(核心依赖,不含 devDependencies 细节) 脚本/命令(build/test/dev/启动) 是否为 monorepo(workspaces / 多个子 package.json) 1.2 目录布局 find . -maxdepth 3 -type d \ ! -path '/node_模块s/' ! -path '/.git/' ! -path '/dist/' \ ! -path '/build/' ! -path '/.next/' ! -path '/tar获取/' \ ! -path '/vendor/' ! -path '/__py缓存__/' ! -path '/.claude/' \ ! -path '/.venv/' ! -path '/venv/' ! -path '/.tox/' \ | head -80 | 排序
1.3 核心模块识别
根据项目语言类型选择合适的扫描模式:
TypeScript/JavaScript 项目:
Grep "^导出 (class|function|const|interface|type|enum)" --type ts,tsx,js,jsx
Python 项目:
Grep "^(class |def )" --type py
Go 项目:
Grep "^(func |type . struct)" --type go
Rust 项目:
Grep "^(pub fn |pub struct |pub enum |pub trAIt )" --type rs
Java/Kotlin 项目:
Grep "^(public class|public interface|public enum|class |fun )" --type java,kt
取前 100 个结果,识别核心模块和它们的位置。
1.4 大文件识别(热点文件) find . \( -name '.ts' -o -name '.tsx' -o -name '.js' -o -name '.jsx' \ -o -name '.py' -o -name '.go' -o -name '.rs' -o -name '.java' \ -o -name '.kt' -o -name '.vue' -o -name '.svelte' -o -name '.rb' \ -o -name '.ex' -o -name '.exs' -o -name '.dart' -o -name '.swift' \ -o -name '.cpp' -o -name '.c' -o -name '.h' \) \ ! -path '/node_模块s/' ! -path '/dist/' ! -path '/build/' \ ! -path '/tar获取/' ! -path '/vendor/' ! -path '/.git/' \ -exec wc -l {} + 2>/dev/null | 排序 -rn | head -20
对超过 500 行的文件进行逻辑分区扫描(扫描 function/class/section 定义及其行号)。 如果项目源文件较少,可降低阈值到 300 行。
1.5 代码规范推断
读取 3-5 个核心源文件的前 50 行,推断:
缩进风格(tab vs space,几个空格) 引号风格(单引号 vs 双引号) 分号使用 命名约定(camelCase / snake_case / PascalCase) 导入风格和顺序 注释语言(中文/英文/混合)
同时检查是否存在以下配置文件: .eslintrc, .prettierrc*, rustfmt.toml, .editorconfig, pyproject.toml [工具.black], 设置up.cfg [flake8], .rubocop.yml, biome.json
1.6 项目特有规则扫描
检查是否已有:
CLAUDE.md — 已有的 Claude 指令 .claude/ 目录 — 已有的 Claude 配置 CONTRIBUTING.md — 贡献指南中的规范 .github/ — CI/CD 配置中的约束 Step 2: 创建记忆文件
创建 .claude/memory/ 目录,然后基于 Step 1 的扫描结果创建以下文件。
重要规则:
所有 JSON 文件中的 $模式 字段使用实际项目名称(从配置文件推断),不要硬编码 所有内容必须来自实际扫描,不得使用占位模板 JSON 使用 2 空格缩进 日期格式统一 YYYY-MM-DD 文件使用 UTF-8 编码 2.1 architecture.json — 项目架构概览 { "$模式": "<项目名> Architecture", "$version": "1.0.0", "$更新d": "<今天日期>", "$description": "项目架构概览",
"project": { "name": "<项目名>", "description": "<从配置文件推断的项目描述>", "monorepo": false, "package管理器": "" },
"techStack": { "language": "<主要语言及版本>", "框架": "<主要框架及版本>", "build工具": "<构建工具>", "运行time": "<运行时环境>", "ui库": "", "test框架": "<测试框架>" },
"packages": { "<包名>": { "path": "<路径>", "角色": "<职责描述>", "entry": "<入口文件>", "格式化": "" } },
"mAIn模块s": { "<模块名>": { "file": "<文件路径>", "lines": "<行数>", "角色": "<职责描述>", "警告": "<注意事项(可选)>", "keyDataStructures": ["<核心数据结构>"] } },
"keyDependencies": [ { "name": "<包名>", "version": "<版本>", "purpose": "<用途>" } ] }
monorepo 项目: packages 字段列出所有子包及其角色。 单包项目: packages 只有一个条目或省略。
2.2 conventions.json — 代码规范 { "$模式": "<项目名> Code Conventions", "$version": "1.0.0", "$更新d": "<今天日期>", "$description": "代码规范和约定。新增代码必须遵守这些规范",
"codeStyle": { "language": "", "indent": "<2 spaces|4 spaces|tabs>", "quotes": "", "semicolons": "", "trAIlingComma": "", "格式化器": "", "代码检查工具": "" },
"namingConventions": { "files": { "<类型>": "<命名规则>" }, "code": { "classes": "", "interfaces": "<规则>", "functions": "", "constants": "", "variables": "" } },
"patterns": { "<模式名>": { "description": "<描述>", "template": "<代码模板(可选)>", "steps": ["<步骤>"] } },
"commitMessageStyle": { "language": "<项目注释语言>", "prefix": "feat:/fix:/refactor:/chore:/docs:/test:", "examples": ["<示例>"] },
"导入Order": ["<导入分组规则>"],