feat(ide): add GEMINI_CLI_IDE_PID env var to override IDE process detection (#15842)

Co-authored-by: Adib234 <30782825+Adib234@users.noreply.github.com>
This commit is contained in:
Kiryl Dubarenka
2026-02-24 05:35:25 -08:00
committed by GitHub
parent 6676546a4b
commit ee2e947435
4 changed files with 82 additions and 0 deletions
+20
View File
@@ -208,6 +208,13 @@ async function getIdeProcessInfoForWindows(): Promise<{
* to identify the main application process (e.g., the main VS Code window
* process).
*
* This function can be overridden by setting the `GEMINI_CLI_IDE_PID`
* environment variable. This is useful for launching Gemini CLI in a
* standalone terminal while still connecting to an IDE instance.
*
* If `GEMINI_CLI_IDE_PID` is set, the function uses that PID and fetches
* the command for it.
*
* If the IDE process cannot be reliably identified, it will return the
* top-level ancestor process ID and command as a fallback.
*
@@ -219,6 +226,19 @@ export async function getIdeProcessInfo(): Promise<{
}> {
const platform = os.platform();
if (process.env['GEMINI_CLI_IDE_PID']) {
const idePid = parseInt(process.env['GEMINI_CLI_IDE_PID'], 10);
if (!isNaN(idePid) && idePid > 0) {
if (platform === 'win32') {
const processMap = await getProcessTableWindows();
const proc = processMap.get(idePid);
return { pid: idePid, command: proc?.command || '' };
}
const { command } = await getProcessInfo(idePid);
return { pid: idePid, command };
}
}
if (platform === 'win32') {
return getIdeProcessInfoForWindows();
}