2 exports nothing needs in format.ts
- where
src/lib/format.ts:3:7- change
- Delete
formatDate; dropexportfromtoISO - autofix
prune fix --apply --path-prefix src/lib/format.ts- done when
prune verify dead_exports-72b08f4a
A structural linter for AI-written TypeScript. Prune finds the dead exports, orphan files, duplicate types and god files your agent leaves behind, then hands the cleanup back to it as tasks it can verify.
Set up Prune in this repo by following https://prunecode.ai/setup, then show me the top cleanup tasks.
works with Claude Code, Cursor, Codex, Copilot and any MCP client
why prune
Every line an agent writes can pass lint and typecheck while the codebase quietly grows a second User type, a helper nobody calls, and a file nothing imports. Prune reads the whole module graph, so it sees those problems.
export function formatDate(d: Date) {
const opts = { month: "short" };
return d.toLocaleDateString();
}
set it up
The one line at the top of this page is the whole install. Your agent follows a runbook written for agents, uses what your repo already has, and tells you what it did.
prune check into the hook system you already usepackage.jsondevDependency prunecode.prunercdefaults, generated code excluded.gitignoreignores the local index .prune/.prune-baseline.json37 existing findings accepted.husky/pre-commit+ npx prune check.mcp.jsonprune MCP serverAGENTS.mdwhen to ask PrunePrune is set up. The baseline holds 37 findings, so nothing blocks commits. Top tasks: delete 2 unused exports in format.ts, merge UserDTO into User, and break the auth ↔ session cycle. Want me to start?
The prune hook uses the binary on your PATH. prune-cargo builds from source instead.
Record existing debt once with prune baseline and commit .prune-baseline.json.
# .pre-commit-config.yaml
repos:
- repo: https://github.com/dlabadini/prune
rev: v0.2.0
hooks:
- id: prune
args: [--fail-on, medium]Install it per repo with npm i -D prunecode, like any other lint tool. With no arguments it checks staged files. Pass a file list to check only those.
# .husky/pre-commit
npx prune check# lefthook.yml
pre-commit:
commands:
prune:
glob: "*.{ts,tsx,js,jsx}"
run: npx prune check {staged_files}--baseline --ci exits 1 on any finding missing from the committed baseline. Add --changed origin/main to scope to the branch.
# .github/workflows/prune.yml
name: prune
on: pull_request
jobs:
prune:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- run: curl -fsSL https://prunecode.ai/install.sh | bash
- run: ~/.prune/bin/prune scan --baseline --ciprune mcp serves tasks, scan, plan, verify, who_uses, safe_to_delete, rename_impact and more over stdio.
# Claude Code
claude mcp add prune -- prune mcp// .mcp.json · .cursor/mcp.json
{ "mcpServers": { "prune": { "command": "prune", "args": ["mcp"] } } }Two lines in AGENTS.md or CLAUDE.md keep agents from deleting something that's still used, and from leaving dead code behind.
Before deleting or renaming an export, ask Prune (`safe_to_delete`, `rename_impact`). After a refactor, run `prune check --fail-on medium` and fix what it reports.
how it works
Prune never rewrites your code behind your back. It finds the dead wood, writes a precise task, and verifies the result, so an agent can clean up without guessing.
Entries found automatically: package.json exports and scripts, next.config routes, convex/ functions, configs, shebang scripts.
src/lib/format.ts:3 :7formatDate; drop export from toISOprune fix --apply --path-prefix src/lib/format.tsprune verify dead_exports-72b08f4a3−export function formatDate(d: Date) {
4− return d.toLocaleDateString("en-US");
5−}
6−
7−export function toISO(d: Date) {
3+function toISO(d: Date) {
4 return d.toISOString();
5 }
1 new finding in what you staged
export interface User {
id: string;
email: string;
name: string;
}
export interface UserDTO {
id: string;
email: string;
name: string;
}
Interface sprawl: UserDTO restates User. Import User instead.
37 existing findings are in the baseline and don't block.
what it finds
Every finding comes with its locations, why it matters, a refactor plan, and an id that stays stable across unrelated edits. essential recommended emerging
1import { parseISO } from "date-fns";
2
3export function formatDate(d: Date) {unused
4 return d.toLocaleDateString("en-US");
5}
6
7export function toISO(d: Date) {same_file_only
8 return d.toISOString();
9}
10
11export const stamp = () => toISO(new Date());used · api/log.ts
Fix: delete formatDate, drop export from toISO. prune fix can do both.
app/page.tsxnext routelib/api.tslib/format.tsscripts/seed.tspackage.json scriptlib/db.tslegacy/orphan.tsunreachablelegacy/orphan-helpers.tsonly orphan.tsFiles that only import each other are deleted together, and the deletion is reverted if your typecheck fails.
src/utils.ts · 41 functions · 1,180 linesFive unrelated concepts in one file. The plan splits it along those lines: strings.ts, dates.ts, money.ts…
import { refresh } from "./session";
export function login() { … }
import { login } from "./auth";
export function refresh() { … }
auth.ts → session.ts → auth.ts evaluates in a different order depending on who imports first. An import type loop is reported separately, at low severity.
export interface User { id; email; name }export interface UserDTO { id; email; name }const UserInfo = z.object({ id, email, name })Three names, one shape, including a validator. Inside a fenced boundary, duplication across the fence is treated as intentional.
type Draft = {
threadId; body; sendAt;
}type Draft = {
docId; blocks; version;
}"Draft" means two unrelated things. Add a glossary entry in .prunerc and Prune flags every use that drifts from it.
export async function getUserById(id) {
const r = await db.users.find(id);
if (!r) throw new NotFound();
return r;
}export async function fetchUser(userId) {
const u = await db.users.find(userId);
if (!u) throw new NotFound();
return u;
}Same logic, different names. The plan keeps one and repoints the callers, and prune rename handles the edits.
export * from "./api";
export * from "./auth";
export * from "./billing";
… 61 moreexport function getUser(id) {
return fetchUser(id);
}Barrels hide real dependencies and slow tooling. A function that only forwards a call is an extra name to learn for no benefit.
local-first
Prune is one Rust binary with no account and no telemetry. Everything from parsing to the index runs on your machine. A scan makes no network requests; the only download is the optional embedding model, once, if you turn it on.
faq
Prune is a free, open-source structural linter for TypeScript and JavaScript. It reads your whole module graph to find what coding agents tend to leave behind: dead exports, unreachable files, duplicate types, god files, import cycles and near-duplicate functions. It then turns those findings into tasks an agent can work through and verify.
Usually not. Ask your coding agent to follow https://prunecode.ai/setup and it handles the install, the baseline, the pre-commit hook and the MCP connection, using whatever your repo already has. Defaults work without a .prunerc. You only touch config to exclude generated code or tune thresholds.
Yes. Prune is MIT licensed and free for any use, including commercial. There is no account, no license key and no paid tier.
No. Prune is a single binary that parses, indexes and analyzes your code locally. A scan makes no network calls. The optional semantic matching uses a small embedding model that runs locally and is only downloaded when you enable it.
TypeScript and JavaScript (.ts, .tsx, .js, .jsx, .mts, .mjs, .cts, .cjs). Entry points are discovered from package.json, tool configs, scripts and shebang files, and there are built-in adapters for Next.js routes and Convex functions.
ESLint and tsc check code file by file. Unused-export tools report what nothing imports. Prune classifies every export by how far it is from used (used, test_only, same_file_only, unused, unreachable). It also finds duplicate shapes, god files and import cycles, and it hands each finding to your agent as a task with a verify command.
Tell your agent: "Set up Prune in this repo by following https://prunecode.ai/setup." The setup page is written for agents. It installs Prune with your package manager, adds the pre-commit check, and connects the MCP server (for Claude Code: claude mcp add prune -- npx prune mcp). After that, the agent can call tasks, verify, who_uses, safe_to_delete and rename_impact on its own.
Not if you record a baseline. Run prune baseline once and commit .prune-baseline.json. After that, prune check in pre-commit and prune scan --baseline --ci fail only on findings that are new.
Only the mechanical ones: dropping export from symbols that only their own file uses, and deleting unreachable files. prune fix --apply --check "<your typecheck>" applies each fix, runs your check, and reverts the fix if the check fails. Everything else becomes a task for you or your agent.
open source
MIT licensed, free forever, built in the open. If Prune gets something wrong, open an issue with the smallest repro you can. That's how the detectors get sharper.