# Getting a client's tty

**URL:** <https://discuss.kakoune.com/t/getting-a-clients-tty/1276>\
**Category:** Help\
**Tags:** terminal\
**Created:** [September 19, 2020, 4:03pm UTC](https://discuss.kakoune.com/t/getting-a-clients-tty/1276 "2020-09-19T16:03:17Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![useredsa](https://discuss.kakoune.com/user_avatar/discuss.kakoune.com/useredsa/32/419_2.png) [@useredsa](https://discuss.kakoune.com/u/useredsa)\
**Post date:** [September 19, 2020, 4:03pm UTC](https://discuss.kakoune.com/t/getting-a-clients-tty/1276/1 "2020-09-19T16:03:17Z")

</div>

I want to be able to write escape codes to the terminal to use kitty’s [clipboard integration](https://sw.kovidgoyal.net/kitty/protocol-extensions.html?highlight=clipboard#pasting-to-clipboard). I could potentially do this using `echo -to-file /dev/tty` but the problem is that commands are executed in the context of the server, which may not even be running inside a terminal.

My current solution is using the `tty` command outside Kakoune to get the specific file I need (like `/dev/pts/0`), but being able to do it inside kakoune would be nice. Any tips?

---

<div class="post-metadata">

**Author:** ![eraserhd](https://discuss.kakoune.com/user_avatar/discuss.kakoune.com/eraserhd/32/15_2.png) [@eraserhd](https://discuss.kakoune.com/u/eraserhd)\
**Post date:** [September 19, 2020, 4:23pm UTC](https://discuss.kakoune.com/t/getting-a-clients-tty/1276/2 "2020-09-19T16:23:06Z")

</div>

I currently have kitty configured for a single user session listening on a unix socket. This works well for me, and allows scripting from systemd and i3 or launchd and skhd and yabai.

A nice bit is that you can access the kitty window id from `$client_env_KITTY_*`

---

<div class="post-metadata">

**Author:** ![useredsa](https://discuss.kakoune.com/user_avatar/discuss.kakoune.com/useredsa/32/419_2.png) [@useredsa](https://discuss.kakoune.com/u/useredsa)\
**Post date:** [September 19, 2020, 5:14pm UTC](https://discuss.kakoune.com/t/getting-a-clients-tty/1276/3 "2020-09-19T17:14:37Z")

</div>

And what do you do when you ssh to another machine?

EDIT: still, being able to access a clients tty would be very nice.

EDIT2: But actually, that gave me the idea of exporting a TTY variable in my `.bashrc`. I didn’t know about `client_env_`.

---

<div class="post-metadata">

**Author:** ![eraserhd](https://discuss.kakoune.com/user_avatar/discuss.kakoune.com/eraserhd/32/15_2.png) [@eraserhd](https://discuss.kakoune.com/u/eraserhd)\
**Post date:** [September 21, 2020, 12:08pm UTC](https://discuss.kakoune.com/t/getting-a-clients-tty/1276/4 "2020-09-21T12:08:52Z")

</div>

I guess I’ve never needed any of the “extra” functionality when ssh’d to another machine. The terminal escape codes and kittens still work, so I assume everything I do via ssh has a a terminal accessible.

Although right now, I have a separate kakoune session on each machine. I want to figure out how to merge them somehow, but have not figured out a decent way to do this. It would involve forwarding Kakoune’s session socket over ssh and having all sessions mount the same filesystems or something… hrmm

---

<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:** [July 23, 2026, 11:10pm UTC](https://discuss.kakoune.com/t/getting-a-clients-tty/1276/5 "2026-07-23T23:10:50Z")

</div>

I use the following technique in my kakrc.

```auto
set window terminal_tty %sh{
  printf '/dev/'
  ps -o 'tty=' -p "$kak_client_pid" |
  awk '
    {
      print $1
    }
  '
}

```
