From ba571c1e72f355877e5ef535452efa44f649e001 Mon Sep 17 00:00:00 2001 From: Strocs Date: Fri, 13 Feb 2026 13:21:58 -0300 Subject: [PATCH] fix(non-interactive-env): prevent environment variable duplication on repeated executions The non-interactive-env hook was prepending environment variables without checking if the prefix was already applied to the command, causing duplication when multiple git commands were executed in sequence. This fix adds an idempotent check: if the command already starts with the env prefix, the hook returns early without modification. This maintains the non-interactive behavior while ensuring the operation is idempotent across multiple tool executions. --- src/hooks/non-interactive-env/non-interactive-env-hook.ts | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/hooks/non-interactive-env/non-interactive-env-hook.ts b/src/hooks/non-interactive-env/non-interactive-env-hook.ts index 90686f64..46ab2e09 100644 --- a/src/hooks/non-interactive-env/non-interactive-env-hook.ts +++ b/src/hooks/non-interactive-env/non-interactive-env-hook.ts @@ -55,6 +55,13 @@ export function createNonInteractiveEnvHook(_ctx: PluginInput) { // The bash tool always runs in a Unix-like shell (bash/sh), even on Windows // (via Git Bash, WSL, etc.), so always use unix export syntax. const envPrefix = buildEnvPrefix(NON_INTERACTIVE_ENV, "unix") + + // Check if the command already starts with the prefix to avoid stacking. + // This maintain the non-interactive behaivor but make the operation idempotent. + if (command.trim().startsWith(envPrefix.trim())) { + return + } + output.args.command = `${envPrefix} ${command}` log(`[${HOOK_NAME}] Prepended non-interactive env vars to git command`, {