npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

@mathonsunday/dead-code-toolkit

v0.2.1

Published

Comprehensive dead code detection and cleanup toolkit for TypeScript projects. Detects unused exports, files, dependencies, type errors, and more via Knip, TypeScript, ESLint, and custom analysis.

Readme

@mathonsunday/dead-code-toolkit

Comprehensive dead code detection and cleanup toolkit for TypeScript projects

Detects unused exports, files, dependencies, type errors, and more via Knip, TypeScript, ESLint, and custom analysis. Perfect for keeping TypeScript codebases clean and maintaining high code quality.

Features

Multi-layered Detection

  • Knip: Unused exports, files, dependencies (symbol-level)
  • TypeScript: Type errors and unused variables
  • ESLint: Linting issues and redundant types
  • Union Exhaustiveness: Validates discriminated unions

🔧 Automated Setup

  • One-command project setup: npx @mathonsunday/dead-code-toolkit setup
  • Detects project type and generates optimal configurations
  • Optional pre-commit hooks via --hooks flag

🚀 LLM-Friendly

  • Callable as an MCP tool for AI assistance
  • Structured JSON output for easy interpretation
  • Action items and recommendations
  • Perfect for Claude, ChatGPT, and other LLMs

📊 Reporting

  • Human-readable terminal output
  • JSON format for programmatic use
  • LLM-friendly summaries
  • Detailed suggestions for fixes

Installation

npm install --save-dev @mathonsunday/dead-code-toolkit

Quick Start

CLI Usage

Analyze your project for dead code:

npx dead-code-toolkit analyze

Output as JSON (for LLMs):

npx dead-code-toolkit analyze --json

Get brief summary:

npx dead-code-toolkit analyze --summary

Specific checks:

npx dead-code-toolkit analyze --checks knip,typescript

Run individual checks:

npx dead-code-toolkit check:knip
npx dead-code-toolkit check:types

Programmatic Usage

import { analyzeDeadCode, createJSONReport } from '@mathonsunday/dead-code-toolkit';

const result = await analyzeDeadCode({
  projectRoot: process.cwd(),
  checks: ['knip', 'typescript'],
  verbose: true,
});

console.log(`Found ${result.summary.totalIssues} issues`);
console.log(`${result.summary.fixableCount} can be auto-fixed`);

// Get JSON report for LLM consumption
const report = createJSONReport(result);
console.log(JSON.stringify(report, null, 2));

Setup in New Project

Automatic setup:

npx @mathonsunday/dead-code-toolkit setup

This auto-detects your project type and generates optimal configurations. Use --hooks flag to also install pre-commit hooks (optional).

Configuration

The toolkit auto-detects your project structure and generates appropriate configs. You can override defaults:

knip.json - Symbol-level dead code detection

{
  "entry": ["src/main.ts", "api/handler.ts"],
  "project": ["src/**/*.ts", "api/**/*.ts"],
  "ignore": ["dist/**", "node_modules/**"]
}

ESLint rules - Add to eslint.config.js:

export default [
  {
    rules: {
      '@typescript-eslint/no-unused-vars': 'warn',
      '@typescript-eslint/no-redundant-type-constituents': 'warn',
      '@typescript-eslint/switch-exhaustiveness-check': 'error',
    },
  },
];

package.json scripts:

{
  "scripts": {
    "dead-code": "knip",
    "dead-code:fix": "knip --fix",
    "dead-code:analyze": "dead-code-toolkit analyze",
    "verify": "npm run type-check && npm run lint && npm run dead-code"
  }
}

LLM Integration

Use with Claude or other LLMs as an MCP tool:

// In your tool registry
const deadCodeTool = {
  name: 'dead_code_analysis',
  description: 'Analyze TypeScript project for dead code',
  execute: async (input) => {
    const result = await analyzeDeadCode({
      projectRoot: input.projectRoot,
      checks: input.checks || ['knip', 'typescript'],
    });
    return createJSONReport(result);
  },
};

LLM Workflow:

  1. User: "Help clean up dead code"
  2. LLM: Calls dead_code_analysis tool
  3. Tool: Returns structured findings
  4. LLM: Interprets results and guides user
  5. User: Approves fixes
  6. LLM: Applies changes

Architecture

Checker Layers

| Layer | Detection Method | Scope | |-------|-----------------|-------| | Knip | Symbol analysis | Exports, files, dependencies | | TypeScript | Type compiler | Type errors, unused variables | | ESLint | Linting rules | Unused variables, redundant types, union exhaustiveness |

Finding Categories

  • unused-export - Exported but never used
  • unused-file - File never imported
  • unused-dependency - Package in package.json but unused
  • type-error - TypeScript compilation error
  • unused-var - Variable declared but never used
  • unused-param - Function parameter never used
  • redundant-type - Union with overlapping members
  • union-issue - Discriminated union not exhaustively handled

Known Limitations

  1. Semantic dead code - Cannot detect if code serves no business purpose
  2. Dynamic imports - May miss import(./${variant})
  3. Reflection - Runtime string-based access not tracked
  4. Cross-project usage - Only analyzes within single project
  5. Performance - May be slow on 100k+ LOC projects (optimization in progress)

Troubleshooting

"Knip not installed"

npm install --save-dev knip

"TypeScript not found"

npm install --save-dev typescript

"No issues found but I think there's dead code"

  • Run with --verbose flag for detailed output
  • Check knip.json entry points are correct
  • Verify project structure matches config

License

MIT