dead-code-ai
v0.1.0
Published
Static analyzer that finds semantically useless code using LLM reasoning
Maintainers
Readme
dead-code-ai
A static analyzer that finds semantically useless code — not just syntactically unused variables (ESLint already does that).
$ npx dead-code-ai src/
What it finds that ESLint can't
| Pattern | Example |
|---|---|
| Result computed, never used | const x = heavyFn(); return otherThing; |
| Condition always true/false | if (env === 'prod' && env !== 'prod') |
| Argument never referenced | function add(a, b, c) { return a + b; } |
| Object built, never read | const obj = {a: 1}; doSomethingElse(); |
| Loop result discarded | items.forEach(x => total += x); return 0; |
| Immediate reassign before read | let x = compute(); x = 0; use(x); |
| Redundant double-computation | validate(data); validate(data); save(data); |
ESLint catches let x = 1; with no usage. dead-code-ai catches semantic waste — code that runs but whose result is meaningless in context.
Install
npm install -g dead-code-ai
# or use directly
npx dead-code-aiUsage
# Analyze current directory
dead-code-ai
# Analyze specific files or directories
dead-code-ai src/ lib/utils.ts
# Only report high-severity issues
dead-code-ai --min-severity high src/
# Output JSON (for CI integration)
dead-code-ai --json src/ > report.json
# Custom extensions
dead-code-ai --ext .ts,.tsx src/Setup
Get a free API key at console.groq.com and set it:
export GROQ_API_KEY=gsk_...Or pass it inline:
dead-code-ai --key gsk_... src/CI Integration
# .github/workflows/dead-code.yml
- name: Check for semantic dead code
run: npx dead-code-ai --min-severity high --json src/
env:
GROQ_API_KEY: ${{ secrets.GROQ_API_KEY }}How it works
- Parse — Babel AST extracts every function/method in your codebase
- Batch — Functions are grouped into batches of 6 to minimize API calls
- Analyze — Each batch is sent to
llama-3.3-70b-versatilevia Groq with a strict prompt focused on semantic analysis - Report — Findings are printed with file, line, severity, and the exact problematic snippet
Options
| Flag | Default | Description |
|---|---|---|
| --key | $GROQ_API_KEY | Groq API key |
| --ext | .js,.jsx,.ts,.tsx,.mjs,.cjs | File extensions to analyze |
| --min-severity | low | Minimum severity: high, medium, low |
| --json | off | Output raw JSON instead of formatted output |
Severity levels
- ● high — Code that provably does nothing (always-false branch, result always discarded)
- ◆ medium — Code that likely does nothing in most contexts
- ○ low — Code that is suspicious and worth reviewing
Supported languages
- JavaScript (
.js,.mjs,.cjs) - TypeScript (
.ts) - React (
.jsx,.tsx)
License
MIT — built by iamadhitya1
