A fast, zero-dependency, cross-platform CLI to find and kill processes occupying ports on Linux, macOS, and Windows.
Stop Googling lsof vs netstat—just run pk 3000 (kp, kill-port and port-kill are the same command).
npm package · Source · Report an issue · Security policy · Privacy · Terms
- Zero Dependencies: Instant startup with
npx—no bloatednode_modulestree. - Cross-Platform: Works seamlessly on Linux (
ss, falling back tolsof), macOS (lsof), and Windows (netstat/taskkill). - Safe & Graceful: On Linux/macOS sends
SIGTERMfirst so servers clean up properly, escalating toSIGKILLonly if needed. Before every signal it re-checks that the PID still holds the port, so a recycled PID is never killed by mistake. By default only the process holding the port is stopped;--childrenadds everything running under it and--treeits parent too. Windows has no graceful signal for server processes, sotaskkill /T /F(the holder and everything under it) is always used there. - Process Info: Shows the process name and PID, who can reach the port (
all interfacesorlocalhost only), and on Linux/macOS the owning user and full command line. Docker containers show their image. - Clear Results: Every freed port says how it was stopped (
SIGTERM (graceful),SIGTERM, then SIGKILL,SIGKILL (forced),taskkill /T /F,docker stop) and multi-port runs end with aFreed 3 of 4 portssummary. - Multi-Port & Ranges: Kill single ports, multiple ports, or port ranges in one command. Ports are freed concurrently, so five servers take about half a second, not five times as long. Large ranges print one summary line for the free ports instead of one line each.
- Docker-Aware: Ports published by a Docker container are freed with
docker stopinstead of killing Docker's proxy (which would break Docker networking). Remote Docker contexts (DOCKER_HOST=tcp://…,ssh://…) are ignored, so a container on another machine is never stopped because its port number matches. - Interactive Mode: Run
pkwith no arguments to see every port in use and tick the ones to free.
- Node.js 18 or newer.
- Linux:
ss(falls back tolsofwhenssis missing). macOS:lsof. Both also usepsfor the owner and command. - Windows:
netstat,tasklistandtaskkill, which ship with the OS. - Optional: Docker to detect and stop containers that publish ports.
npx @majidev-org/port-kill-cli 3000npm install -g @majidev-org/port-kill-cli
pk 3000 # or: kp 3000 (also available as `port-kill` and `kill-port`)npm does not notify you about new versions of a global package, so check from time to time:
pk --version # what you have
npm view @majidev-org/port-kill-cli version # latest published
npm outdated -g @majidev-org/port-kill-cli # shows current vs latest (no output = up to date)
npm install -g @majidev-org/port-kill-cli@latest # updateWith npx, add @latest (npx @majidev-org/port-kill-cli@latest 3000) to be sure you are not running a cached older copy. To hear about releases, use Watch → Custom → Releases on the GitHub repository.
npm uninstall -g @majidev-org/port-kill-cliThis removes all four commands (pk, kp, kill-port, port-kill). Use the package name, not a command name. pk stores no config or data, so nothing else is left behind. If you only ever used npx, nothing is installed; npm cache clean --force clears the cached download.
# Kill a single port
pk 3000 # or: kp 3000
# Kill multiple ports at once
pk 3000 5173 8080 # or: kp 3000 5173 8080
# Kill a range of ports
pk 3000-3005 # or: kp 3000-3005
# Inspect what is running on a port without killing it
pk 3000 --info # or: kp 3000 --info
# Force kill immediately (skips graceful SIGTERM)
pk 3000 --force # or: kp 3000 --force
# Also stop everything running under it (Linux/macOS; Windows always does)
pk 3000 --children # or: kp 3000 --children
# Stop its parent and everything under that, e.g. a helper's app (Linux/macOS). Asks first
pk 3000 --tree # or: kp 3000 --tree
pk 3000 --tree --yes # same, without the question (scripts)
# Pick ports to free from an interactive list
pk # or: kp
# List every port in use (processes and Docker containers)
pk --info # or: kp --info
# Show the installed version
pk --version # or: kp --version
# Show help menu
pk --help # or: kp --helpEvery example works with any of the command names below.
| Command | Notes |
|---|---|
pk |
Shortest alias |
kp |
Alias |
kill-port |
Alias. Clashes with the separate kill-port npm package if both are installed globally |
port-kill |
Full name, never collides with other tools |
| Argument | Example | Meaning |
|---|---|---|
<port> |
pk 3000 |
A single port, 1–65535 |
<start>-<end> |
pk 3000-3005 |
An inclusive range |
| several | pk 3000 5173 3000-3005 |
Any mix of ports and ranges. Duplicates are ignored |
| none | pk |
Interactive picker (see below) |
Inspect what holds your ports without killing anything:
Free several ports at once. Each result says how the process was stopped, and a summary closes the run:
- The table fits your terminal: the command column shrinks (and is cut with
…) to the available width, and colors followNO_COLORand are off when output is piped.ACCESSis green forlocalhost onlyand yellow forall interfaces. Containers show their id,containerand their image. localhost onlymeans the port is bound to127.0.0.1/::1.all interfaces(0.0.0.0,::,*) means other machines on the network can reach it. Any other bind address is printed as is.userandcmdcome fromps, so they appear on Linux and macOS only. Windows shows the process name, PID and bind address. Commands longer than 100 characters are shortened.- Command lines can contain secrets such as tokens passed as arguments.
psshows them to any local user already, but keep it in mind before pastingpk --infooutput into a bug report. - The
Freed N of M portssummary appears when more than one port was handled. A failure sets exit code1.
| Flag | Alias | Description |
|---|---|---|
--info |
-i |
Show the process, bind address, owner and command using the port without killing it |
--force |
-f |
Immediately force-kill the process (SIGKILL / taskkill /F / docker kill) |
--children |
-c |
Also stop everything running under the process, such as workers behind a server. Linux/macOS only, because taskkill /T already does this on Windows |
--tree |
Stop the process's parent and everything under that (which includes --children), for when the port is held by a helper of a larger app. Linux/macOS only. Never stops pk's own terminal, init, a shell or a session manager. Docker containers are unaffected. It lists the parents it would stop and asks [y/N] first (without a terminal it refuses unless you pass --yes) |
|
--yes |
-y |
Skip the --tree question |
--version |
-v |
Print the installed version |
--help |
-h |
Display usage instructions and options |
Flags can go before or after the ports and can be combined: pk 3000 -i, pk -f 3000-3005.
By default pk stops only the process that holds the port, not what runs under it and not the app that started it. Many apps hold their port in a helper (VS Code's extension host, pgAdmin's server), so the window or app can stay open after its port is freed. --children also stops what runs under the holder. --tree stops the parent as well, which can close the whole app and lose unsaved work, so it lists the parents and asks before doing it.
Running pk with no ports lists every port in use as a checkbox list, so you tick exactly the ones to free:
pk Select ports to free 2 of 3 selected
PORT PROCESS PID/ID USER ACCESS COMMAND
─────────────────────────────────────────────────────────────────────────
❯ [x] :3000 node 4121 alice localhost only node server.js
[ ] :5173 node 4188 alice localhost only vite
[x] :8080 api a1b2c3d4e5f6 container all interfaces nginx:1.27
─────────────────────────────────────────────────────────────────────────
[ ] Also stop what it started --children
[ ] Also close the app that started it --tree
user alice · cmd node server.js --port 3000
↑↓ move · space toggle · a all · c children · t app · enter free selected · q quit
The two options under the list work like the ports: move onto one with ↑/↓ and press Space, or press its key from anywhere. Ticking the app also shows the children as included. Closing the app still lists the parents and asks [y/N] first, and the flags --children / --tree just start with the boxes ticked. The options are hidden on Windows, where children are always stopped and --tree is not supported. The typed prompt has no checkboxes, so there you need the flags.
The highlighted row is drawn as a selection bar, the line under the list shows the full owner and command of that row, and a ↑ n more / ↓ n more marker appears in the rule when the list is taller than your terminal.
| Key | Action |
|---|---|
↑ / ↓ (or k / j) |
Move the cursor |
Space |
Tick or untick the port under the cursor |
a |
Tick all, or untick all if everything is already ticked |
c |
Tick or untick Also stop what it started (same as --children) |
t |
Tick or untick Also close the app that started it (same as --tree) |
Enter |
Free the ticked ports (nothing ticked = cancel) |
q, Esc or Ctrl+C |
Cancel without killing anything |
Long lists scroll to fit your terminal. --force, --children and --tree also apply here (pk -f, pk --tree). pk --info prints the same list without prompting. With no terminal attached (for example in a script or CI), pk prints the help instead of waiting for input.
Typed prompt: when raw keypresses are not available (for example output is piped, as in pk | tee out.txt), the list is numbered instead and you type your choice:
| Input | Frees |
|---|---|
1 |
Entry 1 |
1 3 or 1,3 |
Entries 1 and 3 |
2-4 |
Entries 2 to 4 |
a or all |
Every listed entry |
| Enter (empty) | Nothing, cancels |
Exit 0 |
Success, including when a port was already free |
Exit 1 |
Bad arguments, no tool available to list ports, or a process or container could not be stopped (for example permission denied) |
NO_COLOR |
Set to any non-empty value to disable colored output |
Ensure your dev port is always free before starting your server:
{
"scripts": {
"predev": "npx @majidev-org/port-kill-cli 3000",
"dev": "next dev"
}
}pk runs every system tool without a shell, validates ports as integers in 1–65535, and strips control, bidi and zero-width characters from process names before printing them (a process can name itself anything, including terminal escape codes). If no tool can list ports it fails with an error instead of claiming a port is free. On Windows, commands are resolved from System32 so a stray netstat.exe in the current folder is never run. Killing another user's process needs sudo or Administrator rights. See SECURITY.md for the full list and how to report a vulnerability.
Bug reports and ideas are welcome in the issue tracker. To work on the code, see CONTRIBUTING.md and TESTING.md.
pk terminates processes, so read the Terms of Use before using it on systems you don't own. It collects no data; see the Privacy Policy. Vulnerabilities go through the Security Policy.


