Skip to content

skillCode quality

Code Smell Detection

Scans a diff or folder for long methods, feature envy and god classes, and proposes the smallest change that removes each smell. It reports before editing.

npx workspacetemplates add code-smell-detection --tool claude-code

Writes 1 file to .claude/skills/code-smell-detection/

.claude/skills/code-smell-detection/SKILL.md32 lines · 1.7 KBFile
---
name: code-smell-detection
description: Scans a diff or folder for long methods, feature envy and god classes, and proposes the smallest change that removes each smell. It reports before editing.
---

# Code smell detection

Look at changed code first; scan the rest only if asked. Report evidence, not taste.

## Steps

1. Get the scope: `git diff main...HEAD --stat` for a branch, or the folder the user named. Read each changed file in full.
2. Check for these, with the threshold that makes each a finding:
   - Long method: over about 40 lines, or more than one level of abstraction in one body.
   - Feature envy: a method that reads another object's fields more than its own.
   - God class: many unrelated fields and methods, or a name ending in Manager or Helper that everything depends on.
   - Long parameter list: more than four, or booleans that switch behavior.
   - Shotgun surgery: one change forcing edits in many files.
   - Primitive obsession: the same string or number pair passed around with rules attached.
3. For every finding, locate the exact lines and pick the smallest fix: extract method, move method, introduce parameter object, replace flag with two functions.
4. Rank by how often the code changes (use `git log --oneline -- <file>` to count). A smell in cold code is low priority.
5. Do not edit. Present the list and ask which items to apply. Apply only the ones approved, one at a time, running tests after each.

## Rules

- Never propose a smell without a line reference.
- Do not flag style, naming or formatting.
- Behavior stays identical; if tests are missing, say so before refactoring.

## Report

A ranked list: location, smell, why it hurts here, smallest fix, estimated risk (low, medium, high).

What it does

A smell list is only useful if it is short and each item comes with a way out. This skill reads the changed code, names the smells it can point to, and ties each one to a small refactoring with a clear before and after.

It does not rewrite your design. Large moves are listed as suggestions, and only the cheap, safe ones are offered to apply.

Example

you › Check my branch for code smells.

agent › 1. src/billing/Invoice.ts:20-96 long method, 76 lines, mixes tax and layout. Extract calculateTax(). Risk low. 2. src/billing/Report.ts:12 feature envy: reads 7 fields of Customer. Move formatAddress() to Customer. Risk low. 3. src/billing/BillingManager.ts god class, 14 deps. Suggest splitting by use case; not a small fix.

Questions

Does it change code on its own?
Not by default. It lists the findings first and edits only the items you approve.
Why rank by change frequency?
A messy file nobody touches costs little. The same mess in a file edited weekly costs time every week.
  • API Deprecation Handling

    SkillCode quality

    Free
  • Code Duplication Removal

    SkillCode quality

    Free
  • Concurrency Bug Analysis

    SkillCode quality

    Free
  • Cyclomatic Complexity Reduction

    SkillCode quality

    Free