Show HN: Sonar – A tiny CLI to see and kill whatever's running on localhost
https://github.com/RasKrebs/sonar 3000 wud (getwud/wud:latest) wud getwud/wud:latest 3000 http://localhost:3000
3001 dockhand (fnsys/dockhand:latest) dockhand fnsys/dockhand:latest 3000 http://localhost:3001So I built this lightweight CLI. Single binary, no dependencies. It shows everything listening on localhost with process names, Docker container info, clickable URLs etc.
Sure there are workarounds, but none that satisfied my need for a short, easily rememberable command. Also nothing really has the same satisfaction as running sonar kill 3000 — it just feels nice. I’ve already been approached by a few agent orchestration tools that have been struggling with the same thing. It's really useful when you have multiple agents running, but it's not built for just that use case, I have also find it handy when killing off all containers after a failed cleanup and so on. Also know that MCPs are dead and CLIs are the new thing in agentic coding, this might be a useful tool for Claude, particularly when a compose process exits before all containers are stopped.
Open for contributions, ideas and feedback.
https://github.com/clutchski/dotfiles/blob/main/home/bin/por...
For the even less patient there's also this (not mine): https://github.com/jkfran/killport
So why doesn't everyone run local services over Unix sockets?
The only problems: 1) web browsers don't support AF_UNIX URI scheme, and 2) ancient versions of Java don't have built-in APIs for AF_UNIX sockets.
That's it. For these trivial reasons, we've beat our head against arbitrary opaque numbers for decades.
And so, for want of a nail, the Unix was lost.
lk() {
if [ $# -eq 0 ]; then
local output=$(sudo lsof -iTCP -sTCP:LISTEN -n -P)
elif [ $# -eq 1 ]; then
local output=$(sudo lsof -iTCP -sTCP:LISTEN -n -P | grep -i --color=always $1)
else
echo "find and kill processes listening on ports. Usage: lk [pattern]"
return 1
fi
if [ -z "$output" ]; then
echo "No listening processes found."
return 0
fi
# Show header + results
echo "$(sudo lsof -iTCP -sTCP:LISTEN -n -P | head -1)"
echo "$output"
echo ""
# Extract unique PIDs (skip the header row if no grep was applied)
local pids=($(echo "$output" | awk '{print $2}' | grep -E '^[0-9]+$' | sort -u))
if [ ${#pids[@]} -eq 0 ]; then
echo "No PIDs found."
return 0
fi
echo "PIDs to kill: ${pids[*]}"
echo -n "Kill these ${#pids[@]} process(es)? [y/N] "
read -r confirm
if [[ "$confirm" =~ ^[Yy]$ ]]; then
for pid in "${pids[@]}"; do
echo "Killing PID $pid..."
sudo kill -9 $pid
done
echo "Done."
else
echo "Aborted."
fi
}