snipe-port

Kill processes on a port, but only if they belong to the same project.

npm version license
$ npm i -g snipe-port click to copy

Why?

⚠ kill-port

# Kills ANY process on port 3000
# Could be your database, another
# project, or a production process
kill-port 3000

✓ snipe-port

# Only kills if the process belongs
# to your current project
# Safe to use without thinking twice
snipe-port 3000

How it works

1

Find PIDs on the port

Uses lsof to find all processes listening on the given port.

2

Resolve working directory

Determines each process's working directory via lsof -d cwd (macOS) or /proc/PID/cwd (Linux).

3

Check project membership

Compares the process's cwd and git repo root (including worktrees) against your current project.

4

Kill only matching processes

Sends SIGTERM (or SIGKILL with -9) only to processes that belong to your project.

Usage

snipe-port 3000           # kill process on port 3000
snipe-port 3000 8080      # multiple ports
snipe-port -9 3000        # force kill (SIGKILL)
snipe-port --udp 3000     # target UDP

Features

Zero dependencies

Uses only Node.js built-ins. No bloat, no supply chain risk.

Git worktree aware

Recognizes processes in git worktrees as part of the same project.

Programmatic API

Use as a library in your Node.js scripts and tooling.

No shell injection

Uses execFileSync — arguments are never passed through a shell.