Skip to content

Instantly share code, notes, and snippets.

@SilenNaihin
Created January 15, 2026 09:44
Show Gist options
  • Select an option

  • Save SilenNaihin/cd321a0ada16963867ad8984f44922cf to your computer and use it in GitHub Desktop.

Select an option

Save SilenNaihin/cd321a0ada16963867ad8984f44922cf to your computer and use it in GitHub Desktop.
Claude Code: Refactor command for code quality cleanup with jscpd, knip, and code-simplifier

Refactor

You are doing a focused refactoring session. This is a distinct phase, not continuous activity.

Step 1: Run Quality Checks

First, check if jscpd and knip are installed. If not, install them:

npm install -D jscpd knip
npx knip init

Run both tools:

npx jscpd src/
npx knip

Report the results:

  • jscpd: Number of duplicate code blocks and duplication percentage
  • knip: Unused files, unused dependencies, unused exports, unused types

Step 2: Fix Issues Found

For each issue:

  • Duplicate code: Extract to shared utility or component
  • Unused files: Delete them
  • Unused dependencies: Remove from package.json
  • Unused exports: Remove the export or delete if truly unused

Step 3: Run Code Simplifier

After fixing quality issues, run the code-simplifier plugin:

/code-simplifier

This simplifies complex code patterns that accumulated during development.

Step 4: Delete Obsolete Files

Look for files that are no longer needed after recent changes. Common culprits:

  • Old implementations that were replaced
  • Test files for deleted code
  • Unused components or utilities
  • Stale documentation

Step 5: Commit Cleanup

Commit the refactoring changes as a distinct commit:

git add -A
git commit -m "refactor: code quality cleanup (jscpd, knip, simplification)"

Guidelines

  • Treat refactoring as a distinct phase, not continuous activity
  • Do this when you feel pain from Claude making mistakes, or after large additions
  • ~20% of dev time on focused code quality improvements is reasonable
  • Don't over-optimize—ship working code, then clean up
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment