# Target window/buffer in client

**URL:** <https://discuss.kakoune.com/t/target-window-buffer-in-client/2812>\
**Category:** Help\
**Created:** [January 12, 2026, 3:07pm UTC](https://discuss.kakoune.com/t/target-window-buffer-in-client/2812 "2026-01-12T15:07:01Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Maxxus](https://discuss.kakoune.com/user_avatar/discuss.kakoune.com/maxxus/32/889_2.png) [@Maxxus](https://discuss.kakoune.com/u/Maxxus)\
**Post date:** [January 12, 2026, 3:07pm UTC](https://discuss.kakoune.com/t/target-window-buffer-in-client/2812/1 "2026-01-12T15:07:01Z")

</div>

I’m integrating some long running asynchronous processes (think ci, linters, style checkers, etc…) and I’ve set them up to send **eval -client** commands to create highlighters as issues are found. It works as long as I don’t switch buffers between the start and result of the external process, otherwise the highlighter gets applied to the wrong window/buffer. As a minimal example based on Kakoune’s interfacing document, run this in one buffer then switch to another buffer before the sleep expires.

```auto
:nop %sh{ {
    sleep 10
    echo "eval -client '$kak_client' 'execute-keys %{ohello wrong buffer<esc>}'" |
        kak -p ${kak_session}
} > /dev/null 2>&1 < /dev/null & }

```

Is there a way to target the window scope for a specific buffer for a specific client?

---

<div class="post-metadata">

**Author:** ![Maxxus](https://discuss.kakoune.com/user_avatar/discuss.kakoune.com/maxxus/32/889_2.png) [@Maxxus](https://discuss.kakoune.com/u/Maxxus)\
**Post date:** [January 12, 2026, 4:25pm UTC](https://discuss.kakoune.com/t/target-window-buffer-in-client/2812/2 "2026-01-12T16:25:58Z")

</div>

As always seems to be the case, I stumbled on to a solution after finally pulling the trigger on a post. Using **execute-keys -draft** with a **:buffer** seems to do the trick.

```auto
:nop %sh{ {
    sleep 10
    echo "eval -client '$kak_client' 'execute-keys -draft %{:buffer $kak_bufname<ret>ohello right buffer<esc>}'" |
        kak -p ${kak_session}
} > /dev/null 2>&1 < /dev/null & }

```

---

<div class="post-metadata">

**Author:** ![Screwtapello](https://discuss.kakoune.com/user_avatar/discuss.kakoune.com/screwtapello/32/12_2.png) [@Screwtapello](https://discuss.kakoune.com/u/Screwtapello)\
**Post date:** [January 12, 2026, 11:03pm UTC](https://discuss.kakoune.com/t/target-window-buffer-in-client/2812/3 "2026-01-12T23:03:07Z")

</div>

There’s also `eval -buffer $kak_bufname` which lets you execute KakScript in the context of an open buffer, whether or not it’s visible in any particular client.

---

<div class="post-metadata">

**Author:** ![Maxxus](https://discuss.kakoune.com/user_avatar/discuss.kakoune.com/maxxus/32/889_2.png) [@Maxxus](https://discuss.kakoune.com/u/Maxxus)\
**Post date:** [January 13, 2026, 7:13pm UTC](https://discuss.kakoune.com/t/target-window-buffer-in-client/2812/4 "2026-01-13T19:13:04Z")

</div>

The problem I’ve had with **eval** is that it can’t target the window scope.

```auto
eval -client client0 %[eval -buffer test.c %[ set-option window custom_hl_range various_matching_ranges] ]

```

fails with

```auto
Error: 1:1: 'eval': 1:2: 'eval': 1:2: 'set-option': no window in context

```

EDIT: And again I stumble on the solution after posting. If you reverse the nested **eval** s it works.

```auto
eval -buffer test.c %[eval -client client0 %[ set-option window custom_hl_range various_matching_ranges] ]

```
