# How to write an asynchronous plugin?

**URL:** <https://discuss.kakoune.com/t/how-to-write-an-asynchronous-plugin/2955>\
**Category:** Help\
**Tags:** plugins\
**Created:** [August 5, 2026, 4:12pm UTC](https://discuss.kakoune.com/t/how-to-write-an-asynchronous-plugin/2955 "2026-08-05T16:12:30Z")\
**Posts on this page:** 1\
**Showing post:** 4

<div class="post-metadata">

**Author:** ![alexherbo2](https://discuss.kakoune.com/user_avatar/discuss.kakoune.com/alexherbo2/32/1140_2.png) [@alexherbo2](https://discuss.kakoune.com/u/alexherbo2)\
**Post date:** [August 6, 2026, 3:49pm UTC](https://discuss.kakoune.com/t/how-to-write-an-asynchronous-plugin/2955/4 "2026-08-06T15:49:44Z")

</div>

Here’s an example.

1. Open a new terminal and run `sh followname.sh`
2. Open a new terminal and run `kak -n -e "source followname.kak"`
3. Type `:edit some_file<ret>` and see `some_file` being renamed as `some_file.renamed_by_followname`

`followname.kak`

```kak
hook g BufCreate ".*" %{
  echo -to-file "followname.fifo" -quoting "shell" "your_followname_message_type" "%val{session}" "%val{bufname}"
}

```

`followname.sh`

```sh
set -e
mkfifo "followname.fifo" "followname.kak_buflist.fifo" "followname.kak_client_list.fifo"
trap "rm -vf 'followname.fifo' 'followname.kak_buflist.fifo' 'followname.kak_client_list.fifo'" EXIT
echo "followname.fifo created"
echo "followname.kak_buflist.fifo created"
echo "followname.kak_client_list.fifo created"
echo "followname started"
while :
do
  echo "waiting for message..."
  eval set -- "$(cat 'followname.fifo')"
  message_type=$1
  case "$message_type" in
    "your_followname_message_type")
      kak_session=$2
      kak_bufname=$3
      echo "your request is: 'your_followname_message_type'"
      echo "got '$kak_session' as session name"
      echo "got '$kak_bufname' as buffer name"
      printf "echo -end-of-line -to-file '%s' -quoting 'shell' -- %%val{buflist}; echo -end-of-line -to-file '%s' -quoting 'shell' -- %%val{client_list}" "followname.kak_buflist.fifo" "followname.kak_client_list.fifo" |
      kak -p "$kak_session"
      echo "your buffer list is:"
      cat "followname.kak_buflist.fifo"
      echo "your client list is:"
      cat "followname.kak_client_list.fifo"
      printf "eval -buffer '%s' -verbatim rename-buffer -- '%s'" "$kak_bufname" "$kak_bufname.renamed_by_followname" |
      kak -p "$kak_session"
      printf "old_name=%s\\nnew_name=%s\\n" "$kak_bufname" "$kak_bufname.renamed_by_followname"
      ;;
    *)
      echo "Unknown request: '$message_type'"
      ;;
  esac
done

```

---

_[View the full topic](https://discuss.kakoune.com/t/how-to-write-an-asynchronous-plugin/2955)._
