Install
Install with PiG
pig install npm:@clementprevot/pi-ghostty-sessionInstall with Pi
pi install npm:@clementprevot/pi-ghostty-sessionPackages run code with your permissions and influence agent behavior. Catalog inclusion is not a security audit. Review the source before installing a third-party package.
Pi manifest JSON
The pi field of package.json.
{
"extensions": [
"./index.ts"
]
}README
Written by the package's publisher, shown as published in version 0.3.0 (README.md). PiG does not review it.
@clementprevot/pi-ghostty-session
A Pi extension that opens new pi sessions in Ghostty on macOS: one in a split, tab, or window, or several at once grouped in titled tabs. Each session starts in the folder you pick, runs the prompt you give it, and stays a normal interactive session: you switch to it and carry on.
Use it when you want the agent to set up sessions for you to join, for example a parallel task in a fresh worktree, or one review session per pull request.
Install
pi install npm:@clementprevot/pi-ghostty-session
Updates ship with pi update --extensions. The extension applies to your next session (quit and relaunch, or run /reload).
Requirements: macOS, Ghostty 1.3 or later (AppleScript support), and pi running inside Ghostty.
Usage
The agent calls the open_session tool:
{
"surface": "split-down",
"cwd": "~/worktrees/my-repo/fix-login",
"prompt": "Fix the login redirect bug described in TICKET-123, then run the tests.",
"model": "anthropic/claude-sonnet-4-5",
"name": "fix-login"
}
surface:split-right,split-down,split-left,split-up(a split of the pane that runs the current session),tab(a new tab in its window), orwindow.session(optional): an existing session to resume instead of starting a new one, as a session file path or a full or partial session id. See "Resume a session" below.cwd(optional): folder to start in, absolute, relative to the working directory, or starting with~/. Defaults to the folder of the resumed session, or else the working directory.prompt(optional): the first message of the new session, or the next message of a resumed one. Without it, pi opens idle.model(optional): passed topi --model, soprovider/idand a:<thinking>suffix work.name(optional): the session display name, passed topi --name.
You can open one yourself with /open-session <surface> [prompt], for example /open-session split-right review the open TODOs.
The result gives the id of the new session's tab and terminal. Pass the tab id to open_sessions to add sessions to that tab later.
Several sessions at once
The agent calls the open_sessions tool with one entry per tab:
{
"tabs": [
{
"title": "Jira",
"sessions": [
{ "name": "review-web-ui-101", "cwd": "~/repos/web-ui", "prompt": "Review https://github.com/org/web-ui/pull/101." },
{ "name": "review-api-202", "cwd": "~/repos/api", "prompt": "Review https://github.com/org/api/pull/202." }
]
},
{
"title": "Billing",
"sessions": [
{ "name": "review-api-203", "cwd": "~/repos/api", "prompt": "Review https://github.com/org/api/pull/203." }
]
}
]
}
tabs: each entry opens a new tab and gives every session its own pane in it.title(optional): the tab title, usually the topic. It also renames an existing tab.tab(optional): the id of a tab opened earlier byopen_sessionoropen_sessions. The sessions join that tab instead of a new one.sessions: the sessions of the tab, with the samesession,cwd,prompt,modelandnamefields asopen_session.placement(optional, top level):tabputs the new tabs in the window of the current session, which is the default.windowputs them in a new window.
The panes of a tab sit in two columns, filled row by row: the second pane goes right of the first, the third under the first, and so on. Ghostty then evens out their sizes. The result lists each tab id and each session's terminal id.
To have your agent use them, add lines like these to your instructions: "When I ask for a new session I can join, open it with open_session. When I ask for several related sessions at once, open them with open_sessions: one tab per topic, one pane per session."
Resume a session
Set session to reopen a session you closed, for example one an agent found for you:
{ "surface": "tab", "session": "01a1f8ad" }
The tool finds the session file, then types pi --session <file> into a new pane started in the session's own folder. It always passes the file, never the id: given an id from another project, pi would offer to fork the session into the current folder.
A session can run in one pane only, so the tool first checks whether it already runs:
open_sessionopens nothing and moves the focus to the pane that runs it, then says which tab holds that paneopen_sessionsopens nothing at all and lists the sessions to remove from the request, with their tabs- when the session runs in a terminal Ghostty does not show (inside tmux, for example), the result gives its process id and TTY instead
To know which sessions run, each pi session that loads this extension records its id, process id and TTY in pi-ghostty-session/live/ under the system temp directory, and removes the entry when it ends. Sessions started before you installed this version are not recorded until you restart them or run /reload.
How it works
- The tool resolves each folder and checks that it exists, before it asks Ghostty for anything.
- If there is a prompt, it writes it to a private file (mode 600) in
pi-ghostty-session/under the system temp directory. - It runs one AppleScript through
osascript, even for a batch. The script asks Ghostty for each new surface and typespi [--session ...] [--model ...] [--name ...] "$(command cat <prompt file>)"into it. Every value reaches the script as an argument, never as script source. - For a split or a new tab, the script finds the terminal of the current session by its TTY. The new surface lands next to this session even when another pane has the focus. If the script cannot find that terminal (inside tmux, for example), it uses the front window and says so. With no Ghostty window open, it opens a new window.
The command runs in a fresh shell, so your PATH and shell setup apply, and the shell stays open when you quit pi.
Limits
- macOS and Ghostty only. Elsewhere the tool reports an error.
- macOS may ask once whether your terminal may control Ghostty. If you declined, allow it in System Settings, Privacy & Security, Automation.
- The prompt files stay in the temp directory, which macOS cleans up on its own.
Privacy and data
The extension writes the prompts you send, and one small entry per running session (its id, process id and TTY), to the temp directory. It talks to Ghostty through AppleScript, makes no network calls and collects no data.
Local development
npm install
npm test
npm run typecheck
To try the extension in a live session without installing it:
pi -e /path/to/this/repo