Zellij Events

Since 0.46.1, Zellij provides a top-level events command that prints what happens in a session as it happens: panes and tabs opening, closing, being focused, renamed or moved, input mode changes, clients attaching and detaching, and the session being renamed or ending. Each event is printed as one JSON object per line, which makes it easy to react to changes from a script or to drive an external status bar.

To stream the contents of panes rather than changes to the session, see Zellij Subscribe.



Usage

zellij [--session <SESSION_NAME>] events [OPTIONS]

When run inside a Zellij pane, the events of that pane's session are printed. Outside of Zellij, the only running session is used, or the session given with --session (which must come before events).

The command keeps running until the session ends or it is stopped (eg. with Ctrl c).

Options

-t, --type <TYPE>...       Only print events of these types (eg. --type pane_focused tab_created)
-p, --pane-id <PANE_ID>... Only print events about these panes. Accepts terminal_N, plugin_N,
                           or bare integer N (equivalent to terminal_N)
    --tab-id <TAB_ID>...   Only print events about these tabs or the panes in them (tab ids,
                           as shown by `zellij action list-tabs`)
    --no-initial-state     Do not print the initial_state event when the command starts

Each option takes one or more values, and can be given more than once.

Filtering

  • --type keeps only the listed event types.
  • --pane-id and --tab-id keep only the events about the listed panes, the listed tabs, or the panes in the listed tabs. An event matches if it is about any of them.
  • When --type is combined with --pane-id or --tab-id, an event must match both.
  • Events that are not about a pane or a tab (mode_changed, client_attached, client_detached, session_renamed and session_ending) are not removed by --pane-id or --tab-id.
  • pane_moved matches the tab the pane moved from and the tab it moved to.
  • With --pane-id or --tab-id, the initial_state event only lists the matching panes and their tabs.

Output

Every line is a JSON object whose event key holds the event name:

{"event":"tab_focused","client_id":1,"tab_id":1,"previous_tab_id":0}
  • Pane ids are strings, eg. "terminal_1" or "plugin_2".
  • Tab ids are numbers that stay the same when tabs are moved, the same ids shown by zellij action list-tabs. The place of a tab in the tab bar is its position, starting at 0.
  • client_id is a number identifying a connected user (see zellij action list-clients). Events about focus and input modes are reported separately for each connected user.
  • Input modes are lowercase names, eg. normal, locked, pane, tab, resize, scroll, search, entersearch, renametab, renamepane, renamesession, session, move, prompt or tmux.
  • Fields that have no value are null.

Events

initial_state

Printed first, describing the session at the moment the command starts. It is printed whatever --type is given, unless --no-initial-state is used.

{"event":"initial_state","session_name":"my-session","tabs":[...],"panes":[...],"clients":[...]}
FieldDescription
session_nameName of the session
tabsList of tabs, in tab bar order
panesList of panes, including plugin panes such as the tab bar
clientsList of clients

Tab

{"tab_id":0,"position":0,"name":"Tab #1","is_fullscreen_active":false,"is_sync_panes_active":false,"are_floating_panes_visible":false}
FieldDescription
tab_idId of the tab
positionPlace of the tab in the tab bar, starting at 0
nameName of the tab
is_fullscreen_activeWhether a pane in the tab is fullscreen
is_sync_panes_activeWhether input is sent to all panes of the tab
are_floating_panes_visibleWhether the floating panes of the tab are shown

Pane

{"pane_id":"terminal_1","tab_id":0,"title":"~/project","is_plugin":false,"is_floating":false,"is_fullscreen":false,"is_suppressed":false,"is_selectable":true,"exited":false,"exit_status":null,"terminal_command":null,"plugin_url":null}
FieldDescription
pane_idId of the pane
tab_idId of the tab the pane is in
titleTitle of the pane
is_pluginWhether the pane is a plugin
is_floatingWhether the pane is floating
is_fullscreenWhether the pane is fullscreen
is_suppressedWhether the pane is hidden behind another pane (eg. a pane replaced with --in-place)
is_selectableWhether the pane can be focused (false for bars such as the tab bar and status bar)
exitedWhether the command of a command pane has exited
exit_statusExit status of that command, if known
terminal_commandThe command and arguments of a command pane
plugin_urlThe location of a plugin pane, eg. zellij:tab-bar

Client

{"client_id":1,"is_web_client":false,"tab_id":0,"pane_id":"terminal_1","mode":"normal"}
FieldDescription
client_idId of the client
is_web_clientWhether the client is connected through the web client
tab_idId of the tab the client is on
pane_idId of the pane the client has focused
modeThe client's input mode

Pane events

EventWhenFields
pane_openedA pane is openedpane (a pane)
pane_closedA pane is closedpane_id, tab_id
pane_focusedA client focuses a paneclient_id, pane_id, tab_id, previous_pane_id
pane_renamedThe title of a pane changes, either because it was renamed or because the program in it set its titlepane_id, tab_id, title, previous_title
pane_movedA pane is moved to another tabpane_id, tab_id, previous_tab_id
pane_floating_changedA pane becomes floating or tiledpane_id, tab_id, is_floating
pane_fullscreen_changedA pane enters or leaves fullscreenpane_id, tab_id, is_fullscreen
pane_exitedThe command of a command pane exits and the pane stays openpane_id, tab_id, exit_status
pane_cwd_changedThe working directory of a terminal pane changespane_id, tab_id, cwd
pane_command_changedThe program running in the foreground of a terminal pane changespane_id, tab_id, command, is_foreground

