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.json exists): 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 prunecode
    • pnpm-lock.yaml → pnpm add -D prunecode
    • yarn.lock → yarn add -D prunecode
    • otherwise → npm i -D prunecode

    From then on, run Prune as npx prune (or bunx 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): append npx prune check as its own line to .husky/pre-commit.
  • lefthook (lefthook.yml exists): add under pre-commit.commands:
    prune:
      glob: "*.{ts,tsx,js,jsx}"
      run: npx prune check {staged_files}
    
  • pre-commit (.pre-commit-config.yaml exists): add a local hook, which works whether Prune came from npm or the binary install:
    - repo: local
      hooks:
        - id: prune
          name: prune check
          entry: npx prune check
          language: system
          types_or: [ts, tsx, javascript, jsx]
          require_serial: true
    
    (Without npm, use entry: 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:

  1. If the task has an autofix command, run it with the repo's typecheck: npx prune fix --apply --check "<typecheck command>" --path-prefix <file>.
  2. Otherwise make the change described in change. Before deleting anything, confirm with safe_to_delete.
  3. Run the task's done when command (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.

Reference: Docs · llms.txt · Source

Install

Using a coding agent? Skip manual install and tell it: “Set up Prune in this repo by following prunecode.ai/setup.” It follows the agent setup runbook above.
# 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 prunecode

Prebuilt 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 it
With a baseline, check 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 check

lefthook

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 --ci

Finding 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.

A prompt that works well: “Run 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"] } } }
ToolAnswers
tasksPrioritized tasks. Filters: limit, min_severity, changed, use_baseline
scanFindings and score, most severe first (same filters, default limit 50)
plan, compose_planMarkdown or structured refactor plan for one finding
verifyWhether a finding is resolved
who_usesUsage class of an export, every file that uses it, and barrels that re-export it
safe_to_deleteWhether deleting or un-exporting it is safe, with reasons
rename_impactFiles and edit counts a rename touches. Nothing is written.
recent_filesFiles 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.

KeyAction
j / kMove up and down
EnterFinding detail
cCopy the refactor plan
pSave the plan to REFACTOR_PLAN.md
wToggle watch mode
s / fCycle strictness / filter by pattern
r / ? / qRescan / help / quit

Commands

CommandWhat it does
pruneInteractive TUI
prune scanFindings 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 tasksPrioritized task list. --json, -n, --min-severity, --changed, --baseline, -o FILE
prune baselineWrite current findings to .prune-baseline.json
prune fixSafe autofix, dry run unless --apply. --check CMD, --only unexport,delete-file, --path-prefix
prune rename FILE FROM TORename an export across importers, dry run unless --apply
prune plan IDMarkdown refactor plan. --copy, -o FILE, --rescan
prune verify IDExit 0 when a finding is resolved. --json, --quick
prune initWrite .prunerc and ignore .prune/
prune configShow the effective configuration
prune mcpServe MCP tools over stdio

Every command takes -p PATH to run against another project root.

Patterns

PatternFinds
Dead exportsUnreachable files and exports, classified by reachability
God fileFiles 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 cycleRuntime value cycles. A type-only cycle is reported at low severity, and only when no value cycle runs through it.
Interface sprawlTypes, interfaces and object validators (v.object, z.object) that restate the same fields
LexiconOne shape under several names, and glossary terms used for unrelated shapes
Redundant logicSimilar functions that should be consolidated
Barrel bloatIndex files re-exporting too many modules
Over-abstractionWrappers 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.

ClassMeaningFix
usedReached from product code, or consumed by a framework or tool—
test_onlyOnly tests use itDelete it with its tests
same_file_onlyOnly its own file uses itDrop export (prune fix)
unusedNothing reachable uses itDelete it
unreachableIts file is not reachable from any entryDelete 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/**, root middleware/proxy/instrumentation.
  • Convex (convex.json functions, else convex/): every function module is an entry. Registered functions count as used only when referenced through api.* / internal.* chains, "a/b:fn" strings, or convex 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 warnings

New 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.