prune-agent-memory
关于
This skill provides a systematic method to audit, classify, and selectively delete an agent's stored memories to maintain quality and relevance. It features staleness detection, fidelity checks, and a decision tree for deletion, including safeguards like counter-memory inoculation. Use it for periodic maintenance, when memory becomes large/uncurated, or after significant project shifts degrade retrieval quality.
快速安装
Claude Code
推荐npx skills add pjt222/agent-almanac -a claude-code/plugin add https://github.com/pjt222/agent-almanacgit clone https://github.com/pjt222/agent-almanac.git ~/.claude/skills/prune-agent-memory在 Claude Code 中复制并粘贴此命令以安装该技能
技能文档
修主憶
審、分、擇忘所存憶。憶為基。忘為策。此技定策。
manage-memory 聚於組與長憶(何留、何構),此技聚反:何棄、如何察衰、如何使忘為意非偶。二技互補、定期維時當共用。
用
- 憶檔大而無人察相關→用
- 案態大變(重構、庫易名、碑畢)、憶恐引舊境→用
- 取質衰——憶生噪非號→用
- 一陣動生多憶項而無理→用
- 排定維任(如每 10-20 會或案碑時)→用
- 多憶項涵同題含小異(重複漂)→用
- 接新合作前承憶境→用
- 棄策或式而觸件仍存後——以防自源沿同徑重生、非僅恃除→用
入
- 必:憶目徑(常
~/.claude/projects/<project-path>/memory/) - 可:留策覆(如「皆留布署」「激修除錯注」)
- 可:末察以來知案變(如「庫易名」「自 Jest 遷至 Vitest」)
- 可:前修審跡為勢析
行
一:枚並分憶
讀諸憶檔、各項按四維分。
# Inventory the memory directory
ls -la <memory-dir>/
wc -l <memory-dir>/*.md
# Count total entries (approximate by counting top-level bullets and headers)
grep -c "^- \|^## " <memory-dir>/MEMORY.md
for f in <memory-dir>/*.md; do echo "$f: $(grep -c '^- \|^## ' "$f") entries"; done
各憶項分為下型之一:
| Type | Description | Example | Default retention |
|---|---|---|---|
| Project | Facts about project structure, architecture, conventions | "skills/ has 310 SKILL.md files across 55 domains" | Keep until verified stale |
| Decision | Choices made and their rationale | "Chose hub-and-spoke over sequential for review teams because..." | Keep indefinitely |
| Pattern | Debugging solutions, workflow insights, recurring behaviors | "Exit code 5 means quoting error — use temp files" | Keep until superseded |
| Reference | Links, version numbers, external resources | "mcptools docs: https://..." | Keep until verified stale |
| Feedback | User preferences, corrections, style guidance | "User prefers kebab-case for file names" | Keep indefinitely |
| Ephemeral | Session-specific context that leaked into persistent memory | "Currently working on issue #42" | Prune immediately |
各項亦注:
- 齡:何時書或末更?
- 取頻:此項於近會用乎?(按題對近工之關估)
得:完錄含每憶項按型分、含齡與取頻估。Ephemeral 項已標即除。
敗:憶檔過大或無構不可逐項分→於段級行。分全段非各項。標為覆、非粒。
二:察舊
對今案態比憶述。舊為憶衰之最常式。
察下舊式:
- 數漂:檔、技、主、域、團數變
- 徑漂:移、易名、除之檔、目、URL
- 態漂:態(解事、畢碑、合 PR)仍述為開或進中
- 決反:後覆而原由仍於憶
- 具/版漂:版、API 簽、具名變(如包易名)
# Spot-check counts against source of truth
grep -oP '\d+ skills' <memory-dir>/MEMORY.md
grep -c "^ - id:" skills/_registry.yml
# Check for references to files that no longer exist
grep -oP '`[^`]+\.(md|yml|R|js|ts)`' <memory-dir>/MEMORY.md | sort -u | while read f; do
path="${f//\`/}"
[ ! -f "$path" ] && echo "STALE: $path referenced but not found"
done
# Check for references to old names/paths
grep -i "old-name\|previous-name\|renamed-from" <memory-dir>/*.md
各舊項標其舊型與今正值。
得:舊項列含特變據。各舊項薦行:更(若知正值)、驗(若不確)、修(若全項已廢)。
敗:因外態(API、三方文、布署態)而不能驗→標為 unverifiable 勿假其正。未驗項為修候若無活用。
三:行誠檢
試憶取時否仍生用境。此最難——主不能驗己縮憶之誠——需外錨。
誠檢法:
-
往返驗:讀憶項、後察其述之實案態。憶引至正檔、正式、正結乎?
-
縮失察:憶撮對原源比。50 行討縮為 2 行憶、縮保行洞乎抑只題標?
# Find the source that a memory entry was derived from # (git log, old PRs, original files) git log --oneline --all --grep="<keyword from memory entry>" | head -5 -
矛盾掃:搜憶相矛或矛 CLAUDE.md/案文。
# Look for potential contradictions in counts grep -n "total" <memory-dir>/MEMORY.md grep -n "total" CLAUDE.md # Compare the values — they should agree -
用試:各憶項問:「此項除、後 5 會何錯?」答「恐無」→項誠值低即正。
得:各憶項今有誠評:高(驗準用)、中(恐準偶用)、低(未驗或罕用)、敗(驗誤或矛)。
敗:諸項誠檢不決→聚最高效項。誤憶於案架險於誤憶於除錯。骨級實察先於肉級細。
四:施擇除
用此決樹按序定何修:
Pruning Decision Tree (apply in order):
1. EPHEMERAL entries (Step 1 classification)
→ Delete immediately. These should never have been persisted.
2. FAILED fidelity entries (Step 3)
→ Delete immediately. Inaccurate memories are worse than no memories.
3. DUPLICATES
→ Keep the most complete/accurate version, delete others.
→ If duplicates span MEMORY.md and a topic file, keep the topic file version.
4. STALE entries with known corrections (Step 2)
→ UPDATE if the entry is otherwise useful (change the stale value to current).
→ DELETE if the entire entry is obsolete (the topic no longer matters).
5. LOW fidelity, low access frequency entries
→ Delete. These are taking space without providing value.
6. MEDIUM fidelity entries about completed/closed work
→ Archive or delete. Past sprint details, resolved incidents, merged PRs.
→ Exception: keep if the resolution contains a reusable pattern.
7. REFERENCE entries with freely available sources
→ Delete if the reference is a Google search away.
→ Keep if the reference is hard to find or has project-specific context.
各除、記項、其分、除由(用於步八)。
施此樹之 DELETE 前、察項否當受逆種(步五)。敗策、棄徑、險式為「除兼種」之候、非「唯除」。
得:明列除項、更項、留項——各含記由。留/除比依憶健;善養者修 5-10%、忽者修 30-50%。
敗:諸項決樹模→緊濾:「今知所知、今書此項乎?」否→修候。傾修——重學實易於繞誤憶。
五:種逆以絕重生
某棄結不可徑除。除孤敗於生憶之件未滅——系自同入沿同推徑重生所除之憶。為此例、書一逆憶以絕重生、與除並行(或代之)。
決則——唯除、除兼種、唯種:
| 憶類 | 行 | 由 |
|---|---|---|
| 舊實、過指、廢境 | 唯除 | 唯取清;重生無行險 |
| 敗策、險式、棄徑而觸件仍存 | 除兼種 | 推徑將自重生其結 |
| 後覆之決而原由猶要 | 唯種 | 留原項;加 SUPERSEDED 逆憶指其 |
SUPERSEDED 錄式(auto-memory frontmatter;構從他憶系而適):
---
name: superseded-<short-id>
description: Counter-memory preventing re-derivation of <pattern>
type: superseded
---
SUPERSEDED <YYYY-MM-DD>
Pattern: <what was tried — describe the conclusion or strategy>
Period: <start> to <end>
Evidence: <what happened — concrete data, not narrative>
Abandonment reason: <specific cause; not "did not work">
Do not re-derive from: <signal types or input patterns that previously led here>
Supersedes: <path to original memory if delete + inoculate, or N/A>
SUPERSEDED 錄各為己檔置於憶目(如 superseded_strategy_X.md)使取時與活憶並現。逆憶乃所行之變機:相號至、SUPERSEDED 浮、絕重生之徑。
何時不種:
- 瑣舊實(重生無行險)
- 原觸件已滅之憶(易名畢、依棄、團散)
- 新據下重決為宜者(策恐於來態可成、當再評)
種衛:
Pattern與Do not re-derive from宜特。模逆憶(如「勿試繁解」)為噪- SUPERSEDED 項記日。老種於底件變後恐自舊——入次修週為察候
- 一棄式一 SUPERSEDED。勿鏈諸棄於一逆憶;取受損
- 修誌錄除時、亦錄並 SUPERSEDED 檔徑、使審跡備二半
得:步四之除候涉棄策險式者、各於除前生對應 SUPERSEDED 逆憶檔。修誌錄除與種。活憶猶瘦而重生徑絕。
敗:項當種否未定→默種。冗 SUPERSEDED 之費少;重生惡式之費厚。SUPERSEDED 列大至自為噪→是上層件生諸棄之兆——修在入層、非憶層。
六:施前濾
定「何不存」則防未來憶污。察現憶為書時當濾之式。
永不為持憶之式:
| Pattern | Why | Example |
|---|---|---|
| Session-specific task state | Stale by next session | "Currently debugging issue #42" |
| Intermediate reasoning | Not a conclusion | "Tried approach A, didn't work because..." |
| Debug output / stack traces | Ephemeral diagnostic data | "Error was: TypeError at line 234..." |
| Exact command sequences | Brittle, version-dependent | "Run npm install [email protected] && ..." |
| Emotional/tonal notes | Not actionable | "User seemed frustrated" |
| Duplicates of CLAUDE.md | Already in system prompt | "Project uses renv for dependencies" |
| Unverified single observations | May be wrong | "I think the API rate limit is 100/min" |
現憶有此式者→加於步四除列。
濾則記於 MEMORY.md 或 retention-policy.md 題檔以使未會於書新憶前察。
得:憶目記之前濾則。現項合此式者標除。
敗:記濾則似早(憶小、污少)→略記而仍施濾以捉現違。則可後形於憶目熟時。
七:書審跡
各除錄使忘可察。立或更修誌。
<!-- In <memory-dir>/pruning-log.md or appended to MEMORY.md -->
## Pruning Log
### YYYY-MM-DD Audit
- **Entries audited**: N
- **Entries pruned**: M (X%)
- **Entries updated**: K
- **Staleness found**: [list of stale patterns detected]
- **Fidelity failures**: [list of entries that failed verification]
#### Deletions
| Entry (summary) | Type | Reason |
|-----------------|------|--------|
| "Currently working on issue #42" | Ephemeral | Session-specific, stale |
| "skills/ has 280 SKILL.md files" | Project | Count drift: actual is 310 |
| "Use acquaint::mcp_session()" | Pattern | Package renamed to mcptools |
修誌簡。為責、非考古。誌大→撮老項:「2025:3 審、47 項修(多數漂與 ephemeral 漏)」。
得:時印之修誌項記何除何由。誌存於憶目與憶共。
敗:分檔似過(唯 1-2 項修)→於 MEMORY.md 加短注:<!-- Last pruned: YYYY-MM-DD, removed 2 stale entries -->。任記優於默除。
八:定護憶
某憶項當免修不論齡、頻、誠分。為失即需大力重構之不可代境。
護憶則:
| Category | Examples | Why protected |
|---|---|---|
| Architecture decisions | "Chose flat skill directory over nested" | Rationale is lost if re-derived later |
| User identity preferences | "Always use kebab-case," "Never auto-commit" | Explicit user intent, not inferrable |
| Security audit results | "Last audit: 2025-12-13 — PASSED" | Compliance evidence with timestamps |
| Rename/migration records | "Repo renamed: X to Y on date Z" | Cross-reference integrity depends on this |
標法:護項以 <!-- PROTECTED --> 內標或於修誌持 protected 列。步四決樹必先察護態乃施除則。
解護:修護項→先明除標、於修誌記由。二步防偶除高值憶。
得:護項過諸修。修誌記任護加除。
敗:護集過大(>總 30%)→察則——護為不可代境、非「重」項。重而可重立之實當受常修。
九:修後重合
除後餘憶恐碎——交引指除項、題檔失連、MEMORY.md 有缺。重合復構整。
重合清單:
- 解破引:掃餘項為連除容。除或轉引
- 合相片:修留二項涵同題之疊面→合為一連項
- 更題檔構:題檔失 >50% 容→計餘折回 MEMORY.md 而除題檔
- 分冷憶:察過修而近未取項:
- 冷由不用:題合活案標而生其之段已過。留——其段重時恐重相關(如活開時 CRAN 提注)
- 冷由不關:題本邊——一時驗、旁查、覆徑。次修週標除
- 驗 MEMORY.md 連:上下讀 MEMORY.md。當述案連故事、非為亂實集
得:修後憶構固——無孤引、無冗片、無不連題檔。冷項分為未來修決。
敗:重合顯修過激(要境失)→察修誌、自審跡重立。此為審跡所以存。
十:自憶漂復
憶漂於存實默誤——非始誤、實底變而憶未更。漂復試就地修憶非修除。
漂察觸:
- 憶述矛今具出或檔容
- 憶中數或版號不合錄或鎖檔
- 憶中徑返「檔未見」
- 依憶引易名或棄包
復程:
- 識漂:憶述對今地實(git log、錄、實檔)比
- 評可復:今案態可定正值乎?
- 是→就地更憶含今值與
[corrected YYYY-MM-DD]注 - 否→標
unverifiable而標修
- 是→就地更憶含今值與
- 追因:為漸漂(數緩異)或離散事(易名、遷)?離散事常影多項——掃同伴
- 防再:漂影常變值(數、版)→計憶當追值乎抑引源實:「見 skills/_registry.yml 為今數」非「317 技」
得:漂憶可則就地修保境。不可修者標修。防則減未來漂。
敗:漂廣(>20%)→憶恐需全重立非漸修。則檔當前憶目、自始、擇重入過驗者。
驗
- 諸憶檔錄、項按型分
- 對今案態行舊察
- 至少一誠檢法施(往返、縮失、矛掃、用試)
- 除決循決樹序
- 無項無記由而除
- 各除候皆察種否;存重生險者立 SUPERSEDED 逆憶
- 前濾則記或施
- 修誌記何除、何時、何由——含種項對應 SUPERSEDED 檔徑
- 修後 MEMORY.md 仍 <200 行
- 餘憶準(對案態點察)
- 修 MEMORY.md 引未生孤題檔
- 護項標而過諸修
- 修後重合解破交引並合片
- 冷項分為不用對不關為未來修決
- 漂項可則就地修、非僅除
忌
- 除敗策而不種:棄徑之憶除、而生其之件仍存。系自同入沿同徑重生同結。除為虛行。觸件存→用步五逆種
- 不驗而修:因「似舊」除而不察其準否與用否。齡單非除則——某最寶憶為老架決仍真
- 自驗誠:主讀己縮憶結「是、似正」非誠檢。誠需外錨:案檔、git 史、錄數、實具出。無錨則察一致非準
- 激修無審跡:除而不錄何除。未會需修除實時、審跡述何發、可含足境重立憶
- 修決為憶:勿書「我決修 X 由 Y」為常憶項。此唯入修誌。憶管之憶為元污
- 忽前濾:修現項而不立則防同式再。無濾則後 10 會將重立汝甫除之同 ephemeral
- 諸型同處:決憶與饋憶幾不當修——其表用意與由。案與引為主修標、其追變態
- 混縮為壞:撮繁題為一行之憶為縮非壞。唯標為誠敗於縮失行洞、非但細
- 過釘:標多項為護敗修旨。>30% 護則則寬。護不可代境、非僅重實
- 重合圈:重合中合片可立新項其需次週修。少合——僅合明涵同題者。修中勿合新洞
參
manage-memory— 組與長憶之補技;共用為全憶維meditate— 清接地可顯何憶生噪rest— 有時最佳憶維為不維assess-context— 推境健察、憶質直影
GitHub 仓库
相关推荐技能
llamaguard
其他LlamaGuard是Meta推出的7-8B参数内容审核模型,专门用于过滤LLM的输入和输出内容。它能检测六大安全风险类别(暴力/仇恨、性内容、武器、违禁品、自残、犯罪计划),准确率达94-95%。开发者可通过HuggingFace、vLLM或Sagemaker快速部署,并能与NeMo Guardrails集成实现自动化安全防护。
cost-optimization
其他这个Claude Skill帮助开发者优化云成本,通过资源调整、标记策略和预留实例来降低AWS、Azure和GCP的开支。它适用于减少云支出、分析基础设施成本或实施成本治理策略的场景。关键功能包括提供成本可视化、资源规模调整指导和定价模型优化建议。
quantizing-models-bitsandbytes
其他这个Skill使用bitsandbytes库量化大语言模型,能在GPU内存有限时通过8位或4位量化减少50-75%内存占用,同时保持精度损失最小。它支持INT8、NF4、FP4等多种量化格式,可与HuggingFace Transformers无缝集成,适用于需要部署更大模型或加速推理的场景。还提供QLoRA训练和8位优化器支持,让开发者能轻松实现高效模型压缩。
dispatching-parallel-agents
其他该Skill用于并行处理3个以上无依赖关系的独立故障,可为每个问题域分派专属Claude代理同时执行调查修复。它通过并发处理多个独立问题显著提升故障排查效率,特别适用于测试文件、子系统等无共享状态的场景。
