How to write an asynchronous plugin?

I’m attempting to write my first plugin - followname - which tracks files as they get moved or renamed. I’ve done the hard part of making a program which watches for rename events using inotify and outputs the new name to stdout when they occur, but I’m having trouble getting Kakoune to interpret that information.

At first I thought it would be as simple as this:

hook global BufCreate .* %{
    evaluate-commands %sh{
        $HOME/src/followname/followname $kak_buffile | awk '{print "edit "$0}'
    }
}

But of course the %sh expansion can’t get evaluated until the program terminates, so I learned about $kak_command_fifo which seemed like the answer. But this is as far as I manged to get:

define-command followname '
    nop %sh{
        $HOME/src/followname/followname $kak_buffile | while read line; do
        	echo edit \"$line\" > $kak_command_fifo
        	echo info \"moved to $line\" > $kak_command_fifo
        done
    }
'

When I run this command I can see it working, Kakoune jumps to the new file whenever I rename it, but it locks interaction with waiting for shell command to finish. (It also spawns a new process every time the file is renamed, but that’s another matter)
I found this post from 2019 which lists some hacks for running processes in the background, with that I was able to get this monstrocity:

define-command followname '
    nop %sh{ {
        $HOME/src/followname/followname $kak_buffile | while read line; do
        	echo "eval -client $kak_client edit \"$line\"" | kak -p ${kak_session}
        	echo "eval -client $kak_client info \" moved to $line\"" | kak -p ${kak_session}
        done
    } > /dev/null 2>&1 < /dev/null & }
'

Which almost works; the “info” part doesn’t seem to work, and I have to run the command manually as when I run it from a BufCreate hook, $kak_client appears to be empty. It also creates a new buffer every time the file is renamed and leaves to old one open, which isn’t ideal. And there’s probably at least one other dumb thing that I haven’t noticed yet.

I’m sure what I’m trying to do isn’t as complicated as I’m making it, but I don’t know enough about Kakoune to figure it out.