Show HN: Sonar – A tiny CLI to see and kill whatever's running on localhost

129 points - yesterday at 9:59 AM

Source

Comments

derodero24 today at 2:42 AM
Can never remember the right lsof incantation for this and end up googling it every time. The Docker container detection is a nice touch — half the time whatever's squatting on port 3000 is some container I forgot to stop two days ago.
diablevv yesterday at 9:08 PM
Nice — the use case for this is immediately obvious. I've spent more time than I care to admit running `lsof -i :PORT` or `netstat -tulpn | grep PORT` trying to figure out what's squatting on a port before running a dev server. Having a clean CLI for this with kill support is the kind of small tool that earns a permanent spot in your toolkit. Added to my dotfiles setup.
mrbonner yesterday at 7:46 PM
Hey, thanks for sharing this. Your app inspires me to take a look at Go, again! I've been searching for another primary language to learn. My primary used to be Java at $day$ job and now Python for ML/AI. I love Python but still feel insecure given the lack of static typing. I look at TypeScript as well, especially in the context of Bun runtime. I decided it may not be for me, not the language, but the ecosystem around it.
raskrebs yesterday at 9:59 AM
I always have a bunch of local projects running, particularly during the weekend where I'm rarely working on one thing at a time. A big pain of mine was constantly running into port: Redis from one project blocking another, orphaned dev servers from old worktrees, Docker containers I forgot about. The usual fix is lsof -iTCP | grep ..., then figuring out what the PID actually is, then killing it. But I always forget the command, and it doesn’t really include all the information that I like.

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

klaushardt yesterday at 12:46 PM
Would be nice to have a flag to customize the URL displayed for Docker containers. I connect to my host via Tailscale, but I can’t open links with localhost. It would be helpful to have a parameter that allows us to choose a network device or specify an IP address to display.

    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:3001
mustafa0x yesterday at 6:16 PM
Nice util. It should be possible to kill inline.

I like clack/prompts. See its multiselect API.

https://github.com/bombshell-dev/clack/tree/main/packages/pr...

deleted yesterday at 11:25 PM
maciejj yesterday at 2:51 PM
Nice! I always forget the lsof flags and end up googling them every time. Would be cool if it could run in the system tray and show what's running on your ports at a glance. Also, the name had me thinking SonarQube at first, might be worth considering a rename to avoid the confusion.
chwzr yesterday at 1:43 PM
i have this in my .zshrc which provides same functionality:

  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
  }
fcoury yesterday at 4:52 PM
We live in crazy times. I wanted to add a PID to the list for my personal use and since I use Rust way more than Go, I decided to one-shot one app, and Codex indeed one shotted it, wow.

https://github.com/fcoury/sonars

koinedad yesterday at 11:09 PM
I run lsof a good amount. This is a great idea.
clutchski yesterday at 1:51 PM
pdimitar yesterday at 1:49 PM
I am absolutely installing this and starting to use it daily!

For the even less patient there's also this (not mine): https://github.com/jkfran/killport

RonanSoleste yesterday at 3:51 PM
I just have an alias in my .bashrc :)
mfkrause yesterday at 2:07 PM
I always find myself going through my zsh history for `lsof`. Will definitely check this out, seems interesting (even though I'm generally reluctant of installing third-party tools for such jobs).
moezd yesterday at 1:24 PM
Sonar as in SonarQube? That's an interesting choice for a name :)
kohexo yesterday at 5:32 PM
Honestly, pretty cool. I was wondering if something like this existed. Right now I have scripts to kill the ports I use consistently to avoid issues when developing. Kudos!
quotemstr yesterday at 4:13 PM
Christ Almighty I hate our industry practice of binding to some inscrutable port number on localhost. Unix domain sockets aren't that hard! They're secure against all sorts of attacks and more convenient to boot. Instead of connecting to a number, you connect to a file. An ordinary file, with an ordinary name you can mv, chmod, and rm. Boring on a good way.

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.

Bradd3rs yesterday at 11:22 AM
love this, i get tired of spamming lsof -i tcp:xxxx
frankdenbow yesterday at 1:14 PM
love this, happens too often
jkestner yesterday at 4:47 PM
I read the readme. :) Very nice. Thoughtful features. Get this on Homebrew!
rrojas-nexus yesterday at 9:12 PM
[dead]
aplomb1026 yesterday at 5:31 PM
[dead]
takahitoyoneda yesterday at 1:38 PM
[dead]
olivercoleai yesterday at 2:04 PM
[dead]
abitabovebytes yesterday at 6:26 PM
[dead]
Servant-of-Inos yesterday at 10:26 AM
[dead]