Send commands to the terminal pane in a coding session via kitty remote control. Use when you need to run shell commands in the terminal pane, check command output, or interact with the terminal window alongside the coding agent.
When running inside a coding session, $CODING_SESSION_TERMINAL_KITTY_WINDOW_ID
identifies the terminal pane. Use kitty's remote control API to interact with it.
Verify the terminal window ID is available:
echo "$CODING_SESSION_TERMINAL_KITTY_WINDOW_ID"
If empty, there is no coding session terminal pane available.
Send text to the terminal pane (include \n to execute):
kitty @ send-text --match id:$CODING_SESSION_TERMINAL_KITTY_WINDOW_ID "ls -la\n"
Send multiple commands sequentially:
kitty @ send-text --match id:$CODING_SESSION_TERMINAL_KITTY_WINDOW_ID "cd src && make build\n"
Get the terminal pane's current working directory and foreground process:
kitty @ ls | python3 -c "
import json, sys
data = json.load(sys.stdin)
wid = $CODING_SESSION_TERMINAL_KITTY_WINDOW_ID
for osw in data:
for tab in osw['tabs']:
for w in tab['windows']:
if w['id'] == wid:
print('cwd:', w['cwd'])
procs = [p['cmdline'] for p in w.get('foreground_processes', [])]
print('procs:', procs)
"
Retrieve the last N lines of scrollback from the terminal pane:
kitty @ get-text --match id:$CODING_SESSION_TERMINAL_KITTY_WINDOW_ID --extent last_cmd_output
Other --extent options:
screen — visible screen contentall — full scrollback buffer (can be large)last_cmd_output — output from the last command (requires shell integration)Focus the terminal pane (e.g., before sending interactive commands):
kitty @ focus-window --match id:$CODING_SESSION_TERMINAL_KITTY_WINDOW_ID
rm -rf, git reset --hard, etc.)
without explicit user confirmation.send-text simulates typing — if the terminal has a running
process (not a shell prompt), the text goes to that process's stdin.