From 64ab94f121c8ce07eceabbef645175de05860206 Mon Sep 17 00:00:00 2001 From: ollie Date: Sun, 19 Jul 2026 19:18:28 +0200 Subject: [PATCH] hooks: skip non-existent CWD for remote sessions If the session CWD does not exist locally (remote execution), do not set cmd.Dir. This prevents fork/exec failures when the CWD only exists on the remote host. --- pkg/agent/hooks.go | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/pkg/agent/hooks.go b/pkg/agent/hooks.go index eb67db2..ce17644 100644 --- a/pkg/agent/hooks.go +++ b/pkg/agent/hooks.go @@ -6,6 +6,7 @@ import ( "encoding/json" "errors" "fmt" + "os" "os/exec" "strings" "syscall" @@ -132,7 +133,12 @@ func runHookCmd(ctx context.Context, name, cmdStr string, payloadJSON []byte, cw cmd.SysProcAttr = &syscall.SysProcAttr{Setpgid: true} cmd.Stdin = bytes.NewReader(payloadJSON) if cwd != "" { - cmd.Dir = paths.ExpandHome(cwd) + expanded := paths.ExpandHome(cwd) + // Only set Dir if the path exists locally (remote sessions + // have a CWD that only exists on the remote host). + if _, err := os.Stat(expanded); err == nil { + cmd.Dir = expanded + } } // Inject payload map keys as OLLIE_* environment variables so hook