vibe-code-cleanup
它能做什么
这个工具可以帮助清理和整理快速搭建的网页应用中的代码,删除不必要或已损坏的部分,同时不改变原本正常运行的功能。目标是让代码更安全,也更便于在正式环境中维护。
适用场景
- ✓应用能运行,但存在导入错误或未使用代码的时候。
- ✓上线应用或把应用交给别人之前。
- ✓需要整理代码,但不想改动路由或 API 等核心功能时。
技能链接
https://github.com/sickn33/agentic-awesome-skills/blob/main/plugins/agentic-awesome-skills-claude/skills/vibe-code-cleanup/SKILL.md复制后粘贴给你的 AI(Claude、ChatGPT 或 Cursor),让它按照说明操作。
使用方法
最简单的方法:复制下面的消息,粘贴给你的 AI。它会读取这个技能并按说明操作。
可直接粘贴的消息
适用于 Claude Code、Codex 或 Cursor:在项目文件夹中运行,即可安装该技能。
下载 SKILL.md,放进智能体的技能文件夹。
可以这样问 AI
“帮我清理代码,删除未使用的部分,并修复损坏的导入。”
每周 5 个新技能,1 分钟读完。
工作原理
工具会分析代码,找出损坏的导入和未使用的代码。然后,它会谨慎地删除这些部分,同时确保路由和 API 等重要功能继续正常工作。
技术内容(原始 SKILL.md)
作者在 GitHub 上的英文原文。
Vibe-Code Cleanup — Production Refactor Skill
A safe, incremental cleanup workflow for AI-generated / vibe-coded fullstack apps. The goal is to make the codebase production-ready without breaking anything that already works.
When to Use
- Use when a rapidly built app works but has broken imports, duplicated logic, dead code, unclear environment variables, or fragile release hygiene.
- Use before launch or handoff to convert exploratory code into a maintainable production baseline.
- Use when cleanup must preserve existing behavior and avoid broad rewrites of routes, APIs, auth, data models, or integrations.
Core Philosophy
Surgery, not demolition. Remove only what is provably dead. Preserve everything else.
Never:
- Rewrite working systems for cosmetic reasons
- Rename routes, slugs, or API endpoints that may be indexed or cached
- Change tool inputs/outputs, API contracts, DB schema, or auth flow
- Delete files you haven't verified are unused
- Make broad sweeping changes in a single commit
Always:
- Make small, targeted, reversible changes
- Validate after every meaningful batch of changes
- Prefer shared helpers over copy-pasted blocks
- Keep backward compatibility
Step 1 — Reconnaissance (read before touching)
Before changing anything, map the codebase:
# List all pages/routes
find . -type f \( -name 'page.js' -o -name 'page.jsx' -o -name 'page.ts' -o -name 'page.tsx' \)
find pages -type f \( -name '*.js' -o -name '*.jsx' -o -name '*.ts' -o -name '*.tsx' \) | rg -v '/_' | sort
# Find broken imports (TS projects)
npx tsc --noEmit 2>&1 | head -80
# Find unused exports (optional, for larger projects)
npx ts-prune 2>/dev/null | head -40
# Check for console.log / debug leftovers
grep -r "console\.log\|debugger\|TODO\|FIXME\|HACK" --include="*.{js,ts,jsx,tsx}" -l
Document what you find. Do NOT change yet.
Step 2 — Fix Broken Imports First
Broken imports cause build failures and should be fixed before anything else.
# TypeScript: list all errors
npx tsc --noEmit 2>&1
# Common patterns to fix:
# - Missing file (file was deleted or renamed)
# - Wrong relative path (../lib vs ../../lib)
# - Named export that doesn't exist
Fix rule: Fix the import reference. Do NOT delete the referenced file unless you've confirmed it's unused everywhere.
Step 3 — Identify Dead Code (verify before removing)
A file/export is safe to remove only if:
- No other file imports it (grep-confirmed)
- It's not referenced in config, sitemap, or route manifest
- It's not a public-facing URL (page.js, route.js)
# Check if a file is imported anywhere
grep -r "from.*my-file\|require.*my-file" --include="*.{js,ts,jsx,tsx}" .
# Check if a component is used anywhere
grep -r "MyComponent" --include="*.{js,ts,jsx,tsx}" .
Step 4 — Consolidate Repeated Logic into Helpers
Look for repeated patterns (metadata blocks, API fetch wrappers, error handlers) that appear in 3+ places.
Good consolidation targets:
- Page-level SEO metadata (Open Graph, Twitter cards, canonical)
- Fetch wrappers with error handling
- Repeated utility functions (slugify, formatDate, truncate)
Bad consolidation targets (leave alone):
- One-off business logic
- Route handlers with different contracts
- Anything touching DB schema or auth
Pattern for shared metadata helper (Next.js):
// lib/socialMetadata.js
export function buildPageMetadata({ title, description, path, image }) {
const baseUrl = process.env.NEXT_PUBLIC_BASE_URL || 'https://yourdomain.com';
const imageUrl = image?.startsWith('http') ? image : `${baseUrl}${image}`;
return {
title,
description,
openGraph: {
title,
description,
url: `${baseUrl}${path}`,
images: [{ url: imageUrl, width: 1200, height: 630, alt: title }],
},
twitter: {
card: 'summary_large_image',
title,
description,
images: [imageUrl],
},
alternates: {
canonical: `${baseUrl}${path}`,
},
};
}
Step 5 — Environment Variable Audit
# List all env vars used in code
grep -r "process\.env\." --include="*.{js,ts,jsx,tsx}" . | grep -oP 'process\.env\.\w+' | sort -u
# Compare against .env.example or .env.local
cat .env.example 2>/dev/null || cat .env.local 2>/dev/null
Flag any env vars used in code but missing from .env.example. Never add secrets to version control.
…
常见问题
什么是“死代码”?
死代码是指写了但在应用中从未被实际使用的代码。
这个工具会把我的网站弄坏吗?
不会。它的主要目标就是防止出错。它只会删除确定没有被使用的内容,并且只做小而安全的改动。
所有网页应用都能用吗?
可以。它对使用 Next.js、React、Node.js 等技术搭建的网页应用特别有用,这些技术在全栈开发中很常见。
详情
作者的原始描述
Safe production cleanup and hardening for vibe-coded fullstack apps (Next.js, React, Node.js, etc.). Removes dead imports, unused files, and broken references without breaking routes or APIs.
热度
- GitHub 星标
- 48k
- 排名
- #6113
- 许可证
- MIT
- 更新时间
- 2026/10/15
评论
- …
同一仓库的更多技能
00-andruia-consultant
48k帮你的智能体启动或改进 AI 项目。它可以分析代码、推荐工具,并用西班牙语制定行动计划。
007
48k让你的智能体执行安全审计和威胁建模。它有助于保护项目免受攻击和漏洞的威胁。
10-andruia-skill-smith
48k帮你的智能体创建或改进 AI 工具。它可以定义工具的工作方式、编写文档,并验证其结构。
20-andruia-niche-intelligence
48k让你的智能体创建某个特定行业的摘要。它有助于借助可靠的信息来源,了解项目的背景、规则、使用模式和风险。