Claude Skills Guide

Claude Code for Dead Code Elimination Workflow Guide

Dead code—functions never called, variables never used, classes never instantiated—silently accumulates in software projects over time. This guide shows you how to use Claude Code to systematically identify and eliminate dead code, improving code quality and reducing maintenance burden.

Understanding Dead Code in Modern Projects

Dead code comes in several forms that Claude Code can help you detect:

Before diving into the workflow, ensure Claude Code is installed and your project is accessible.

The Dead Code Elimination Workflow

Step 1: Analyze Your Project Structure

Start by having Claude Code scan your project to understand its structure and identify potential dead code zones:

claude -p "Analyze this project's directory structure and identify the main source directories, programming languages used, and any existing dead code patterns you notice. Focus on finding unused functions, imports, and variables."

This initial analysis helps you understand the scope and guides subsequent detailed investigation.

Step 2: Identify Unused Functions

Ask Claude Code to find functions that are defined but never called:

claude -p "Find all functions in the src/ directory that are defined but never called or referenced elsewhere in the codebase. List each function, its file location, and explain why it appears unused."

Claude Code will analyze your codebase and provide a list of potentially unused functions. Review each suggestion carefully—some functions may be called dynamically or used as callbacks.

Step 3: Detect Unused Imports and Variables

Unused imports bloat your codebase and slow down builds. Have Claude Code identify them:

claude -p "Scan all TypeScript/JavaScript files in src/ and list all imports that are imported but never used in the file. Also identify any declared variables that are never read."

For Python projects, modify the prompt accordingly:

claude -p "Find all imported modules and variables in Python files under the lib/ directory that are imported but never used. Also identify any undefined names or unused function parameters."

Step 4: Find Unreachable Code

Unreachable code—code that can never execute—often results from refactoring or conditional logic that always evaluates the same way:

claude -p "Identify unreachable code in the codebase. Look for: 1) code after unconditional return/throw statements, 2) if statements with conditions that are always true or false, 3) case statements in switch statements that can never be matched. List each instance with file and line number."

Step 5: Identify Deprecated API Usage

Code using deprecated APIs should be updated or removed:

claude -p "Search for usage of deprecated APIs in the codebase. Look for: 1) functions/classes marked as @deprecated or similar annotations, 2) imports from deprecated modules, 3) usage of deprecated language features. List each instance with recommended replacements."

Practical Example: Eliminating Dead Code in a Node.js Project

Consider a typical Node.js project with dead code. Here’s how Claude Code helps clean it up:

Before (sample code with dead code):

// utils/helpers.js
export function formatDate(date) {
  return new Date(date).toISOString();
}

export function formatDateShort(date) {
  return new Date(date).toLocaleDateString();
}

export function oldFormat(date) {
  // This function was used in v1.0 but is no longer needed
  return `${date.getMonth() + 1}/${date.getDate()}/${date.getFullYear()}`;
}

export function calculateSum(numbers) {
  return numbers.reduce((a, b) => a + b, 0);
}

// main.js
import { formatDate } from './utils/helpers.js';

const data = { timestamp: new Date() };
console.log(formatDate(data.timestamp));

Claude Code Analysis:

Running the analysis reveals:

  1. Unused functions: formatDateShort, oldFormat, calculateSum are never imported
  2. Unused variables: data object properties beyond timestamp are never accessed

After (dead code removed):

// utils/helpers.js
export function formatDate(date) {
  return new Date(date).toISOString();
}

// main.js
import { formatDate } from './utils/helpers.js';

console.log(formatDate(new Date()));

Actionable Advice for Ongoing Dead Code Management

Integrate Dead Code Checks into Your CI/CD Pipeline

Add automated dead code detection to your build process:

# For JavaScript/TypeScript projects
npx depcruise --validate . | grep "unused"

# For Python projects
pip install vulture && vulture path/to/code/

Create a Claude Code Skill for Dead Code Detection

Build a reusable skill that automates your dead code workflow:

---
name: dead-code-detector
description: Analyzes codebase for dead code patterns
tools: [read_file, bash]
---

You are a dead code detector. Analyze the provided codebase for:
1. Unused functions and methods
2. Unused imports and variables
3. Unreachable code paths
4. Deprecated API usage

Provide a detailed report with file paths and line numbers.

Schedule Regular Dead Code Reviews

Make dead code elimination a regular practice:

Use TypeScript/ESLint for Automatic Detection

Configure your tooling to catch dead code early:

{
  "rules": {
    "no-unused-vars": "error",
    "no-unused-imports": "error",
    "no-dead-code": "error"
  }
}

Claude Code can help you set up and configure these rules:

claude -p "Help me set up ESLint configuration to detect unused variables and imports in my TypeScript project. Provide the necessary dependencies and eslint.config.js setup."

Conclusion

Dead code elimination is essential for maintaining healthy codebases. Claude Code transforms this tedious task into an efficient workflow by providing intelligent analysis, contextual understanding, and actionable recommendations. Start implementing this workflow today, and you’ll see improvements in code maintainability, faster build times, and reduced cognitive load when navigating your codebase.

Remember: the key to effective dead code management is consistency. Regular scans and incremental cleanup prevent dead code accumulation and keep your project healthy long-term.