clean-codebase
정보
이 스킬은 사용되지 않는 코드, 미사용 임포트, 린트 경고와 같은 코드 위생 문제를 자동으로 정리하면서 포맷팅을 표준화합니다. 급속한 개발 후 핵심 비즈니스 로직을 변경하지 않고 기술 부채를 해결하는 데 이상적입니다. 이 도구는 여러 언어에서 작동하며 정적 분석 도구가 일반적으로 표시하는 유지보수 작업에 중점을 둡니다.
빠른 설치
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/clean-codebaseClaude Code에서 이 명령을 복사하여 붙여넣어 스킬을 설치하세요
문서
コードベースのクリーンアップ
使用タイミング
Use this skill when a codebase has accumulated hygiene debt:
- Lint warnings have piled up during rapid development
- Unused imports and variables clutter files
- Dead code paths exist but were never removed
- Formatting is inconsistent across files
- Static analysis tools report fixable issues
Do NOT use for architectural refactoring, bug fixes, or business logic changes. This skill focuses purely on hygiene and automated cleanup.
入力
| Parameter | Type | Required | Description |
|---|---|---|---|
codebase_path | string | Yes | Absolute path to codebase root |
language | string | Yes | Primary language (js, python, r, rust, etc.) |
cleanup_mode | enum | No | safe (default) or aggressive |
run_tests | boolean | No | Run test suite after cleanup (default: true) |
backup | boolean | No | Create backup before deletion (default: true) |
手順
ステップ1: Pre-Cleanup Assessment
Measure the current state to quantify improvements later.
# Count lint warnings by severity
lint_tool --format json > lint_before.json
# Count lines of code
cloc . --json > cloc_before.json
# List unused symbols (language-dependent)
# JavaScript/TypeScript: ts-prune or depcheck
# Python: vulture
# R: lintr unused function checks
期待結果: Baseline metrics saved to lint_before.json and cloc_before.json
失敗時: If lint tool not found, skip automated fixes and focus on manual review
ステップ2: Fix Automated Lint Warnings
Apply safe automated fixes (spacing, quotes, semicolons, trailing whitespace).
JavaScript/TypeScript:
eslint --fix .
prettier --write .
Python:
black .
isort .
ruff check --fix .
R:
Rscript -e "styler::style_dir('.')"
Rust:
cargo fmt
cargo clippy --fix --allow-dirty
期待結果: All safe lint warnings resolved; files formatted consistently
失敗時: If automated fixes introduce test failures, revert changes and escalate
ステップ3: Identify Dead Code Paths
Use static analysis to find unreferenced functions, unused variables, and orphaned files.
JavaScript/TypeScript:
ts-prune | tee dead_code.txt
depcheck | tee unused_deps.txt
Python:
vulture . | tee dead_code.txt
R:
Rscript -e "lintr::lint_dir('.', linters = lintr::unused_function_linter())"
General approach:
- Grep for function definitions
- Grep for function calls
- Report functions defined but never called
期待結果: dead_code.txt lists unused functions, variables, and files
失敗時: If static analysis tool unavailable, manually review recent commit history for orphaned code
ステップ4: Remove Unused Imports
Clean up import blocks by removing references to packages never used.
JavaScript:
eslint --fix --rule 'no-unused-vars: error'
Python:
autoflake --remove-all-unused-imports --in-place --recursive .
R:
# Manual review: grep for library() calls, check if package used
grep -r "library(" . | cut -d: -f2 | sort | uniq
期待結果: All unused import statements removed
失敗時: If removing imports breaks build, they were used indirectly — restore and document
ステップ5: Remove Dead Code (Mode-Dependent)
Safe Mode (default):
- Only remove code explicitly marked as deprecated
- Remove commented-out code blocks (if >10 lines and >6 months old)
- Remove TODO comments referencing completed issues
Aggressive Mode (opt-in):
- Remove all functions identified as unused in Step 3
- Remove private methods with zero references
- Remove feature flags for deprecated features
For each candidate deletion:
- Verify zero references in codebase
- Check git history for recent activity (skip if modified in last 30 days)
- Remove code and add entry to
CLEANUP_LOG.md
期待結果: Dead code removed; CLEANUP_LOG.md documents all deletions
失敗時: If uncertain whether code is truly dead, move to archive/ directory instead
ステップ6: Normalize Formatting
Ensure consistent formatting across all files (even if not caught by linters).
- Normalize line endings (LF vs CRLF)
- Ensure single newline at end of file
- Remove trailing whitespace
- Normalize indentation (spaces vs tabs, indent width)
# Example: Fix line endings and trailing whitespace
find . -type f -name "*.js" -exec sed -i 's/\r$//' {} +
find . -type f -name "*.js" -exec sed -i 's/[[:space:]]*$//' {} +
期待結果: All files follow consistent formatting conventions
失敗時: If sed breaks binary files, skip and document
ステップ7: Run Tests
Validate that cleanup didn't break functionality.
# Language-specific test command
npm test # JavaScript
pytest # Python
R CMD check # R
cargo test # Rust
期待結果: All tests pass (or same failures as before cleanup)
失敗時: Revert changes incrementally to identify breaking change, then escalate
ステップ8: Generate Cleanup Report
Document all changes for review.
# Codebase Cleanup Report
**Date**: YYYY-MM-DD
**Mode**: safe | aggressive
**Language**: <language>
## Metrics
| Metric | Before | After | Change |
|--------|--------|-------|--------|
| Lint warnings | X | Y | -Z |
| Lines of code | A | B | -C |
| Unused imports | D | 0 | -D |
| Dead functions | E | F | -G |
## Changes Applied
1. Fixed X lint warnings (automated)
2. Removed Y unused imports
3. Deleted Z lines of dead code (see CLEANUP_LOG.md)
4. Normalized formatting across W files
## Escalations
- [Issue description requiring human review]
- [Uncertain deletion moved to archive/]
## Validation
- [x] All tests pass
- [x] Backup created: backup_YYYYMMDD/
- [x] CLEANUP_LOG.md updated
期待結果: Report saved to CLEANUP_REPORT.md in project root
失敗時: (N/A — generate report regardless of outcome)
バリデーション Checklist
After cleanup:
- All tests pass (or same failures as before)
- No new lint warnings introduced
- Backup created before any deletions
-
CLEANUP_LOG.mddocuments all removed code - Cleanup report generated with metrics
- Git diff reviewed for unexpected changes
- CI pipeline passes
よくある落とし穴
-
Removing Code Still Used via Reflection: Static analysis misses dynamic calls (e.g.,
eval(), metaprogramming). Always check git history. -
Breaking Implicit Dependencies: Removing imports that were used by dependencies. Run tests after every import removal.
-
Deleting Feature Flags for Active Features: Even if unused in current branch, feature flags may be active in other environments. Check deployment configs.
-
Over-Aggressive Formatting: Tools like
blackorprettiermay reformat code in ways that trigger unnecessary diffs. Configure tools to match project style. -
Ignoring Test Coverage: Cannot safely clean codebases without tests. If coverage is low, escalate for test additions first.
-
Not Backing Up: Always create
backup_YYYYMMDD/directory before deleting anything, even if using git. -
Wrong R binary on hybrid systems: On WSL or Docker,
Rscriptmay resolve to a cross-platform wrapper instead of native R. Check withwhich Rscript && Rscript --version. Prefer the native R binary (e.g.,/usr/local/bin/Rscripton Linux/WSL) for reliability. See Setting Up Your Environment for R path configuration.
関連スキル
- tidy-project-structure — Organize directory layout, update READMEs
- repair-broken-references — Fix dead links and imports
- escalate-issues — Route complex problems to specialists
- r-packages/run-r-cmd-check — Run full R package checks
- devops/dependency-audit — Check for outdated dependencies
GitHub 저장소
연관 스킬
railway-docs
문서이 스킬은 Railway의 기능, 작동 방식 또는 특정 문서 URL에 대한 질문에 답하기 위해 최신 Railway 문서를 가져옵니다. 개발자들이 Railway의 공식 소스로부터 정확하고 최신 정보를 직접 받을 수 있도록 보장합니다. 사용자가 Railway의 작동 방식을 묻거나 Railway 문서를 참조할 때 사용하세요.
n8n-code-python
문서이 Claude Skill은 n8n의 Code 노드에서 Python 코드를 작성할 때 전문적인 지침을 제공하며, 특히 Python 표준 라이브러리 사용과 n8n의 특수 구문인 `_input`, `_json`, `_node` 작업에 중점을 둡니다. 이는 개발자가 n8n 내에서 Python의 제한 사항을 이해하도록 돕고, 대부분의 워크플로에는 JavaScript 사용을 권장하면서도 특정 데이터 변환 요구사항에 대한 Python 솔루션을 제안합니다.
archon
문서Archon 스킬은 REST API를 통해 RAG 기반 시맨틱 검색과 프로젝트 관리를 제공합니다. 이 스킬을 사용하여 문서 검색, 계층적 프로젝트/태스크 관리, 문서 업로드 기능을 갖춘 지식 검색을 수행할 수 있습니다. 외부 문서를 검색할 때는 다른 소스를 사용하기 전에 항상 Archon을 최우선으로 활용하세요.
n8n-code-javascript
문서이 Claude Skill은 n8n의 Code 노드에서 JavaScript 코드 작성에 대한 전문적인 지침을 제공합니다. `$input`/`$json` 변수, HTTP 헬퍼, DateTime 처리와 같은 필수적인 n8n 특정 구문을 다루며 일반적인 오류를 해결합니다. Code 노드에서 사용자 정의 JavaScript 처리가 필요한 n8n 워크플로우를 개발할 때 활용하세요.
