Communitygithub.com

config-gc

为你的 Claude Code 配置执行垃圾回收。定期扫描 ~/.claude(技能、记忆、钩子、权限、MCP 服务器、缓存),找出冗余、过时、孤立或低价值的条目,并引导用户逐个确认删除。当用户要求清理时使用。

config-gc 是什么?

Config GC 是一个专门为 Claude Code 配置环境设计的垃圾回收技能。它将运行时垃圾回收的概念应用于开发工具配置管理,通过定期扫描《~/.claude》目录下的技能、记忆、钩子、权限、MCP 服务器和缓存等八个渠道,识别并清理冗余、过时、孤立或低价值的配置项。该技能遵循强制人工参与的原则,每次清理前都会展示证据并要求用户逐个确认(y/n/skip),绝不自动删除。它采用软删除优先策略,先重命名文件或移至回收目录,再执行真实删除,并详细记录每次操作到 gc_log.md 以便撤销。Config GC 支持所有运行 Claude Code 的平台,通过扫描命令(如 bash 和 jq)识别候选对象,每个渠道都有独立的过期信号(如技能名称重叠、权限重复被通配符覆盖、缓存超过30天等),旨在帮助开发者保持配置的整洁和高效。

兼容平台✓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/<date>/。权限条目存在于 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 "ORPHAN: $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) moved skills/dead-skill -> _gc_trash/$gc_date/ (undo: mv back)" >> ~/.claude/gc_log.md

移除已确认冗余的权限条目(JSON 无法添加注释——先备份、记录、再编辑):

cp ~/.claude/settings.local.json ~/.claude/settings.local.json.bak
echo "$(date -Iseconds) removed permission entry: Bash(git push) (undo: restore from .bak or re-add)" >> ~/.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 个技能包时,正是与现有技能重叠出现的时候。
  • 当两个技能重叠时,优先禁用触发描述较弱的那一个——它可能是那个本来就不怎么触发的。
  • 权限清理是每分钟花费中价值最高的渠道:冗余的允许条目会让安全审查变得更困难。
  • 永远保留 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.

相关技能