The best way to control Claude Code, Codex and more from any computer or phone
perf(server): Windows git reads no longer start a console host (#19288)
Kayzel committed
Nov 6, 2026 at 05:21 UTC
cedaa0de48e6ab2b6fc5d18ee115df2e262b797a
3 files changed
+75
-1
apps/server/src/vcs/GitVcsDriverCore.ts
+4
-1
@@ -36,7 +36,7 @@ import { dedupeRemoteBranchesWithLocalMatches } from "@t3tools/shared/git";
36
import * as HostProcess from "@t3tools/shared/HostProcess";
37
import { compactTraceAttributes } from "@t3tools/shared/observability";
38
import { decodeJsonResult } from "@t3tools/shared/schemaJson";
39
-import { resolveSpawnCommand } from "@t3tools/shared/shell";
39
+import { resolveSpawnCommand, runsGitWithoutConsole } from "@t3tools/shared/shell";
40
import { parseT3ProjectFile } from "@t3tools/shared/t3ProjectFile";
41
import { resolveProjectFileBackedSetting } from "@t3tools/shared/projectSettings";
42
import { gitCommandDuration, gitCommandsTotal, withMetrics } from "../observability/Metrics.ts";
@@ -993,6 +993,9 @@ export const makeGitVcsDriverCore = Effect.fn("makeGitVcsDriverCore")(function*
993
cwd: commandInput.cwd,
994
env: spawnEnv,
995
forceKillAfter: input.forceKillAfterMs,
996
+ ...(runsGitWithoutConsole(hostPlatform, executable, commandInput.args)
997
+ ? { detached: true, windowsHide: true }
998
+ : {}),
999
}),
1000
)
1001
.pipe(
packages/shared/src/shell.test.ts
+31
@@ -32,6 +32,7 @@ import {
32
resolveCommandPath,
33
resolveSpawnCommand,
34
resolveWindowsEnvironment,
35
+ runsGitWithoutConsole,
36
SpawnExecutableResolution,
37
WindowsShellEnvironment,
38
withPathDirectoryListings,
@@ -561,6 +562,36 @@ effectIt.layer(NodeServices.layer)("resolveCommandPath", (it) => {
562
);
563
});
564
565
+describe("runsGitWithoutConsole", () => {
566
+ const git = "C:\\Program Files\\Git\\ucrt64\\bin\\git.exe";
567
+
568
+ it.each([
569
+ [["rev-parse", "--git-path", "index"], true],
570
+ [["--git-dir", "C:\\repo\\.git", "symbolic-ref", "refs/remotes/origin/HEAD"], true],
571
+ [["remote", "get-url", "--", "origin"], true],
572
+ [["config", "--get", "branch.main.pushRemote"], true],
573
+ [["symbolic-ref", "--quiet", "HEAD"], true],
574
+ [["rev-parse", "--abbrev-ref", "--symbolic-full-name", "@{upstream}"], true],
575
+ [["rev-parse", "HEAD"], false],
576
+ [["symbolic-ref", "HEAD", "refs/heads/x"], false],
577
+ [["symbolic-ref", "-qd", "refs/remotes/origin/HEAD"], false],
578
+ [["config", "--get", "--edit"], false],
579
+ [["-c", "core.pager=x", "config", "--get", "user.name"], false],
580
+ ])("Git for Windows %j without a console: %s", (args, expected) => {
581
+ expect(runsGitWithoutConsole("win32", git, args)).toBe(expected);
582
+ });
583
+
584
+ it.each([
585
+ ["win32", "C:\\Program Files\\Git\\cmd\\git.exe"],
586
+ ["win32", "C:\\Users\\x\\scoop\\shims\\git.exe"],
587
+ ["linux", git],
588
+ ] as const)("keeps the console on %s for %s", (platform, executable) => {
589
+ expect(runsGitWithoutConsole(platform, executable, ["rev-parse", "--show-toplevel"])).toBe(
590
+ false,
591
+ );
592
+ });
593
+});
594
+
595
describe("preferGitForWindowsBinary", () => {
596
const files =
597
(...paths: Array<string>) =>
packages/shared/src/shell.ts
+40
@@ -827,6 +827,46 @@ export interface SpawnCommandOptions extends CommandAvailabilityOptions {
827
readonly bypassNpmShim?: boolean;
828
}
829
830
+// `*` is one argument that is not an option. These forms read refs or config
831
+// only, so git starts no hook, helper, pager, editor or lazy fetch for them.
832
+const CONSOLE_FREE_GIT_READS = [
833
+ "rev-parse --git-path index",
834
+ "rev-parse --git-common-dir",
835
+ "rev-parse --show-toplevel",
836
+ "rev-parse --symbolic-full-name HEAD",
837
+ "rev-parse --abbrev-ref --symbolic-full-name @{upstream}",
838
+ "symbolic-ref --quiet HEAD",
839
+ "symbolic-ref *",
840
+ "remote",
841
+ "remote get-url *",
842
+ "remote get-url -- *",
843
+ "config --get *",
844
+].map((form) => form.split(" "));
845
+
846
+export function runsGitWithoutConsole(
847
+ platform: NodeJS.Platform,
848
+ executable: string,
849
+ args: ReadonlyArray<string>,
850
+): boolean {
851
+ if (platform !== "win32") return false;
852
+ const { basename, dirname } = NodePath.win32;
853
+ const bin = dirname(executable);
854
+ const build = basename(dirname(bin)).toLowerCase();
855
+ if (basename(executable).toLowerCase() !== "git.exe" || basename(bin).toLowerCase() !== "bin") {
856
+ return false;
857
+ }
858
+ if (!GIT_FOR_WINDOWS_BUILDS.some((candidate) => candidate === build)) return false;
859
+ const rest =
860
+ args[0] === "--git-dir" && args[1] !== undefined && !args[1].startsWith("-")
861
+ ? args.slice(2)
862
+ : args;
863
+ return CONSOLE_FREE_GIT_READS.some(
864
+ (form) =>
865
+ form.length === rest.length &&
866
+ form.every((part, i) => part === rest[i] || (part === "*" && !rest[i]!.startsWith("-"))),
867
+ );
868
+}
869
+
870
export const resolveSpawnCommand = Effect.fnUntraced(function* (
871
command: string,
872
args: ReadonlyArray<string>,