Agent skill

Dead Code Removal with Knip

by shift-editor in shift-editor/shift

Finds unused files, exports and class members with Knip, then verifies each candidate through reference tracing before removing anything, never using knip --fix.

Apache-2.0Auto-check passedDevelopment

Install Dead Code Removal with Knip

skills CLI
$ npx skills add shift-editor/shift --skill dead-code -a claude-code

Project install by default; add -g for ~/.claude/skills/.

GitHub CLI
$ gh skill install shift-editor/shift dead-code --agent claude-code

Project scope by default; add --scope user for a personal install. Needs GitHub CLI 2.90.0 or later (public preview).

Manual copy
$ git clone --depth 1 https://github.com/shift-editor/shift.git skills-src && mkdir -p .claude/skills && cp -r skills-src/.claude/skills/dead-code .claude/skills/dead-code && rm -rf skills-src

Use ~/.claude/skills/ instead of .claude/skills for a personal install. The folder must contain SKILL.md.

Claude Code skills documentation · loads skills from .claude/skills/

Facts

Skill name
dead-code
GitHub stars
343
Token cost
~1.8k tokens
SKILL.md length
646 words
Files
1
Skills in repo
14
Repo updated
First seen
Licence
Apache-2.0

At a glance

Finds unused files, exports and class members with Knip, then verifies each candidate through reference tracing before removing anything, never using knip --fix.

  • Works in 3 steps: Discovery → Verification → Action
  • Cleaning up unused files and exports in a TypeScript codebase
  • SKILL.md covers Phase 1: Discovery, Phase 2: Verification, Phase 3: Action and Safety Protocol
  • Calls pnpm and npx

What it does

Knip is used only to generate candidates, through the project's deadcode and class-member scripts, and the output is sorted into unused files, unused exports and unused class members. The skill warns never to run knip --fix because it once deleted code that was in use, breaking the editor and its tests.

Each candidate is then checked by hand. Files are searched by name and checked against config files, test helpers, package scripts and CI. Exports are checked for barrel re-exports, extends and implements clauses and test-only use, with a find-refs.ts script giving a compiler-level reference count. Class members, where most false positives occur, are traced through interface contracts, composite types, dependency-injection interfaces, base classes and abstract methods.

When your agent uses it

  • Cleaning up unused files and exports in a TypeScript codebase
  • Deciding whether a class member that Knip flags is really unused
  • Reducing codebase size without breaking code Knip cannot trace

Example prompts

  • “Find dead code in this repo with Knip and verify each candidate before deleting anything.”
  • “Knip says this method is unused. Check interface contracts and base classes before I remove it.”
  • “Remove the unused exports, but check barrel files and test imports first.”

Requirements

  • Knip with the project's deadcode scripts configured
  • pnpm

Workflow steps

3 steps, taken from the step headings in SKILL.md.

  1. Discovery
  2. Verification
  3. Action

What it can do on your machine

Read from SKILL.md and the folder at commit e7dacfa. It shows what the files ask for, not the result of running them.

  • Tool permissions

    Pre-approves nothing: there is no allowed-tools line, so your agent's usual permission prompts apply.

    From allowed-tools in the SKILL.md frontmatter.

  • Runs code

    Shell commands in SKILL.md call:

    • pnpm
    • npx

    From the folder's file list and the shell code blocks in SKILL.md.

  • Network

    No URLs in SKILL.md. Its commands use pnpm and npx, which can reach the network depending on how they are called.

    From URLs in SKILL.md, links to its own repository left out.

  • Credentials

    Names no API keys, tokens, secrets or passwords.

    From names ending in _API_KEY, _TOKEN, _SECRET, _KEY or _PASSWORD in SKILL.md.

Context cost

Dead Code Removal with Knip loads about 1.8k tokens when it runs. Until then it costs about 75 tokens; SKILL.md has 646 words of instructions outside code blocks.

