Communitygithub.com

config-gc

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

config-gc 是什么?

Config GC 是一款专为 Claude Code 配置设计的垃圾回收工具。它借鉴了运行时垃圾回收的思想,定期扫描 `~/.claude` 目录中的技能、记忆文件、钩子、权限、MCP 服务器、定时提醒、项目历史和运行缓存,识别冗余、过期、孤立或低价值的对象,并回收磁盘空间。其核心设计原则是“强制人工参与”:每个候选删除项都需要用户逐一确认(y/n/skip),绝不进行自主删除。 该工具支持多个扫描通道,每个通道有独立的陈腐/冗余信号判定规则。例如,技能通道检查名称重叠和长期未触发;权限通道查找重复条目和被通配符覆盖的特定授权。工作流程包括扫描、排序、逐项确认、软删除(优先重命名为 .disabled 或移动至 _gc_trash)、详细日志记录和最终报告。 Config GC 常用于大型技能包安装后、用户抱怨配置过多或启动缓慢时,以及定期的月度配置审查。它与 `skill-stocktake`(审计技能质量)、`workspace-surface-audit`(推荐新技能)和 `configure-ecc`(安装技能后冲突调解)等技能配合使用,构成完整的配置生命周期管理。

兼容平台✓Claude Code~Codex CLI~Cursor
npx skills add https://github.com/affaan-m/ECC/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. 保留日志。 每次垃圾回收运行都会追加到 ~/.claude/gc_log.md:涉及的内容、原因以及如何撤销。

扫描通道

#通道路径陈腐/冗余信号
1技能~/.claude/skills/*/名称高度重叠;近期对话中从未触发;领域与用户实际工作不匹配;SKILL.md 损坏或为空
2记忆~/.claude/**/memory/*.md 及其索引同一主题有多个索引条目;内容与较新条目冲突;日期已过;索引中缺少孤立文件;应合并的少于 100 字的片段
3钩子~/.claude/hooks/ + 设置脚本存在于磁盘但未被任何钩子配置引用;被重写取代的旧版本
4权限permissions.allow 在 settings.json / settings.local.json重复条目;已被通配符覆盖的特定条目(例如当 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 个候选——垃圾回收是周期性的,不是穷举的。
  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 "孤立: $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/ (撤销: 移回)" >> ~/.claude/gc_log.md

移除已确认冗余的权限条目(JSON 无注释——备份、记录、然后编辑):

cp ~/.claude/settings.local.json ~/.claude/settings.local.json.bak
echo "$(date -Iseconds) removed permission entry: 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/)。配置垃圾回收从不进入源代码树。

最佳实践

  • 在大规模添加后运行,而不是仅按日历运行:安装 50 个技能包时正是与现有技能重叠出现的时候。
  • 当两个技能重叠时,优先禁用触发描述较弱的那一个——因为它可能从未被触发过。
  • 按每分钟花费的时间计算,权限清理是价值最高的通道:冗余的允许条目使安全审查更加困难。
  • 永久保留 gc_log.md。它很小,而且“我什么时候禁用了那个钩子以及为什么”的出现频率比你想象的要高。

相关技能

  • skill-stocktake — 审计技能质量;config-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/content-engine

Create platform-native content systems for X, LinkedIn, TikTok, YouTube, newsletters, and repurposed multi-platform campaigns. Use when the user wants social posts, threads, scripts, content calendars, or one source asset adapted cleanly across platforms.

affaan-m/ECC

Multi-platform content distribution across X, LinkedIn, Threads, and Bluesky. Adapts content per platform using content-engine patterns. Never posts identical content cross-platform. Use when the user wants to distribute content across social platforms.

affaan-m/fal-ai-media

Unified media generation via fal.ai MCP — image, video, and audio. Covers text-to-image (Nano Banana), text/image-to-video (Seedance, Kling, Veo 3), text-to-speech (CSM-1B), and video-to-audio (ThinkSound). Use when the user wants to generate images, videos, or audio with AI.

affaan-m/manim-video

日本語翻訳:このファイルは manim-video 用の日本語翻訳が必要です

affaan-m/remotion-video-creation

Remotion のベストプラクティス - React で動画を作成する。3D、アニメーション、音声、字幕、チャート、トランジションなどをカバーするドメイン固有の29のルール。

affaan-m/video-editing

AI-assisted video editing workflows for cutting, structuring, and augmenting real footage. Covers the full pipeline from raw capture through FFmpeg, Remotion, ElevenLabs, fal.ai, and final polish in Descript or CapCut. Use when the user wants to edit video, cut footage, create vlogs, or build video content.

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.

agent-self-evaluation

Use after completing any non-trivial task. The agent self-rates its output on 5 axes — accuracy, completeness, clarity, actionability, conciseness — with concrete evidence per criterion. Produces a structured 1-5 scorecard with specific improvement suggestions.

agent-sort

Build an evidence-backed ECC install plan for a specific repo by sorting skills, commands, rules, hooks, and extras into DAILY vs LIBRARY buckets using parallel repo-aware review passes. Use when ECC should be trimmed to what a project actually needs instead of loading the full bundle.

ai-first-engineering

Engineering operating model for teams where AI agents generate a large share of implementation output. Use when setting team process, review gates, or ownership rules for a codebase largely written by agents.

ai-regression-testing

Regression testing strategies for AI-assisted development. Sandbox-mode API testing without database dependencies, automated bug-check workflows, and patterns to catch AI blind spots where the same model writes and reviews code. Use when adding regression coverage to AI-assisted code, or when the same model both wrote and reviewed a change.

android-clean-architecture

Clean Architecture patterns for Android and Kotlin Multiplatform projects — module structure, dependency rules, UseCases, Repositories, and data layer patterns. Use when structuring modules, layers, or data flow in an Android or KMP project.

angular-developer

Generates Angular code and provides architectural guidance. Trigger when creating projects, components, or services, or for best practices on reactivity (signals, linkedSignal, resource), forms, dependency injection, routing, SSR, accessibility (ARIA), animations, styling (component styles, Tailwind CSS), testing, or CLI tooling.

相关技能