Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion plugins/codex/scripts/lib/process.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,14 @@ function looksLikeMissingProcessMessage(text) {
return /not found|no running instance|cannot find|does not exist|no such process/i.test(text);
}

function envWithoutMsysPathConversion(env) {
return {
...(env ?? process.env),
MSYS_NO_PATHCONV: "1",
MSYS2_ARG_CONV_EXCL: "*"
};
}

export function terminateProcessTree(pid, options = {}) {
if (!Number.isFinite(pid)) {
return { attempted: false, delivered: false, method: null };
Expand All @@ -66,7 +74,8 @@ export function terminateProcessTree(pid, options = {}) {
if (platform === "win32") {
const result = runCommandImpl("taskkill", ["/PID", String(pid), "/T", "/F"], {
cwd: options.cwd,
env: options.env
// Keep taskkill's /PID and /T flags intact when Claude Code runs under Git Bash/MSYS.
env: envWithoutMsysPathConversion(options.env)
});

if (!result.error && result.status === 0) {
Expand Down
16 changes: 13 additions & 3 deletions tests/process.test.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,9 @@ test("terminateProcessTree uses taskkill on Windows", () => {
let captured = null;
const outcome = terminateProcessTree(1234, {
platform: "win32",
runCommandImpl(command, args) {
captured = { command, args };
env: { PATH: "C:\\Windows\\System32", SHELL: "C:\\Program Files\\Git\\bin\\bash.exe" },
runCommandImpl(command, args, options) {
captured = { command, args, options };
return {
command,
args,
Expand All @@ -26,7 +27,16 @@ test("terminateProcessTree uses taskkill on Windows", () => {

assert.deepEqual(captured, {
command: "taskkill",
args: ["/PID", "1234", "/T", "/F"]
args: ["/PID", "1234", "/T", "/F"],
options: {
cwd: undefined,
env: {
PATH: "C:\\Windows\\System32",
SHELL: "C:\\Program Files\\Git\\bin\\bash.exe",
MSYS_NO_PATHCONV: "1",
MSYS2_ARG_CONV_EXCL: "*"
}
}
});
assert.equal(outcome.delivered, true);
assert.equal(outcome.method, "taskkill");
Expand Down