Communitygithub.com

config-gc

Claude Code 設定的垃圾回收機制。定期掃描 ~/.claude(技能、記憶、鉤子、權限、MCP 伺服器、快取),找出冗餘、過時、孤立或低價值的項目,並引導使用者逐一確認刪除。在使用者要求時啟用。

config-gc 是什麼?

config-gc 是一項用於 Claude Code 設定的垃圾回收(GC)技能,靈感來自運行時的垃圾回收概念。它會定期掃描 ~/.claude 目錄下的技能、記憶檔案、鉤子、權限、MCP 伺服器、排程提醒、專案歷史和運行時快取等八個通道,找出冗餘、過時、孤立或低價值的項目。不同於自動化 GC,本技能強制要求人機迴圈(human-in-the-loop):每個候選項目都需使用者以 [y/n/skip] 逐一確認,絕不自動刪除。支援所有 Claude Code 運行的平台(Linux、macOS、Windows),並遵循軟刪除優先(例如重新命名為 .disabled)、保留操作日誌與還原路徑等設計原則。 此技能特別適合在安裝大量技能包後、使用者抱怨啟動變慢或設定過於雜亂時使用。它與 skill-stocktake(技能品質審計)和 workspace-surface-audit(建議新增技能)形成互補,共同維護 Claude Code 設定的健康生命週期。執行結果會記錄在 ~/.claude/gc_log.md 中,包含時間戳、處理的項目與還原方法。

相容平台✓Claude Code~Codex CLI~Cursor
npx skills add https://github.com/affaan-m/everything-claude-code/tree/main/skills/config-gc

在你喜歡的 AI 中提問

開啟一個已預先載入此 Agent Skill 的新對話。

說明文件

Config GC — Claude Code 設定的垃圾回收機制

借鑑運行時垃圾回收的概念:定期掃描不再被參照、冗餘、過期或低價值的物件,並回收空間。關鍵差異在於:此處的回收需要人為介入。絕不自主刪除。

何時啟用

  • 使用者要求清理、審計或精簡其 Claude Code 設定
  • 使用者抱怨技能太多、鉤子太雜或工作階段啟動緩慢
  • 每月/定期設定審查時間到
  • 安裝大型技能包(例如本倉庫)後,用以調和與現有設定的重疊

請勿在以下情況啟用:清理專案原始碼(那是重構)、清除聊天記錄或解除安裝 Claude Code 本身。

設計哲學

  1. 僅附加的設定會洩漏。 技能、記憶檔案、鉤子和權限條目只會不斷增加。沒有定期審查,它們會默默腐化。
  2. 定期審計優於一次性清理。 大約每 30 天掃描一次,每次提出少量候選項目。
  3. 各通道策略不同。 每種累積類型(技能、鉤子、權限……)都有其自己的過時訊號 — 不要對所有類型套用同一規則。
  4. 先軟刪除。 重新命名為 .disabled > 移至 ~/.claude/_gc_trash/ > 真正刪除。始終保留還原路徑。
  5. 強制人機迴圈。 每個候選項目都有自己的 [y/n/skip] 確認。沒有「全部同意」的捷徑。
  6. 保留日誌。 每次 GC 執行都會附加到 ~/.claude/gc_log.md:記錄了什麼、原因以及如何還原。

掃描通道

#通道路徑過時/冗餘訊號
1技能~/.claude/skills/*/名稱高度重疊;近期對話記錄中從未被觸發;領域與使用者實際工作不符;SKILL.md 損壞或為空
2記憶~/.claude/**/memory/*.md 及其索引同一主題有多個索引條目;內容與較新條目矛盾;日期已過期;索引中缺少孤立檔案;應合併的少於 100 字的片段
3鉤子~/.claude/hooks/ + 設定存在於磁碟上但未被任何鉤子設定參照的腳本;已被重寫取代的舊版本
4權限settings.json / settings.local.json 中的 permissions.allow重複條目;已包含在萬用字元中的特定條目(例如已允許 Bash(*) 時仍有 Bash(git push));過去實驗的一次性授權
5MCP 伺服器~/.claude.json 或專案 .mcp.json無法連線的伺服器;功能重複的伺服器;長期未使用的伺服器
6排程提醒/任務使用者存放它們的任何位置超過 30 天的已觸發一次性提醒;目標腳本已不存在的任務
7專案歷史~/.claude/projects/*/過時的手動交接快照;已被較新狀態取代的工作階段記錄
8運行時快取cache/、file-history/、logs/、shell-snapshots/按大小和修改時間排序;建議超過 30 天且體積較大的項目