In pane_command_changed, command is the program and its arguments as a list of strings (eg. ["vim","notes.md"]). When the pane goes back to its shell, is_foreground is false and command is the shell.

previous_pane_id and exit_status can be null, as can tab_id in pane_closed, pane_cwd_changed and pane_command_changed.

{"event":"pane_opened","pane":{"pane_id":"terminal_2","tab_id":0,"title":"Pane #2","is_plugin":false,"is_floating":false,"is_fullscreen":false,"is_suppressed":false,"is_selectable":true,"exited":false,"exit_status":null,"terminal_command":null,"plugin_url":null}}
{"event":"pane_focused","client_id":1,"pane_id":"terminal_2","tab_id":0,"previous_pane_id":"terminal_1"}
{"event":"pane_renamed","pane_id":"terminal_2","tab_id":0,"title":"logs","previous_title":"Pane #2"}
{"event":"pane_cwd_changed","pane_id":"terminal_2","tab_id":0,"cwd":"/home/me/project"}
{"event":"pane_command_changed","pane_id":"terminal_2","tab_id":0,"command":["vim","notes.md"],"is_foreground":true}
{"event":"pane_exited","pane_id":"terminal_3","tab_id":0,"exit_status":1}
{"event":"pane_closed","pane_id":"terminal_2","tab_id":0}

Tab events

EventWhenFields
tab_createdA tab is openedtab (a tab)
tab_closedA tab is closedtab_id, name
tab_renamedA tab is renamedtab_id, name, previous_name
tab_movedA tab is moved to another place in the tab bartab_id, position, previous_position
tab_focusedA client switches to a tabclient_id, tab_id, previous_tab_id

previous_tab_id can be null. When a tab is closed, a pane_closed event is printed for each of its panes before tab_closed.

{"event":"tab_created","tab":{"tab_id":1,"position":1,"name":"Tab #2","is_fullscreen_active":false,"is_sync_panes_active":false,"are_floating_panes_visible":false}}
{"event":"tab_focused","client_id":1,"tab_id":1,"previous_tab_id":0}
{"event":"tab_renamed","tab_id":1,"name":"build","previous_name":"Tab #2"}
{"event":"tab_moved","tab_id":1,"position":0,"previous_position":1}
{"event":"tab_closed","tab_id":1,"name":"build"}

Mode, client and session events

EventWhenFields
mode_changedA client's input mode changesclient_id, mode, previous_mode
client_attachedA user attaches to the sessionclient_id, is_web_client
client_detachedA user detaches from the sessionclient_id
session_renamedThe session is renamedname, previous_name
session_endingThe session is ending. This is always the last line printednone

previous_mode can be null. When a user attaches, client_attached is followed by tab_focused, pane_focused and mode_changed events for that user.

{"event":"mode_changed","client_id":1,"mode":"locked","previous_mode":"normal"}
{"event":"client_attached","client_id":3,"is_web_client":false}
{"event":"client_detached","client_id":3}
{"event":"session_renamed","name":"work","previous_name":"my-session"}
{"event":"session_ending"}

Exit Codes

Exit codeMeaning
0The session ended, or the output was closed (eg. the program reading it exited)
1No session was found, eg. no session is running, the --session given does not exist, or several sessions are running and none was chosen
2An error, eg. a wrong flag or event type, an invalid pane id, or a session running a version of Zellij that does not support events

Listening to a Different Session

To listen to a session other than the current one, use the global --session flag:

$ zellij --session my-background-session events

This is especially useful when combined with background sessions.

Examples

Print every event of the current session:

$ zellij events

Print only focus changes, without the initial state:

$ zellij events --type pane_focused tab_focused --no-initial-state

Follow a single pane:

$ zellij events --pane-id terminal_1

Follow everything that happens in a tab:

$ zellij events --tab-id 2

Print the name of each tab as it is opened:

$ zellij events --type tab_created --no-initial-state | jq --unbuffered -r '.tab.name'

Wait for a command pane to finish and print its exit status:

$ read -r status < <(zellij events --type pane_exited --pane-id terminal_3 --no-initial-state | jq --unbuffered -r '.exit_status')
$ echo "$status"

Show a notice whenever a command pane fails:

$ zellij events --type pane_exited --no-initial-state \
    | jq --unbuffered -r 'select(.exit_status != 0) | .pane_id' \
    | while read -r pane; do zellij prompt notify "$pane failed"; done

Print the current input mode, for an external status bar:

$ zellij events --type mode_changed --no-initial-state | jq --unbuffered -r '.mode'

Print the folder a pane is in each time it changes:

$ zellij events --type pane_cwd_changed --pane-id terminal_1 --no-initial-state | jq --unbuffered -r '.cwd'