Skip to content

appintents: expose PID and TTY on TerminalEntity#11354

Closed
ocean6954 wants to merge 1 commit intoghostty-org:mainfrom
ocean6954:feat/terminal-entity-pid-tty
Closed

appintents: expose PID and TTY on TerminalEntity#11354
ocean6954 wants to merge 1 commit intoghostty-org:mainfrom
ocean6954:feat/terminal-entity-pid-tty

Conversation

@ocean6954
Copy link
Copy Markdown

This is a re-submission of #10983. Vouched in #11287.

Add child process PID and TTY device name as queryable properties on
TerminalEntity for App Intents. This enables external applications and
Shortcuts to identify and filter terminals by their PID or TTY device.

Closes #10756

Co-Authored-By: Claude Opus 4.6 noreply@anthropic.com

@ocean6954 ocean6954 requested review from a team as code owners March 11, 2026 04:15
}

// Returns the PID of the child process, or nil if not available.
var childPID: Int32? {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These should live on the Ghostty.Surface model instead of here, its been a long transition to move over there.

Comment thread src/Surface.zig Outdated
}

/// Returns the PID of the child process, or -1 if not available.
pub fn childPid(self: *Surface) i32 {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should use native Zig optionals here, not sentinel integral values.

Comment thread src/Surface.zig Outdated
}

/// Returns the TTY device name (e.g. "/dev/ttys003"), or null if not available.
pub fn ttyName(self: *Surface) ?[*:0]const u8 {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same, use Zig types.

Comment thread src/termio/Exec.zig Outdated
@@ -586,6 +586,7 @@ const Subprocess = struct {
screen_size: renderer.ScreenSize,
pty: ?Pty = null,
process: ?Process = null,
tty_name: ?[*:0]const u8 = null,
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Store as a zig type, not this.

@grimmerk
Copy link
Copy Markdown

Hi @ocean6954, just checking in — are you still working on this? I have a use case for this feature (switching to Claude Code sessions by PID in a terminal switcher app). Let me know if there's anything I can help with!

@ocean6954 ocean6954 requested a review from mitchellh March 22, 2026 11:53
@ocean6954
Copy link
Copy Markdown
Author

Hi @grimmerk

Sorry for the late reply! I had already pushed the fixes but wasn't sure how to re-request a review — I just did that now. Thanks for your interest in this feature!

@dnwpark
Copy link
Copy Markdown

dnwpark commented Mar 27, 2026

also looking for this!

@jcollie
Copy link
Copy Markdown
Member

jcollie commented Mar 27, 2026

@ocean6954 Did you want to rebase this on top of the core changes from #11639 ?

Comment thread include/ghostty.h Outdated
void ghostty_surface_update_config(ghostty_surface_t, ghostty_config_t);
bool ghostty_surface_needs_confirm_quit(ghostty_surface_t);
bool ghostty_surface_process_exited(ghostty_surface_t);
int32_t ghostty_surface_child_pid(ghostty_surface_t);
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What do you think about returning a pid_t? That is the POSIX type for an integer representing a process ID.

Only using 32 bits is restrictive, while pid_t is kind of opaque in that each platform can define it differently. You never know if Ghostty will exist on platforms supporting larger that 32 bit process IDs. I would assume that there are equivalent types in Swift and Zig.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The core API returns a u64. I chose that specifically over a pid_t to avoid any sort of platform dependence (Zig seems to be going hard against POSIX in the upcoming 0.16 release).

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@tristan957

I've rebased on top of #11639 and refactored to use the getProcessInfo() API. As @jcollie mentioned, the core API returns u64. This PR converts it to i64 at the C API boundary to allow returning -1 when unavailable.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

0 should work as a signal that the PID was unavailable, at least on any system I'm aware of that's not a valid PID.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point, updated to use u64 with 0 as the sentinel value.

@ocean6954 ocean6954 force-pushed the feat/terminal-entity-pid-tty branch from 1c0f3b0 to b299953 Compare March 30, 2026 02:48
@ocean6954
Copy link
Copy Markdown
Author

Rebased on top of #11639 and refactored to use getProcessInfo(). Squashed into a single commit.

Expose the foreground process PID and slave TTY name on
TerminalEntity via the getProcessInfo() API added in ghostty-org#11639.
This allows Shortcuts/Siri to query process information
for a given terminal session.

Closes ghostty-org#10756

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@ocean6954 ocean6954 force-pushed the feat/terminal-entity-pid-tty branch from b299953 to e7e6e06 Compare March 30, 2026 03:33
@00-kat
Copy link
Copy Markdown
Contributor

00-kat commented Apr 24, 2026

This has been superseded by #11922 right?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

macOS: Expose TTY, PID on TerminalEntity within App Shortcuts

8 participants