gemini-cli - 💡(How to fix) Fix [FEATURE] Include pid/pgid in terminal_info ACP metadata for orphan process detection [1 participants]

Official PRs (…)
ON THIS PAGE

Recommended Tools

×6

Utilities matched from this issue’s tags and category — try them while you read without losing context.

GitHub issue graph ai analysis

Paste a GitHub issue URL. We fetch that issue, discover linked issues from bodies/comments/timeline, collect linked pull requests, and produce a structured English report.

The report is written in English Markdown for sharing and archival.

Helpful · Quick feedback

Loading…
GitHub stats
anthropics/claude-code#45180Fetched 2026-04-09 08:11:25
View on GitHub
Comments
0
Participants
1
Timeline
3
Reactions
24
Participants
Timeline (top)
labeled ×3

Root Cause

Use case:

  1. User starts agent session in Zed (or any ACP client)
  2. Gemini CLI runs something that forks background workers (dev server, build watcher, etc.)
  3. Shell exits with 0, CLI sends terminal_exit
  4. Child processes keep running, consuming resources, no parent
  5. ACP client can't touch them because it has no PID or PGID
  6. With pid/pgid in terminal_info, client calls killpg(pgid, 0) after exit, finds orphans, cleans up with SIGTERM

Fix Action

Fix / Workaround

Code Example

{"terminal_info": {"terminal_id": "toolu_...", "cwd": "/some/path"}}

---

{"terminal_info": {"terminal_id": "toolu_...", "cwd": "/some/path", "pid": 12345, "pgid": 12345}}
RAW_BUFFERClick to expand / collapse

What would you like to be added?

Add pid and pgid fields to the terminal_info metadata sent via ACP ToolCall._meta. Currently terminal_info only includes terminal_id and cwd. With pid/pgid, ACP clients like Zed can detect and clean up orphaned child processes after the shell exits.

Current:

{"terminal_info": {"terminal_id": "toolu_...", "cwd": "/some/path"}}

Proposed:

{"terminal_info": {"terminal_id": "toolu_...", "cwd": "/some/path", "pid": 12345, "pgid": 12345}}

_meta is freeform JSON, so no ACP protocol changes are needed — just two extra fields in existing JSON.

Why is this needed?

When Gemini CLI runs terminal commands through ACP, if a command spawns child processes (dev servers, watchers, build scripts), those processes outlive the shell and become orphans. The ACP client has no process handle — it only sees streamed output via terminal_output events. Without pid/pgid, there's no way to call killpg() to clean up after the shell exits.

Use case:

  1. User starts agent session in Zed (or any ACP client)
  2. Gemini CLI runs something that forks background workers (dev server, build watcher, etc.)
  3. Shell exits with 0, CLI sends terminal_exit
  4. Child processes keep running, consuming resources, no parent
  5. ACP client can't touch them because it has no PID or PGID
  6. With pid/pgid in terminal_info, client calls killpg(pgid, 0) after exit, finds orphans, cleans up with SIGTERM

Alternatives considered:

  • A reverse terminal/kill in ACP protocol (client-to-agent direction) — works but requires protocol-level change on both sides for what could be two JSON fields
  • Scanning /proc by command string — too fragile, too many false positives

Additional context

extent analysis

TL;DR

Add pid and pgid fields to the terminal_info metadata in Claude Code to enable Zed to detect and kill child processes.

Guidance

  • Modify the existing JSON payload in Claude Code to include pid and pgid, as shown in the proposed solution.
  • Verify that the modified payload is correctly sent and received by checking the _meta data in the ACP ToolCall.
  • Update the Zed code to parse the new pid and pgid fields from the terminal_info metadata and use them to call killpg() after the shell exits.
  • Test the changes with a scenario that spawns child processes, such as a build script with watchers or a dev server, to ensure that Zed can correctly detect and kill the child processes.

Example

{
  "terminal_info": {
    "terminal_id": "toolu_...",
    "cwd": "/some/path",
    "pid": 12345,
    "pgid": 12345
  }
}

Notes

This solution assumes that Claude Code has access to the pid and pgid of the spawned shell and can include them in the terminal_info metadata. The Zed code will need to be updated to parse these new fields and use them to call killpg().

Recommendation

Apply the proposed workaround by adding pid and pgid fields to the terminal_info metadata, as it is a simpler and more targeted solution than introducing a reverse terminal/kill in the ACP protocol or scanning /proc by command string.

Vote matrix · Quick signals

Works
Did the solution work? Tap to confirm.
Easy Fix
Was it a quick fix?
Time Saver
Did it save you time?
Blocking
Was it severely blocking?
Common Issue
Are others likely hitting this too?
Flaky / Intermittent
Is it intermittent?
Verified / Reproducible
Can you reproduce it reliably?
Loading…

Still need to ship something?

×6

Another batch ranked right after the header list — different links, same matching logic.

Back to top recommendations

TRENDING