fix(hooks): use socket-based Kitty remote control to prevent escape sequence leaks#493
Open
Mutdogus wants to merge 1 commit intodanielmiessler:mainfrom
Open
fix(hooks): use socket-based Kitty remote control to prevent escape sequence leaks#493Mutdogus wants to merge 1 commit intodanielmiessler:mainfrom
Mutdogus wants to merge 1 commit intodanielmiessler:mainfrom
Conversation
…equence leaks
When PAI hooks use `kitty @` commands without specifying a socket, Kitty
communicates via escape sequences. In subprocess contexts (how hooks run),
these escape sequences cannot be properly consumed, causing them to leak
into the terminal output as visible "P@kitty-cmd" garbage text.
This affects:
- UpdateTabTitle.hook.ts
- SetQuestionTab.hook.ts
- QuestionAnswered.hook.ts
- handlers/tab-state.ts
The fix adds a `getKittySocket()` helper that checks for:
1. KITTY_LISTEN_ON environment variable
2. Default socket at /tmp/kitty-$USER
All kitty/kitten commands now use `--to <socket>` flag for socket-based
communication, which doesn't suffer from escape sequence leaks.
Users need to configure Kitty with:
```
allow_remote_control socket-only
listen_on unix:/tmp/kitty-$USER
```
Fixes terminal artifacts like:
P@kitty-cmd{"ok": false, "error": "Remote control is disabled"}
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
A13xSM
approved these changes
Feb 2, 2026
A13xSM
left a comment
There was a problem hiding this comment.
This solution worked perfectly for me. It not only resolved the escape sequence leaks but also resolved a buffering issue where PAI would hang when loading, requiring input to refresh the buffer. Great fix.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes P@kitty-cmd escape sequence artifacts appearing in terminal when using PAI with Kitty terminal.
Problem
When PAI hooks use
kitty @commands without a socket, Kitty responds via escape sequences. Since hooks run as subprocesses, these sequences cannot be properly consumed and leak into the terminal as visible garbage:This affects anyone using PAI with Kitty terminal.
Root Cause
Kitty's
allow_remote_control yesmode uses escape sequences for IPC. When hooks run as detached subprocesses:Solution
getKittySocket()helper to all tab-related hooks--to <socket>flag for socket-based communicationFiles Changed
Packs/pai-hook-system/src/hooks/UpdateTabTitle.hook.tsPacks/pai-hook-system/src/hooks/SetQuestionTab.hook.tsPacks/pai-hook-system/src/hooks/QuestionAnswered.hook.tsPacks/pai-hook-system/src/hooks/handlers/tab-state.tsUser Configuration Required
Users need to configure Kitty for socket-based remote control by adding to
~/.config/kitty/kitty.conf:Then restart Kitty for changes to take effect.
Testing
Tested on macOS with Kitty terminal - artifacts no longer appear after fix.
🤖 Generated with Claude Code