工作流程

  1. 掃描所有通道(或使用者指定的子集)。收集候選項目,包含:路徑、通道、觸發訊號、大小、最後修改時間。
  2. 依信心度排序(損壞/孤立 = 高;僅過時 = 低)並以編號表格呈現。每次執行最多約 20 個候選項目 — GC 是週期性的,並非窮舉。
  3. 逐一確認。 對每個候選項目顯示證據,然後詢問 [y/n/skip]。使用者可隨時停止。
  4. 軟刪除已確認項目:技能/鉤子優先使用 .disabled 重新命名,檔案則優先移至 _gc_trash/<日期>/。權限條目位於 JSON 中(無法加註解):先備份設定檔,將每個已移除的條目逐字記錄在 gc_log.md 中,然後使用 jq 從 allow 陣列中移除。僅在使用者明確要求時才永久刪除。
  5. 將執行記錄到 ~/.claude/gc_log.md:時間戳、處理的項目、還原說明。
  6. 報告:回收的空間大小、仍健康的通道、建議的下次審查日期。

掃描指令範例

孤立的鉤子腳本(通道 3)— 存在於磁碟上但未被任何鉤子設定參照的腳本:

for f in ~/.claude/hooks/*; do
  name=$(basename "$f")
  grep -rq "$name" ~/.claude/settings.json ~/.claude/settings.local.json 2>/dev/null \
    || echo "孤立: $f"
done

冗餘的權限條目(通道 4)— 重複項目,以及被萬用字元遮蔽的特定授權:

jq -r '.permissions.allow[]' ~/.claude/settings.local.json | sort | uniq -d
if jq -e '.permissions.allow | index("Bash(*)")' ~/.claude/settings.local.json >/dev/null; then
  jq -r '.permissions.allow[]' ~/.claude/settings.local.json \
    | grep '^Bash(' | grep -vF 'Bash(*)'
fi

最大且過時的快取(通道 8)— 使用 du -k (而非僅 GNU 的 find -printf),以便在 macOS/BSD 上也能運作:

find ~/.claude/file-history ~/.claude/shell-snapshots -type f -mtime +30 \
  -exec du -k {} + 2>/dev/null | sort -rn | head -20

軟刪除並保留還原路徑(一次記錄日期,避免日誌與目錄不一致):

gc_date=$(date +%Y-%m-%d)
mkdir -p ~/.claude/_gc_trash/$gc_date
mv ~/.claude/skills/dead-skill ~/.claude/_gc_trash/$gc_date/
echo "$(date -Iseconds) 已移動 skills/dead-skill -> _gc_trash/$gc_date/ (還原: mv 回來)" >> ~/.claude/gc_log.md

移除已確認冗餘的權限條目(JSON 無法加註解 — 先備份、記錄、再編輯):

cp ~/.claude/settings.local.json ~/.claude/settings.local.json.bak
echo "$(date -Iseconds) 已移除權限條目: Bash(git push) (還原: 從 .bak 還原或重新加入)" >> ~/.claude/gc_log.md
jq '.permissions.allow -= ["Bash(git push)"]' ~/.claude/settings.local.json.bak \
  > ~/.claude/settings.local.json

反模式

  • 批量批准。 詢問「刪除全部 15 個?[y/n]」違背了設計理念。一個項目,一個決定。
  • 第一次就永久刪除。 如果沒有 _gc_trash/ 副本或 .disabled 重新命名,你就做錯了。
  • 將「過時」等同於「死亡」。 一個技能 60 天未觸發可能是季節性的(稅季、季度審查)。年齡是訊號,不是判決 — 這就是為什麼需要人為確認。
  • 透過截斷來清理記憶。 合併兩個矛盾的記憶檔案需要閱讀兩者並保留較新的事實,而不是刪除較長的那個。
  • 碰觸 ~/.claude(或專案的 .claude/)以外的任何東西。 Config GC 絕不進入原始碼樹。

最佳實踐

  • 在大量新增後執行,而不僅是按時程:安裝一個 50 技能的套件正是與現有技能產生重疊的時候。
  • 當兩個技能重疊時,優先停用觸發描述較弱的那個 — 它很可能從未被觸發過。
  • 權限清理是每分鐘花費最有價值的通道:冗餘的 allow 條目會使安全審查更加困難。
  • 永久保留 gc_log.md。它很小,而且「我何時停用了那個鉤子以及為什麼」這個問題出現的頻率比你想像的更高。

相關技能

  • skill-stocktake — 審計技能品質;config-gc 審計技能是否存在。在 GC 留下的技能上執行 stocktake。
  • workspace-surface-audit — 其互補對應:建議安裝什麼。config-gc 是同一個生命週期的減法部分。
  • configure-ecc — 用它安裝技能後,執行 config-gc 以調和與現有設定的重疊。
  • continuous-learning — 產生此技能稍後會審計的記憶檔案。
  • security-review — 與權限通道搭配良好。

Individual skills in this repo

This repo contains 20 individual skills — each has its own dedicated page.

accessibility

Design, implement, and audit inclusive digital products using WCAG 2.2 Level AA. Use when building or auditing UI that must meet WCAG 2.2 Level AA, or when reviewing a change for keyboard, contrast, or screen-reader support.

affaan-m/claude-api

Anthropic Claude API patterns for Python and TypeScript. Covers Messages API, streaming, tool use, vision, extended thinking, batches, prompt caching, and Claude Agent SDK. Use when building applications with the Claude API or Anthropic SDKs.

affaan-m/everything-claude-code

Development conventions and patterns for everything-claude-code. JavaScript project with conventional commits.

affaan-m/everything-claude-code

End-to-end marketing campaign planning and execution. Covers audience research, positioning, campaign angle definition, landing page copy, email sequences, social posts, ad copy, short-form video scripts, and content calendars. Use as the orchestration layer for multi-channel product launches. Use when planning or executing a multi-channel product launch, or producing landing page, email, social, or ad copy.

affaan-m/everything-claude-code-conventions

Development conventions and patterns for everything-claude-code. JavaScript project with conventional commits.

affaan-m/frontend-design

Create distinctive, production-grade frontend interfaces with high design quality. Use when the user asks to build web components, pages, or applications and the visual direction matters as much as the code quality.

affaan-m/gget

gget CLI and Python workflow for quick genomic database queries, sequence lookup, BLAST-style searches, enrichment checks, and reproducible bioinformatics evidence logs.

affaan-m/literature-review

Systematic literature-review workflow for academic, biomedical, technical, and scientific topics, including search planning, source screening, synthesis, citation checks, and evidence logging.

affaan-m/motion-ui

Production-ready UI motion system for React/Next.js. Use when implementing animations, transitions, or motion patterns.

affaan-m/project-guidelines-example

Example project-specific skill template based on a real production application.

affaan-m/pubmed-database

Direct PubMed and NCBI E-utilities search workflows for biomedical literature, MeSH queries, PMID lookup, citation retrieval, and API-backed literature monitoring.

affaan-m/scholar-evaluation

Structured scholarly-work evaluation for papers, proposals, literature reviews, methods sections, evidence quality, citation support, and research-writing feedback.

affaan-m/uspto-database

USPTO patent and trademark data workflow for official record lookup, PatentSearch queries, TSDR checks, assignment data, and reproducible IP research logs.

agent-architecture-audit

Full-stack diagnostic for agent and LLM applications. Audits the 12-layer agent stack for wrapper regression, memory pollution, tool discipline failures, hidden repair loops, and rendering corruption. Produces severity-ranked findings with code-first fixes. Essential for developers building agent applications, autonomous loops, or any LLM-powered feature. Use when an agent or LLM feature misbehaves and the failing layer is unknown, or before shipping an agent stack.

agent-eval

Head-to-head comparison of coding agents (Claude Code, Aider, Codex, etc.) on custom tasks with pass rate, cost, time, and consistency metrics. Use when choosing between coding agents, or when a change to an agent setup needs measured pass rate, cost, and time rather than an impression.

agent-harness-construction

Design and optimize AI agent action spaces, tool definitions, and observation formatting for higher completion rates. Use when defining or revising an agent

agentic-engineering

Operate as an agentic engineer using eval-first execution, decomposition, and cost-aware model routing. Use when planning or executing engineering work that agents will carry out end to end.

agentic-os

Build persistent multi-agent operating systems on Claude Code. Covers kernel architecture, specialist agents, slash commands, file-based memory, scheduled automation, and state management without external databases. Use when building a persistent multi-agent system on Claude Code with its own memory, commands, and scheduling.

agent-introspection-debugging

Structured self-debugging workflow for AI agent failures using capture, diagnosis, contained recovery, and introspection reports. Use when an agent run fails and you need a reproducible diagnosis instead of a retry.

agent-payment-x402

Add x402 payment execution to AI agents with per-task budgets, spending controls, and non-custodial wallets. Supports Base through agentwallet-sdk and X Layer through OKX Payments / OKX Agent Payments Protocol. Use when an agent must pay for something itself and needs per-task budgets, spending controls, and a non-custodial wallet.

相關技能