Always · name and description, kept in context so the agent knows when to use it
~75
When it runs · the whole SKILL.md, loaded when a task matches
~1.8k

Estimates: characters ÷ 4, the usual rule of thumb; real counts depend on the model's tokenizer. Scripts and assets cost tokens only if the agent reads them.

Safety

Auto-check passed

The automated check found no risky patterns in SKILL.md.

Automated static check — not a guarantee. Review scripts before installing. It scans the text of SKILL.md for risky patterns (piping downloads into a shell, reading credential files, hidden Unicode, destructive commands); files beside SKILL.md are not scanned.

SKILL.md

The full file from shift-editor/shift at commit e7dacfa, republished under its Apache-2.0 licence (© shift-editor). 646 words, ~1,807 tokens.

Download SKILL.mdSave it as .claude/skills/dead-code/SKILL.md (or your agent's skills folder).
name
dead-code
description
Find and remove dead code (unused files, exports, class members) using Knip as a candidate generator, then verify each candidate through AST-level analysis and interface tracing before removing anything. Use when the user asks to clean up unused code, find dead code, or reduce the codebase.

/dead-code — Find and Remove Dead Code

Use this skill to find unused files, exports, and class members in the codebase. It uses Knip as a candidate generator, then verifies each candidate through AST-level analysis and interface tracing before removing anything.

NEVER use knip --fix — it has previously deleted code that was actually in use, breaking the editor and tests.

Phase 1: Discovery

Run Knip to generate candidates:

bash
pnpm deadcode 2>&1        # unused files + exports
pnpm deadcode:class 2>&1  # unused class members

Parse the output into three categories:

  • Unused files — files with zero imports
  • Unused exports — exported symbols with no consumers
  • Unused class members — class methods/properties reported as unused

Phase 2: Verification

For each candidate, apply the appropriate checks below. Use scripts/find-refs.ts when reading code alone is insufficient.

Verifying Unused Files
  1. Grep for the filename (without extension) across the codebase
  2. Check config references: tsconfig.json, vite.*.config.ts, forge.config.ts
  3. Check if it's a test helper imported by test files (Knip may miss test-only imports)
  4. Check if it's referenced in package.json scripts or CI workflows
Verifying Unused Exports
  1. Check if re-exported by a barrel file (index.ts) consumed by another package
  2. Check if used in extends/implements clauses
  3. Check if used only in test files (Knip sometimes misses test imports)
  4. Run npx tsx scripts/find-refs.ts <file> <symbol> for compiler-level reference count
Verifying Unused Class Members (Main Pain Point)

This is where most false positives occur. Knip cannot trace usage through interfaces, composite types, or dep interfaces.

Check these patterns in order:

  1. Interface contract — Is the member defined on an interface the class implements? Check the known interface contracts below.
  2. Composite type — Is the class consumed through a type intersection? e.g., ShiftEditor = EditorAPI & CanvasCoordinatorContext means all EditorAPI members on Editor are used.
  3. Dep interface — Is the member part of a dependency injection interface? Classes implement dep interfaces that are consumed by managers.
  4. Base class — Is the member defined on a base class (BaseCommand, BaseTool) and used by subclasses?
  5. Abstract member — Is it an abstract method that subclasses must implement?
  6. Find References — Run npx tsx scripts/find-refs.ts <file> <memberName> for compiler confirmation.
Show full SKILL.md (312 more words)Show less
Known Interface Contracts (Always False Positives)

Members that satisfy any of these interfaces are NOT dead code, even if Knip reports them:

EditorAPI sub-interfaces (apps/desktop/src/renderer/src/lib/tools/core/EditorAPI.ts):

  • Viewport: zoomLevel, panX, panY, screenToUpm, upmToScreen, screenToUpmDistance, viewportBounds
  • Selection: selectedPointIds, selectedSegmentIds, selectPoints, selectSegments, clearSelection, marqueePreviewPointIds, setMarqueePreview
  • HitTesting: hitTestPoint, hitTestSegment, hitTestContour, hitTestBoundingBox, hitTestContourEndpoint, hitTestHandle
  • Snapping: createDragSnapSession, createRotateSnapSession, setSnapIndicator
  • Editing: startEdit, commitEdit, cancelEdit, isEditing
  • Commands: execute
  • ToolLifecycle: activeTool, setActiveTool, activeToolSettings
  • VisualState: hoveredPoint, setHoveredPoint, hoveredSegment, setHoveredSegment, cursor, setCursor

Font interface (apps/desktop/src/renderer/src/lib/editor/Font.ts):

  • getMetrics, getMetadata, getSvgPath, getAdvance, getBbox

Command interface (apps/desktop/src/renderer/src/lib/commands/core/):

  • execute, undo, redo, name

Behavior interface (apps/desktop/src/renderer/src/lib/tools/core/):

  • canHandle, transition, onTransition

BaseTool abstract members:

  • behaviors, render, executeAction, onStateChange, preTransition

Dep interfaces (consumed by managers, implemented by FontEngine or Editor):

  • EditingEngineDeps — apps/desktop/src/renderer/src/engine/editing.ts
  • SessionEngineDeps — apps/desktop/src/renderer/src/engine/session.ts
  • InfoEngineDeps — apps/desktop/src/renderer/src/engine/info.ts
  • IOEngineDeps — apps/desktop/src/renderer/src/engine/io.ts
  • Snap — apps/desktop/src/renderer/src/managers/SnapManager.ts
  • Clipboard — apps/desktop/src/renderer/src/managers/ClipboardManager.ts
  • CanvasCoordinatorContext — apps/desktop/src/renderer/src/lib/editor/rendering/CanvasCoordinator.ts
Using the Find References Script
bash
# Check if a symbol has any non-definition references
npx tsx scripts/find-refs.ts apps/desktop/src/renderer/src/lib/editor/Editor.ts undo

# Output shows: file, line, kind (definition vs reference)
# Zero non-definition references = confirmed dead
# >0 references = inspect them to confirm usage

Phase 3: Action

Categorize Results

Present a categorized report:

CategoryMeaningAction
Confirmed deadNo references, not on any interfaceRemove with confirmation
Likely deadAmbiguous — few references, possibly test-onlyFlag for human review
False positiveInterface-mediated, dep interface, or base classTag with @knipclassignore
Removing Confirmed Dead Code
  1. Remove the dead code manually (NEVER use knip --fix)
  2. Run verification after each batch of removals:
    bash
    pnpm typecheck && pnpm test && pnpm lint:check
  3. If tests fail, revert the removal and recategorize as "likely dead"
Tagging False Positives

For confirmed false positive class members, add the @knipclassignore JSDoc tag:

typescript
/** @knipclassignore */
undo(): void {
    // ...
}

After tagging, decrease the --max-issues threshold in package.json's deadcode:class script:

bash
# Current threshold
pnpm deadcode:class  # check current --max-issues value

# After tagging N false positives, reduce by N
# Edit package.json: --max-issues (current - N)

# Verify the new threshold holds
pnpm deadcode:class

The goal is to drive --max-issues toward 0, at which point CI catches any new dead code with zero tolerance.

Safety Protocol

  1. NEVER use knip --fix or deadcode:fix
  2. NEVER remove code without verifying it's not used through interfaces
  3. ALWAYS run pnpm typecheck && pnpm test && pnpm lint:check after removals
  4. ALWAYS check interface contracts before declaring a class member dead
  5. If in doubt, categorize as "likely dead" rather than "confirmed dead"

© shift-editor, Apache-2.0. Rendered from Markdown: HTML in the file is shown as text, images as links, and headings moved down two levels. Raw file

Files

Just SKILL.md in .claude/skills/dead-code of shift-editor/shift.

Open the folder on GitHubat commit e7dacfa

Compare with similar skills

Dead Code Removal with Knip next to the 5 skills that share the most tags, products or categories with it. Stars are the repository's; “used in” counts other GitHub owners with a copy.

Dead Code Removal with Knip compared with similar skills
SkillStarsUsed inTokensAuto-checkLicenceRepo updated
Dead Code Removal with Knip this skillshift-editor/shift343—~1.8kAutomated safety check: PassApache-2.0
DRY Refactoring With jscpdkucherenko/jscpd6.3k—~2.1kAutomated safety check: PassMIT
Code RefinerMathews-Tom/armory327—~3.1kAutomated safety check: PassMIT
Code Simplification for ego-litecitrolabs/ego-lite17k—~1.2kAutomated safety check: PassMIT
Dep Refszai-org/ZCode7.5k—~552Automated safety check: PassApache-2.0
Codebase Health Refactoringkucherenko/jscpd6.3k—~2.5kAutomated safety check: PassMIT

Similar skills

  • Removes copy-paste duplication found by jscpd, starting with exact clones and hotspots, then renamed and near-miss copies, using proven refactoring strategies.

    6.3k GitHub stars~2.1k tokensUpdated today
    DevelopmentAuto-check passed
  • Code Refiner

    Mathews-Tom/armory

    Deep code simplification and refactoring preserving behavior across Python, Go, TypeScript, Rust.

    327 GitHub stars~3.1k tokensUpdated yesterday
    DevelopmentAuto-check passed
  • Finds and implements evidence-backed simplifications in the ego-lite repository, such as dead code, duplicated state and speculative abstractions, without hiding behavior changes.

    17k GitHub stars~1.2k tokensUpdated 14 days ago
    DevelopmentAuto-check passed
  • Dep Refs

    zai-org/ZCode

    A skill your agent uses when needs to inspect TypeScript export references in the z-code workspace, list exports from a file, verify whether an export is unused before deletion, investigate who…

    7.5k GitHub stars~552 tokensUpdated 8 days ago
    DevelopmentAuto-check passed
  • A three-part cleanup guided by jscpd: measure health, then fix duplicated code, remove dead code and simplify the most complex files, finishing by re-measuring the score.

    6.3k GitHub stars~2.5k tokensUpdated today
    DevelopmentAuto-check passed
  • Finds duplicated code in 220+ languages with jscpd, reports exact, renamed and near-miss clones in a compact agent-friendly format and measures duplication.

    6.3k GitHub stars~4.6k tokensUpdated today
    DevelopmentAuto-check passed

More from shift-editor/shift

All 14 skills in this repo
  • Shift Commit Rules

    shift-editor/shift

    Rules for writing git commits in the Shift font editor repo: Conventional Commits subjects, user-facing changelog wording, concise subjects and logical commit boundaries.

    343 GitHub stars~1.4k tokensUpdated yesterday
    Auto-check: notes
  • Shift Subsystem Docs

    shift-editor/shift

    Updates or creates DOCS.md files for Shift subsystems, recording the architecture invariants and constraints that cannot be learned from reading the source.

    343 GitHub stars~1.9k tokensUpdated yesterday
    Auto-check passed
  • Adversarial Docs Audit

    shift-editor/shift

    Fact-checks DOCS.md files against the source code, testing each concrete claim and sorting it as true, false, stale or unverifiable.

    343 GitHub stars~818 tokensUpdated yesterday
    Auto-check passed
  • Shift Issue Writer

    shift-editor/shift

    Sets the rules for finding, writing and updating Shift GitHub issues: search for duplicates first, use outcome-focused titles and testable acceptance criteria.

    343 GitHub stars~1.4k tokensUpdated yesterday
    Auto-check passed
  • Shift JSDoc Contracts

    shift-editor/shift

    Guides writing JSDoc for Shift exported APIs as a stable caller contract, covering ownership, lifetime, side effects and nullability that TypeScript types cannot express.

    343 GitHub stars~3.7k tokensUpdated yesterday
    Auto-check passed
  • Shift Pull Request Rules

    shift-editor/shift

    Rules for preparing, opening and updating pull requests in the Shift repository: Conventional Commit titles, Release Please effects, evidence-based bodies and UI screenshots.

    343 GitHub stars~2.1k tokensUpdated yesterday
    Auto-check: notes

Works with

Categories

Questions about Dead Code Removal with Knip

What does Dead Code Removal with Knip do?

Finds unused files, exports and class members with Knip, then verifies each candidate through reference tracing before removing anything, never using knip --fix. Knip is used only to generate candidates, through the project's deadcode and class-member scripts, and the output is sorted into unused files, unused exports and unused class members. The skill warns never to run knip --fix because it once deleted code that was in use, breaking the editor and its tests.

When should I use Dead Code Removal with Knip?

Dead Code Removal with Knip fits situations like: cleaning up unused files and exports in a TypeScript codebase; deciding whether a class member that Knip flags is really unused; reducing codebase size without breaking code Knip cannot trace.

How do I install Dead Code Removal with Knip in Claude Code?

Run `npx skills add shift-editor/shift --skill dead-code -a claude-code`. Or copy the skill folder (.claude/skills/dead-code in shift-editor/shift) into .claude/skills/dead-code in your project. Claude Code loads it when a task matches its description.

How do I install Dead Code Removal with Knip in Codex?

Run `npx skills add shift-editor/shift --skill dead-code -a codex`. Or copy the skill folder (.claude/skills/dead-code in shift-editor/shift) into .agents/skills/dead-code in your project. Codex loads it when a task matches its description.

Can I use Dead Code Removal with Knip in Cursor, Gemini CLI or GitHub Copilot?

Cursor, Gemini CLI, GitHub Copilot and OpenCode also load SKILL.md folders. With the skills CLI, run `npx skills add shift-editor/shift --skill dead-code -a cursor` (or -a gemini-cli, github-copilot or opencode for the others). To copy it by hand, put the folder in .cursor/skills/dead-code, .gemini/skills/dead-code, .github/skills/dead-code and .opencode/skills/dead-code in your project.

What does Dead Code Removal with Knip need to run?

Going by SKILL.md and its folder, Dead Code Removal with Knip needs the command-line tools its instructions call (pnpm and npx). Our summary lists: Knip with the project's deadcode scripts configured; pnpm.

Does Dead Code Removal with Knip access the network?

SKILL.md contains no URLs. Its commands use npx, which can reach the network depending on how they are called. This is read from the text; nothing was executed.

Is Dead Code Removal with Knip safe to install?

Our automated static check of SKILL.md found no risky patterns, such as piping downloads into a shell, reading credential files or hidden Unicode. It is not a guarantee. Review the folder before installing.

What licence does Dead Code Removal with Knip use?

Dead Code Removal with Knip is published under the Apache-2.0 licence (the repository's licence). It allows redistribution, so the full SKILL.md is shown on this page.

How many tokens does Dead Code Removal with Knip use?

About 1.8k tokens (SKILL.md is roughly 7.2k characters). Agents keep only the skill's name and description in context until a task matches; then they load SKILL.md in full.

What are the alternatives to Dead Code Removal with Knip?

Skills that share tags, products or a category with Dead Code Removal with Knip: DRY Refactoring With jscpd (kucherenko/jscpd, 6.3k stars), Code Refiner (Mathews-Tom/armory, 327 stars), Code Simplification for ego-lite (citrolabs/ego-lite, 17k stars) and Dep Refs (zai-org/ZCode, 7.5k stars). The comparison table on this page puts their stars, adoption, token cost, safety result and licence side by side.

Who maintains Dead Code Removal with Knip?

shift-editor (a GitHub organization) maintains it in shift-editor/shift, which has 343 GitHub stars. The repository holds 14 skills in this directory. The repository was last updated on October 6, 2026.

Source: shift-editor/shift on GitHub. Facts on this page come from the repository at the commit we read; the author's words are quoted as theirs.