MCP HubMCP Hub
스킬 목록으로 돌아가기

clean-codebase

pjt222
업데이트됨 2 days ago
4 조회
17
2
17
GitHub에서 보기
문서api

정보

이 스킬은 사용되지 않는 코드와 임포트를 제거하고 린트 경고를 수정하며 서식을 정규화하여 자동화된 코드베이스 위생 관리를 수행합니다. 급속한 개발 과정에서 기술 부채가 누적되었을 때 비즈니스 로직이나 아키텍처를 변경하지 않고 사용하도록 설계되었습니다. 이 도구는 코드베이스 전반에 걸쳐 수정 가능한 정적 분석 문제와 서식 불일치에 중점을 둡니다.

빠른 설치

Claude Code

추천
기본
npx skills add pjt222/agent-almanac -a claude-code
플러그인 명령대체
/plugin add https://github.com/pjt222/agent-almanac
Git 클론대체
git clone https://github.com/pjt222/agent-almanac.git ~/.claude/skills/clean-codebase

Claude Code에서 이 명령을 복사하여 붙여넣어 스킬을 설치하세요

문서

clean-codebase

Use When

Codebase has hygiene debt:

  • Lint warns piled up during rapid dev
  • Unused imports + vars clutter files
  • Dead code paths never removed
  • Formatting inconsistent across files
  • Static analysis reports fixable issues

Do NOT use for architectural refactor, bug fixes, or business logic changes. This = hygiene + automated cleanup only.

In

ParamTypeRequiredDescription
codebase_pathstringYesAbsolute path to codebase root
languagestringYesPrimary language (js, python, r, rust, etc.)
cleanup_modeenumNosafe (default) or aggressive
run_testsbooleanNoRun test suite after cleanup (default: true)
backupbooleanNoCreate backup before deletion (default: true)

Do

Step 1: Pre-Cleanup Assessment

Measure current state → quantify gains 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 + cloc_before.json

If err: Lint tool not found → skip automated fixes, manual review

Step 2: Fix Automated Lint Warnings

Apply safe auto fixes (spacing, quotes, semis, trailing ws).

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 warns resolved; files formatted consistent

If err: Auto fixes break tests → revert, escalate

Step 3: Identify Dead Code Paths

Static analysis → unreferenced fns, unused vars, 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:

  1. Grep fn defs
  2. Grep fn calls
  3. Report fns defined but never called

dead_code.txt lists unused fns, vars, files

If err: Static analysis tool unavail → manual review recent commit history for orphans

Step 4: Remove Unused Imports

Clean import blocks → drop refs to pkgs 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 imports removed

If err: Removing imports breaks build → used indirectly → restore + doc

Step 5: Remove Dead Code (Mode-Dependent)

Safe Mode (default):

  • Remove code explicit marked deprecated
  • Remove commented-out blocks (>10 lines + >6 months old)
  • Remove TODO comments for completed issues

Aggressive Mode (opt-in):

  • Remove all unused fns from Step 3
  • Remove private methods w/ zero refs
  • Remove feature flags for deprecated features

Each candidate deletion:

  1. Valid. zero refs in codebase
  2. Check git history → skip if modified last 30 days
  3. Remove + add entry to CLEANUP_LOG.md

Dead code removed; CLEANUP_LOG.md documents all deletions

If err: Uncertain code truly dead → move to archive/ dir vs. delete

Step 6: Normalize Formatting

Consistent formatting all files (even if linters miss).

  1. Normalize line endings (LF vs CRLF)
  2. Single newline at EOF
  3. Remove trailing ws
  4. Normalize indentation (spaces vs tabs, 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 err: sed breaks binary files → skip + doc

Step 7: Run Tests

Valid. 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 fails as pre-cleanup)

If err: Revert incrementally → identify breaking change → escalate

Step 8: Generate Cleanup Report

Doc 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

If err: (N/A — generate report regardless)

Check

Post-cleanup:

  • All tests pass (or same fails as before)
  • No new lint warns introduced
  • Backup created pre-delete
  • CLEANUP_LOG.md documents all removed code
  • Cleanup report generated w/ metrics
  • Git diff reviewed for unexpected changes
  • CI pipeline passes

Traps

  1. Remove Code Still Used via Reflection: Static analysis misses dynamic calls (e.g., eval(), metaprogramming). Always check git history.

  2. Break Implicit Deps: Removing imports used by deps. Run tests after every import removal.

  3. Delete Feature Flags for Active Features: Unused in current branch, but maybe active in other envs. Check deployment configs.

  4. Over-Aggressive Formatting: Tools like black / prettier reformat → unnecessary diffs. Configure tools → project style.

  5. Ignore Test Coverage: Can't safely clean codebases w/o tests. Low coverage → escalate for test additions first.

  6. No Backup: Always create backup_YYYYMMDD/ dir pre-delete, even w/ git.

  7. Wrong R binary on hybrid systems: WSL / Docker, Rscript maybe resolves to cross-platform wrapper vs. native R. Check w/ which Rscript && Rscript --version. Prefer native R binary (e.g., /usr/local/bin/Rscript Linux/WSL) for reliability. See Setting Up Your Environment for R path config.

GitHub 저장소

pjt222/agent-almanac
경로: i18n/caveman-ultra/skills/clean-codebase
0
agentsagentskillsai-assisted-developmentclaude-codeskillsteams

연관 스킬

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 워크플로우를 개발할 때 활용하세요.

스킬 보기