docs · v0.2.0
Prune docs
Prune is a free, MIT-licensed structural linter for TypeScript and JavaScript. It runs locally, from your terminal, your git hooks, your CI, or your coding agent.
Agent setup
This runbook is written for coding agents. Point yours at prunecode.ai/setup (it's served there as Markdown too) and it works through these steps, using whatever your repo already has.
You are setting up Prune, a local structural linter for TypeScript and JavaScript, in the repository you are working in. Follow these steps in order. Each step says how to check it worked. Do not ask the user about choices this page already makes; report what you did at the end.
1. Install Prune
Check whether it is already installed: prune --version, or npx --no-install prune --version in a Node project. Always pass --no-install before Prune is installed, because a bare npx prune would download an unrelated npm package named prune.
If it isn't installed:
Node project (a
package.jsonexists): install it as a devDependency with the repo's package manager. Use the lockfile to tell which one:bun.lock/bun.lockb→bun add -d prunecodepnpm-lock.yaml→pnpm add -D prunecodeyarn.lock→yarn add -D prunecode- otherwise →
npm i -D prunecode
From then on, run Prune as
npx prune(orbunx prune,pnpm exec prune,yarn prune).No package.json:
curl -fsSL https://prunecode.ai/install.sh | bash, then use~/.prune/bin/prune, or add that directory to PATH.
Check: npx prune --version (or prune --version) prints a version.
2. Initialize and scan
npx prune init # writes .prunerc, adds .prune/ to .gitignore
npx prune scan # first scan; builds the local index in .prune/
If the scan prints "Suggested .prunerc excludes", add the ones that are clearly generated or vendored code (build output, generated clients, fixtures) to exclude in .prunerc, then scan again.
Check: .prunerc exists, .prune/ is in .gitignore, and prune scan prints a score.
3. Record a baseline
Existing findings shouldn't block anyone's commits. Record them:
npx prune baseline # writes .prune-baseline.json
Check: .prune-baseline.json exists. It should be committed.
4. Add the pre-commit check
Use the hook system the repo already has. Never add a second one.
- husky (
.husky/exists): appendnpx prune checkas its own line to.husky/pre-commit. - lefthook (
lefthook.ymlexists): add underpre-commit.commands:prune: glob: "*.{ts,tsx,js,jsx}" run: npx prune check {staged_files} - pre-commit (
.pre-commit-config.yamlexists): add a local hook, which works whether Prune came from npm or the binary install:
(Without npm, use- repo: local hooks: - id: prune name: prune check entry: npx prune check language: system types_or: [ts, tsx, javascript, jsx] require_serial: trueentry: prune check.) - lint-staged only: add
"*.{ts,tsx,js,jsx}": "prune check"to its config. - None of these: leave hooks alone and say so in your report. The user can opt in later.
prune check fails only on new findings at or above high severity, and it never downloads anything, so it is safe in a hook.
Check: stage a TypeScript file and run npx prune check. It prints "passed" or lists new findings.
5. Connect the MCP server
Register prune mcp with the agent client you are running in. Use npx prune as the command if Prune was installed with npm:
- Claude Code:
claude mcp add prune -- npx prune mcp - Cursor: add to
.cursor/mcp.json - Other clients that read
.mcp.json: add to.mcp.json
{ "mcpServers": { "prune": { "command": "npx", "args": ["prune", "mcp"] } } }
Check: the client lists tools such as tasks, verify, safe_to_delete and rename_impact.
6. Leave instructions for future agents
Append to AGENTS.md (or CLAUDE.md if that is what the repo uses; create AGENTS.md if neither exists):
## Prune
- Before deleting or renaming an export, ask Prune: `safe_to_delete` / `rename_impact` (MCP) or `npx prune rename … ` as a dry run.
- After a refactor, run `npx prune check --fail-on medium` and fix what it reports.
- To find cleanup work, run `npx prune tasks`. Each task ends with a `prune verify <id>` command that must exit 0.
7. Work the first tasks (only if the user asked for cleanup)
npx prune tasks -n 10
For each task, in order:
- If the task has an
autofixcommand, run it with the repo's typecheck:npx prune fix --apply --check "<typecheck command>" --path-prefix <file>. - Otherwise make the change described in
change. Before deleting anything, confirm withsafe_to_delete. - Run the task's
done whencommand (npx prune verify <id>) and the repo's typecheck and tests. Move on only when both pass.
8. Report
Tell the user, briefly:
- how Prune was installed
- which hook and MCP client you configured, or why you skipped one
- how many findings the baseline recorded
- the top three tasks from
prune tasks
Then stop. Don't commit unless the user asked you to.
Install
# macOS / Linux binary (installs to ~/.prune/bin)
curl -fsSL https://prunecode.ai/install.sh | bash# per-repo devDependency
npm i -D prunecode# from source
cargo install prunecodePrebuilt binaries for Apple Silicon macOS and Linux (x86_64 and arm64) are attached to every GitHub release.
Quick start
prune init # writes .prunerc (commit it) and ignores .prune/ prune scan # findings with a score prune tasks # the same findings as a prioritized checklist prune # interactive TUI
The local index lives in .prune/ and is never committed. .prunerc is optional: defaults work out of the box.
Pre-commit
prune check checks the files staged for commit (or the files you pass) and the files that import them. It fails only on findings at or above --fail-on (default high), and it never downloads a model.
Record existing debt once so it doesn't block commits:
prune baseline # writes .prune-baseline.json; commit itcheck fails only on findings the baseline doesn't contain. It also looks one hop down, at the files your staged files import, so it catches an export your change left unused.pre-commit framework
repos:
- repo: https://github.com/dlabadini/prune
rev: v0.2.0
hooks:
- id: prune # prune on PATH; use prune-cargo to build from source
args: [--fail-on, medium]husky
# .husky/pre-commit
npx prune checklefthook
pre-commit:
commands:
prune:
glob: "*.{ts,tsx,js,jsx}"
run: npx prune check {staged_files}plain git hook
printf '#!/bin/sh\nexec prune check\n' > .git/hooks/pre-commit chmod +x .git/hooks/pre-commit
CI & baselines
prune scan --baseline --ci exits 1 on any finding missing from .prune-baseline.json. --changed origin/main limits findings to files a branch touched and the files that import them.
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 --ciFinding ids come from the pattern and the symbols or files involved, not from titles or line numbers. They stay stable across unrelated edits, which is what makes them work as baseline keys.
Agents & MCP
Give an agent the work list and a way to check its own work:
prune tasks # markdown checklist, most urgent first prune tasks --json -n 20 # machine-readable prune tasks --changed main # only what this branch touched
Each task carries its id, priority (P1 is most urgent), locations, why it matters and the change to make. When prune fix can apply it, the task includes an autofix command. Every task ends with done when: prune verify <id>, which exits 0 once the finding is gone.
prune tasks -n 10. Work the tasks in order. Prefer each task's autofix. After each, run its done-when command and the typecheck before moving on.”MCP server
# Claude Code
claude mcp add prune -- prune mcp// .mcp.json · .cursor/mcp.json
{ "mcpServers": { "prune": { "command": "prune", "args": ["mcp"] } } }| Tool | Answers |
|---|---|
tasks | Prioritized tasks. Filters: limit, min_severity, changed, use_baseline |
scan | Findings and score, most severe first (same filters, default limit 50) |
plan, compose_plan | Markdown or structured refactor plan for one finding |
verify | Whether a finding is resolved |
who_uses | Usage class of an export, every file that uses it, and barrels that re-export it |
safe_to_delete | Whether deleting or un-exporting it is safe, with reasons |
rename_impact | Files and edit counts a rename touches. Nothing is written. |
recent_files | Files touched in recent git history |
AGENTS.md / CLAUDE.md
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.
TUI & watch
Run prune with no arguments for the interactive TUI. prune scan --watch rescans headlessly as files change.
| Key | Action |
|---|---|
| j / k | Move up and down |
| Enter | Finding detail |
| c | Copy the refactor plan |
| p | Save the plan to REFACTOR_PLAN.md |
| w | Toggle watch mode |
| s / f | Cycle strictness / filter by pattern |
| r / ? / q | Rescan / help / quit |
Commands
| Command | What it does |
|---|---|
prune | Interactive TUI |
prune scan | Findings with a score. --json, --watch, --baseline [FILE], --changed [REF], --ci |
prune check [FILES…] | Pre-commit gate over staged files. --fail-on, --all, --baseline FILE, --no-baseline, --json |
prune tasks | Prioritized task list. --json, -n, --min-severity, --changed, --baseline, -o FILE |
prune baseline | Write current findings to .prune-baseline.json |
prune fix | Safe autofix, dry run unless --apply. --check CMD, --only unexport,delete-file, --path-prefix |
prune rename FILE FROM TO | Rename an export across importers, dry run unless --apply |
prune plan ID | Markdown refactor plan. --copy, -o FILE, --rescan |
prune verify ID | Exit 0 when a finding is resolved. --json, --quick |
prune init | Write .prunerc and ignore .prune/ |
prune config | Show the effective configuration |
prune mcp | Serve MCP tools over stdio |
Every command takes -p PATH to run against another project root.
Patterns
| Pattern | Finds |
|---|---|
| Dead exports | Unreachable files and exports, classified by reachability |
| God file | Files whose behavior (functions, classes) exceeds the export limit, or whose distinct concepts do while the file is also long. Validators, schemas and as const data are declarations, not behavior. |
| Import cycle | Runtime value cycles. A type-only cycle is reported at low severity, and only when no value cycle runs through it. |
| Interface sprawl | Types, interfaces and object validators (v.object, z.object) that restate the same fields |
| Lexicon | One shape under several names, and glossary terms used for unrelated shapes |
| Redundant logic | Similar functions that should be consolidated |
| Barrel bloat | Index files re-exporting too many modules |
| Over-abstraction | Wrappers that only forward a call, and single-implementation interfaces |
Reachability
Prune builds the module graph from entry points and walks it twice: from product entries and from test files. Imports resolve through barrels (export *, aliased re-exports) and namespace imports to the symbol that defines them.
| Class | Meaning | Fix |
|---|---|---|
used | Reached from product code, or consumed by a framework or tool | — |
test_only | Only tests use it | Delete it with its tests |
same_file_only | Only its own file uses it | Drop export (prune fix) |
unused | Nothing reachable uses it | Delete it |
unreachable | Its file is not reachable from any entry | Delete the file (prune fix) |
Entries are discovered from package.json (main, module, types, exports, bin, file paths in scripts), tool config files (*.config.*, root bunfig.toml, CI yaml, vercel.json), files with a #! line, .d.ts declarations, and framework adapters:
- Next.js (any directory with
next.config.*):app/**route files (page,layout,route,loading,error, …),pages/**,public/**, rootmiddleware/proxy/instrumentation. - Convex (
convex.jsonfunctions, elseconvex/): every function module is an entry. Registered functions count as used only when referenced throughapi.*/internal.*chains,"a/b:fn"strings, orconvex run.
Test files are read as reference sources even when exclude matches them, and they're never reported.
Configuration
.prunerc in the project root (TOML). Everything is optional.
strictness = "default" # relaxed | default | strict exclude = ["node_modules/**", "dist/**"] disabled_patterns = [] [thresholds] god_file_max_exports = 25 god_file_max_lines = 600 interface_sprawl_similarity = 0.85 dead_exports_min_per_file = 1 [entries] # beyond the discovered ones files = ["vercel.ts", "scripts/**"] test_files = ["**/*.test.ts", "**/__tests__/**", "e2e/**"] [dead_exports] report_unreachable_files = true report_test_only = true report_same_file = true [frameworks.convex] dirs = ["convex"] [frameworks.next] roots = ["."] [[boundaries]] # a fenced boundary owns its types name = "inbox" paths = ["packages/inbox/**"] fenced = true [lexicon.glossary] draft = "a held reply awaiting review" [fix] check = "bun run typecheck" # used by prune fix / rename
Boundaries: duplicate shapes across a fenced boundary are intentional and not reported. Duplicates inside it are.
Safe autofix
prune fix handles the two dead-code fixes that are mechanical: dropping export from symbols only their own file uses, and deleting unreachable files. Unreachable files that import each other are deleted together.
prune fix # dry run: print the plan prune fix --apply --check "bun run typecheck" # apply, verify, revert failures prune rename src/thread.ts ThreadRow ThreadSummary --apply --check "bun run typecheck"
Each unit is written, the check command runs, and the unit is reverted if the check fails.
Contributing
Prune is MIT licensed and developed on GitHub. Issues and pull requests are welcome, and false positives with a minimal repro are especially welcome.
cargo test
cargo test --test accuracy -- --nocapture # precision/recall on labeled fixtures
cargo clippy --all-targets -- -D warningsNew detectors and framework adapters should come with a labeled fixture under tests/fixtures/. Its labels.json lists the findings that must and must not appear.