GHOSTTY_SESSION_ID env var + external session focus #10603
Replies: 5 comments
-
|
See: #8200 TLDR: A UUIDv4 was deemed too complicated, especially since 128 bit integers don't have a natural C type. I think keeping them as strings is even worse. I personally think an opaque random 64 bit unsigned integer is the easiest, whereas Mitchell wanted something with some sort of structure to support some future theoretical distributed Ghostty system. As an aside, testing the GTK apprt via docker is not sufficient. Most of the GUI code has no unit tests so just compiling and running unit tests is not sufficient testing. Nomenclature-wise, Ghostty doesn't have "sessions", we have surfaces. If/when we introduce the notion of sessions it'll be something other than an individual active terminal. "Present surface" would be my preferred verb as it's already used in a few places already. |
Beta Was this translation helpful? Give feedback.
-
|
Thanks @jcollie for the guidance here — both your comment and your work on #8200 were really helpful in aligning on a solution. The u64 approach, the "present surface" naming, and the surface-level lookup pattern from your PR gave us a solid foundation to build on. I've reworked the implementation based on your feedback. Updated branch: Changes from my original
Re: testing — agreed that Docker compilation alone isn't sufficient for the GUI paths. The macOS URL scheme was tested end-to-end (multiple tabs, This discussion and the linked implementation were written with AI assistance (Claude Code), with human review and testing. |
Beta Was this translation helpful? Give feedback.
-
|
This would unlock another often overlooked feature: proper per-tab (surface) command history isolation and recovery. In Iterm2 we can use the $ITERM_SESSION_ID variable which contains a UUID that is stable between restarts, tab reorderings etc so setting the HISTFILE env var to something that contains that unique identifier makes command history work properly across restarts. Without this, after Ghostty is restarted, arrow-up inside a terminal will suddenly show commands from another terminal - very confusing. |
Beta Was this translation helpful? Give feedback.
-
|
another use case: in revdiff (a tui diff reviewer) we ship Claude Code and Codex plugins that spawn revdiff as an overlay in a split pane. on ghostty the launcher splits the only workaround today is matching |
Beta Was this translation helpful? Give feedback.
-
Aside: AppleScript and Apple's Shortcuts lets you focus a terminal now, xref #7634, #8961, and #11208. Apparently there are IDs for those, but I'm not on macOS and know nothing about them. GTK still has nothing, and there's nothing cross-platform (though I'd argue that should wait for #2353), so this discussion is still relevant though. |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
I want to identify specific Ghostty terminal sessions from external tools and focus them programmatically. My use case: I open terminal tabs for different tasks and use a workflow tool to track and manage them. I need each tab to expose a stable identifier so the tool can bring me back to the right tab on demand.
This needs two pieces:
GHOSTTY_SESSION_IDenv var containing a UUID, set per terminal session, so scripts can discover which session they're inI have a working implementation on a branch: chris-spare/ghostty:feature/focus-session
The implementation:
GHOSTTY_SESSION_ID(UUID v4) in every terminal session across all platformsopen "ghostty:///focus-session/$GHOSTTY_SESSION_ID"via aghostty://URL scheme, reusingghosttySurface(id:)andghosttyPresentTerminalghostty +focus-session $GHOSTTY_SESSION_IDvia D-Bus, following the+new-windowpatternTested on macOS (end-to-end) and Linux/GTK (compilation verified via Docker).
Related discussions: #9084, #2353
This discussion and the linked implementation were written with AI assistance (Claude Code), with human review and testing.
Beta Was this translation helpful? Give feedback.
All reactions