All skills
simota avatar
by shingo imotasimota/agent-skills85 stars
15

Refactoring code: variable naming, function extraction, magic number constants, dead code removal. Does not change behavior. Not for bugs/security (Judge), tests (Radar), or features (Builder).

Use this Skill: https://skilld.dev/gh/simota/agent-skills/zen

This session only. Nothing lands on disk.

referencedead-code-detection.md

≈1.1k tokens on demand. Your agent reads this file only when SKILL.md points to it.

Dead Code Detection Guide

Purpose: Use this file before deleting code that might be unused, exported, dynamic, or protected by feature flags.

Contents

Comprehensive guide for detecting and safely removing dead code across languages.


Detection Tools by Language

TypeScript/JavaScript

Tool Detects Command Notes
knip Unused files, exports, deps, types npx knip Recommended — ~300K weekly downloads; auto-detects tooling; VSCode extension available; --fix flag auto-removes unused deps (knip.dev)
eslint Unused vars, imports npx eslint --rule 'no-unused-vars: error' src/
TypeScript compiler Unreachable code tsc --noUnusedLocals --noUnusedParameters
depcheck Unused dependencies npx depcheck Still useful for a focused dep-only check
ts-prune Unused exports npx ts-prune Archived Sep 19, 2025 — use knip instead (comparison & migration)

Python

Tool Detects Command
vulture Unused code vulture src/
autoflake Unused imports/vars autoflake --check -r src/
pylint Unused vars, imports pylint --disable=all --enable=W0611,W0612 src/
flake8 Unused imports flake8 --select=F401 src/
pyflakes Unused imports/vars pyflakes src/

Go

Tool Detects Command
deadcode Unreachable functions deadcode ./...
staticcheck Unused code patterns staticcheck ./...
golangci-lint Multiple checks golangci-lint run --enable unused

Rust

Tool Detects Command
cargo (built-in) Dead code warnings cargo build 2>&1 | grep "dead_code"
cargo-udeps Unused dependencies cargo udeps

Dead Code Categories

Category Example Safe to Remove?
Unused local variable const unused = 1; Yes
Unused import import { unused } from './lib'; Yes
Commented-out code // oldFunction(); Yes
Console.log in production console.log('debug'); Yes
Unused private method private helper() {} Yes
Unused exported function export function unused() {} Check external usage
Unused public API public unusedMethod() {} May be called dynamically
Feature flag dead branch if (false) { ... } Confirm flag is permanent

Safe Removal Checklist

Before removing code that appears dead:

  • Search for string references (dynamic invocation)
  • Check for reflection/metaprogramming usage
  • Verify not used in tests only
  • Check for external package consumers (if library)
  • Confirm feature flags are truly retired
  • Run full test suite after removal

Dead Code Cleanup Pattern

// Step 1: Identify unused code
// Run: npx ts-prune | grep -v "used in module"

// Step 2: Mark for removal (optional comment phase)
/** @deprecated Unused - scheduled for removal */
export function oldHelper() { ... }

// Step 3: Remove and verify
// Delete the code, run tests

// Step 4: Clean up imports
// Remove any import statements that reference deleted code

Language-Specific Patterns

TypeScript: Find Unused Exports

# knip — recommended replacement for ts-prune (archived Sep 2025)
npx knip

# Auto-fix unused deps and some exports
npx knip --fix

# CI: report findings without failing the build while cleaning up
npx knip --no-exit-code

Python: Remove Unused Imports

# Auto-fix with autoflake
autoflake --in-place --remove-all-unused-imports -r src/

# Preview only
autoflake --check -r src/

Go: Find Unreachable Functions

# golang.org/x/tools/cmd/deadcode
go install golang.org/x/tools/cmd/deadcode@latest
deadcode -test ./...

Source: SKILL.md on GitHub

1 warning13d5 checks · Risk SAFE
  • Gen Agent Trust Hub13d

    No security issues detected. The skill provides comprehensive and well-structured instructions for code refactoring and quality review. It utilizes standard developer tools, references reputable technical documentation from trusted organizations, and includes explicit safety boundaries to ensure behavior-preserving changes.

  • Socket13d

    No alerts

  • Snyk13d

    Risk: LOW · No issues

  • Runlayer6mo

    1/15 files flagged

  • ZeroLeaks5mo

    Score: 93/100 · 2 sections analyzed

Signed by skilld at e307415. This ties the file your Agent reads to that commit on GitHub. It does not review the instructions.

Last checked against GitHub 2 days ago.

Activeupdated 2 weeks ago

README badge

README badge for simota/agent-skills/zen